/** * Verifies connection by creating the API URL and testing a call via the client. * * @param v */ protected void onHostVerifyButtonClicked(View v) { if (!NetworkUtils.isOnline(getActivity())) { InterfaceUtils.showAlert( getActivity(), R.string.sitewhere_no_network_message, R.string.sitewhere_no_network_title); return; } // Disable button until processing is complete. apiVerifyButton.setEnabled(false); String uri = apiUri.getText().toString(); if (uri.length() == 0) { apiUri.setError("Enter a value for the remote SiteWhere server address."); apiVerifyGroup.setVisibility(View.GONE); return; } // Calculate API URL and create client for testing. String api = "http://" + uri + "/sitewhere/api/"; apiVerifyMessage.setTextColor(Color.parseColor(SUCCESS_COLOR)); apiVerifyMessage.setText("Verifying SiteWhere API available for URI: '" + api + "' ..."); // Make the group visible. apiVerifyGroup.setVisibility(View.VISIBLE); apiVerifyProgress.setVisibility(View.VISIBLE); SiteWhereClient client = new SiteWhereClient(api, "admin", "password", 4000); executor.submit(new HostVerifier(client)); }
/** * Verifies MQTT connection by trying to establish a connection. * * @param v */ protected void onMqttVerifyButtonClicked(View v) { if (!NetworkUtils.isOnline(getActivity())) { InterfaceUtils.showAlert( getActivity(), R.string.sitewhere_no_network_message, R.string.sitewhere_no_network_title); return; } // Disable button until processing is complete. mqttVerifyButton.setEnabled(false); String uri = mqttUri.getText().toString(); if (uri.length() == 0) { mqttUri.setError("Enter a value for the remote MQTT broker address."); mqttVerifyGroup.setVisibility(View.GONE); return; } // Calculate API URL and create client for testing. String api = "http://" + uri; mqttVerifyMessage.setTextColor(Color.parseColor(SUCCESS_COLOR)); mqttVerifyMessage.setText("Verifying MQTT broker available for URI: '" + api + "' ..."); // Make the group visible. mqttVerifyGroup.setVisibility(View.VISIBLE); mqttVerifyProgress.setVisibility(View.VISIBLE); String mqttUriStr = mqttUri.getText().toString(); String[] mqttParts = mqttUriStr.split("[:]+"); String broker = null; int port = 1883; if (mqttParts.length > 0) { broker = mqttParts[0]; } if (mqttParts.length > 1) { try { port = Integer.parseInt(mqttParts[1]); } catch (NumberFormatException e) { mqttVerifyMessage.setTextColor(Color.parseColor(ERROR_COLOR)); mqttVerifyMessage.setText("Invalid MQTT broker port value."); return; } } if (broker == null) { mqttVerifyMessage.setTextColor(Color.parseColor(ERROR_COLOR)); mqttVerifyMessage.setText("Invalid MQTT broker hostname."); return; } executor.submit(new MqttVerifier(broker, port)); }