public void disconnectFromMqttServer() { try { client.disconnect(); } catch (MqttException e) { LOG.error("DisconnectFromMqttServer: trouble disconnecing {}", e.toString()); } finally { connectedToBroker = false; } }
/** * Returns a <code>String</code> representation of this exception. */ @Override public String toString() { if (cause instanceof org.eclipse.paho.client.mqttv3.MqttException) { org.eclipse.paho.client.mqttv3.MqttException internalException = (org.eclipse.paho.client.mqttv3.MqttException) cause; return internalException.toString(); } String result = getMessage() + " (" + reasonCode + ")"; if (cause != null) { result = result + " - " + cause.toString(); } return result; } }
/** * Adds the current errorcode to IBM Watson IoT Platform. * * @param errorCode The "errorCode" is a current device error code that * needs to be added to the Watson IoT Platform. * * @return code indicating whether the update is successful or not * (200 means success, otherwise unsuccessful) */ public int addErrorCode(int errorCode) { final String METHOD = "addErrorCode"; JsonObject jsonData = new JsonObject(); JsonObject errorObj = new JsonObject(); errorObj.addProperty("errorCode", errorCode); jsonData.add("d", errorObj); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getAddErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Logs from IBM Watson IoT Platform for this device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearLogs() { final String METHOD = "clearLogs"; JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getClearDiagLogsTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Adds the current errorcode to IBM Watson IoT Platform. * * @param errorCode The "errorCode" is a current device error code that * needs to be added to the Watson IoT Platform. * * @return code indicating whether the update is successful or not * (200 means success, otherwise unsuccessful) */ public int addErrorCode(int errorCode) { final String METHOD = "addErrorCode"; JsonObject jsonData = new JsonObject(); JsonObject errorObj = new JsonObject(); errorObj.addProperty("errorCode", errorCode); jsonData.add("d", errorObj); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getAddErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Logs from IBM Watson IoT Platform for this device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearLogs() { final String METHOD = "clearLogs"; JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getClearDiagLogsTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Error Codes from IBM Watson IoT Platform for this device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearErrorCodes() { final String METHOD = "clearErrorCodes"; JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getClearDiagErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
/** * Clear the Error Codes from IBM Watson IoT Platform for this device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearErrorCodes() { final String METHOD = "clearErrorCodes"; JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(client.getDMAgentTopic().getClearDiagErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString());
/** * Clear the Device(connected via the Gateway) ErrorCodes from IBM Watson IoT Platform. * * @param typeId The device type of the device connected to the Gateway * @param deviceId The deviceId of the device connected to the Gateway * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearDeviceErrorCodes(String typeId, String deviceId) { final String METHOD = "clearErrorCodes"; String key = typeId + ':' + deviceId; ManagedGatewayDevice mc = (ManagedGatewayDevice) this.devicesMap.get(key); if(mc == null) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, "The device is not a managed device, so can not send the request"); return -1; } JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(mc.getDMAgentTopic().getClearDiagErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Device(connected through the Gateway) Logs from IBM Watson IoT Platform. * * @param typeId the device type of the attached device * @param deviceId the device Id of the attached device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful). */ public int clearDeviceLogs(String typeId, String deviceId) { final String METHOD = "clearLogs"; String key = typeId + ':' + deviceId; ManagedGatewayDevice mc = (ManagedGatewayDevice) this.devicesMap.get(key); if(mc == null) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, "The device is not a managed device, so can not send the request"); return -1; } JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(mc.getDMAgentTopic().getClearDiagLogsTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Device(connected through the Gateway) Logs from IBM Watson IoT Platform. * * @param typeId the device type of the attached device * @param deviceId the device Id of the attached device * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful). */ public int clearDeviceLogs(String typeId, String deviceId) { final String METHOD = "clearLogs"; String key = typeId + ':' + deviceId; ManagedGatewayDevice mc = (ManagedGatewayDevice) this.devicesMap.get(key); if(mc == null) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, "The device is not a managed device, so can not send the request"); return -1; } JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(mc.getDMAgentTopic().getClearDiagLogsTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }
/** * Clear the Device(connected via the Gateway) ErrorCodes from IBM Watson IoT Platform. * * @param typeId The device type of the device connected to the Gateway * @param deviceId The deviceId of the device connected to the Gateway * @return code indicating whether the clear operation is successful or not * (200 means success, otherwise unsuccessful) */ public int clearDeviceErrorCodes(String typeId, String deviceId) { final String METHOD = "clearErrorCodes"; String key = typeId + ':' + deviceId; ManagedGatewayDevice mc = (ManagedGatewayDevice) this.devicesMap.get(key); if(mc == null) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, "The device is not a managed device, so can not send the request"); return -1; } JsonObject jsonData = new JsonObject(); try { JsonObject response = sendAndWait(mc.getDMAgentTopic().getClearDiagErrorCodesTopic(), jsonData, REGISTER_TIMEOUT_VALUE); if (response != null ) { return response.get("rc").getAsInt(); } } catch (MqttException e) { LoggerUtility.log(Level.SEVERE, CLASS_NAME, METHOD, e.toString()); } return 0; }