public class ManagedGateway extends GatewayClient implements org.eclipse.paho.client.mqttv3.IMqttMessageListener, Runnable
The device management feature enhances the IBM Watson IoT Platform service with new capabilities for managing devices and Gateways.
This is a derived class from GatewayClient and can be used by
Gateway devices to perform both Device operations and Device Management operations,
i.e, the Gateways can use this class to do the following,
commandCallbacks, messageCodecs, messageCodecsByFormatCLIENT_ID_DELIMITER, config, DEFAULT_ACTION_TIMEOUT, DEFAULT_DISCONNECTED_BUFFER_SIZE, DEFAULT_MAX_CONNECT_ATTEMPTS, DEFAULT_MAX_INFLIGHT_MESSAGES, DEFAULT_MESSAGING_QOS, disconnectRequested, gson, messageCount, mqttAsyncClient, mqttCallback, mqttClient, mqttClientOptions, persistence| Constructor and Description |
|---|
ManagedGateway(GatewayConfig config,
DeviceData deviceData)
Constructor that creates a ManagedGateway object using the properties file, but does not connect to
IBM Watson IoT Platform yet.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCustomActionHandler(CustomActionHandler actionHandler) |
void |
addDeviceActionHandler(DeviceActionHandler actionHandler)
Adds a device action handler which is of type
DeviceActionHandler |
int |
addDeviceErrorCode(String typeId,
String deviceId,
int errorCode)
Adds the Device errorcode to IBM Watson IoT Platform.
|
int |
addDeviceLog(String typeId,
String deviceId,
String message,
Date timestamp,
LogSeverity severity)
Adds a Device(connected via the Gateway) Log message to the IBM Watson IoT Platform.
|
int |
addDeviceLog(String typeId,
String deviceId,
String message,
Date timestamp,
LogSeverity severity,
String data)
Adds a Device(connected via the Gateway) Log message to the IBM Watson IoT Platform.
|
void |
addFirmwareHandler(DeviceFirmwareHandler fwHandler)
Adds a firmware handler for both Gateway and devices connected through the gateway,
that is of type
DeviceFirmwareHandler |
int |
addGatewayErrorCode(int errorCode)
Adds the Gateway errorcode to IBM Watson IoT Platform.
|
int |
addGatewayLog(String message,
Date timestamp,
LogSeverity severity)
Adds a Gateway Log message to the IBM Watson IoT Platform.
|
int |
addGatewayLog(String message,
Date timestamp,
LogSeverity severity,
String data)
Adds a Gateway Log message to the IBM Watson IoT Platform.
|
int |
clearDeviceErrorCodes(String typeId,
String deviceId)
Clear the Device(connected via the Gateway) ErrorCodes from IBM Watson IoT Platform.
|
int |
clearDeviceLogs(String typeId,
String deviceId)
Clear the Device(connected through the Gateway) Logs from IBM Watson IoT Platform.
|
int |
clearGatewayErrorCodes()
Clear the Gateway ErrorCodes from IBM Watson IoT Platform.
|
int |
clearGatewayLogs()
Clear the Gateway Logs from IBM Watson IoT Platform.
|
void |
disconnect()
Disconnects the Gateway and all the devices connected, from IBM Watson IoT Platform
|
DeviceData |
getAttachedDeviceData(String typeId,
String deviceId)
Returns the DeviceData of the attached device.
|
DeviceData |
getGatewayDeviceData()
Returns the DeviceData of the gateway.
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message)
This method is called by the MQTT library when a message(command) is sent by the IBM Watson IoT Platform.
|
protected org.eclipse.paho.client.mqttv3.IMqttDeliveryToken |
publish(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message) |
protected void |
reconnect()
This method reconnects when the connection is lost due to n/w interruption and this method
is called only when the connection is established originally by the library code.
|
void |
run() |
boolean |
sendDeviceManageRequest(String typeId,
String deviceId,
DeviceData deviceData,
long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions)
Sends a device manage request to IBM Watson IoT Platform
|
boolean |
sendDeviceManageRequest(String typeId,
String deviceId,
DeviceData deviceData,
long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions,
List<String> bundleIds)
Sends a device manage request to IBM Watson IoT Platform
|
boolean |
sendDeviceManageRequest(String typeId,
String deviceId,
long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions)
Sends a device manage request to IBM Watson IoT Platform
|
boolean |
sendDeviceManageRequest(String typeId,
String deviceId,
long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions,
List<String> bundleIds)
Sends a device manage request to IBM Watson IoT Platform
|
boolean |
sendDeviceUnmanageRequet(String typeId,
String deviceId)
Moves the device connected via the Gateway from managed state to unmanaged state
A device uses this request when it no longer needs to be managed.
|
boolean |
sendGatewayManageRequest(long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions)
Sends a manage request to IBM Watson IoT Platform
|
boolean |
sendGatewayManageRequest(long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions,
List<String> bundleIds)
Sends a manage request to IBM Watson IoT Platform
|
boolean |
sendGatewayUnmanageRequet()
Moves the Gateway from managed state to unmanaged state
A device uses this request when it no longer needs to be managed.
|
int |
updateDeviceLocation(String typeId,
String deviceId,
Double latitude,
Double longitude,
Double elevation)
Update the location of the Device connected via the Gateway to IBM Watson IoT Platform.
|
int |
updateDeviceLocation(String typeId,
String deviceId,
Double latitude,
Double longitude,
Double elevation,
Date measuredDateTime)
Update the location of the Device connected via the Gateway.This method converts the
date in the required format.
|
int |
updateDeviceLocation(String typeId,
String deviceId,
Double latitude,
Double longitude,
Double elevation,
Date measuredDateTime,
Date updatedDateTime,
Double accuracy)
Update the location of the device connected through the Gateway.
|
int |
updateGatewayLocation(Double latitude,
Double longitude,
Double elevation)
Update the location of the Gateway to IBM Watson IoT Platform.
|
int |
updateGatewayLocation(Double latitude,
Double longitude,
Double elevation,
Date measuredDateTime)
Update the location of the Gateway.
|
int |
updateGatewayLocation(Double latitude,
Double longitude,
Double elevation,
Date measuredDateTime,
Date updatedDateTime,
Double accuracy)
Update the location of the Gateway.
|
publishDeviceEvent, publishDeviceEvent, subscribeToDeviceCommands, unsubscribeFromDeviceCommandsconnect, connectComplete, connectionLost, deliveryComplete, publishEvent, publishEvent, registerCodec, registerCommandCallbackclose, configureMqttClient, getConfig, isConnected, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic ManagedGateway(GatewayConfig config, DeviceData deviceData) throws Exception
Constructor that creates a ManagedGateway object using the properties file, but does not connect to IBM Watson IoT Platform yet. The properties must have the following definitions,
config - Configuration object for the gateway devicedeviceData - The Device ModelException - If the essential parameters are not setpublic DeviceData getGatewayDeviceData()
public DeviceData getAttachedDeviceData(String typeId, String deviceId)
typeId - the device type of the devicedeviceId - the device id of the devicepublic boolean sendGatewayManageRequest(long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions)
throws org.eclipse.paho.client.mqttv3.MqttException
Sends a manage request to IBM Watson IoT Platform
A Gateway uses this request to become a managed device. It should be the first device management request sent by the Gateway after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway to IBM Watson IoT Platform if its not connected already
lifetime - The length of time in seconds within
which the Gateway must send another Manage device request.
if set to 0, the managed Gateway will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the Gateway supports firmware actions or not.
The Gateway must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the Gateway supports Device actions or not.
The Gateway must add a Device action handler to handle the reboot and factory reset requests.org.eclipse.paho.client.mqttv3.MqttException - when failurepublic boolean sendGatewayManageRequest(long lifetime,
boolean supportFirmwareActions,
boolean supportDeviceActions,
List<String> bundleIds)
throws org.eclipse.paho.client.mqttv3.MqttException
Sends a manage request to IBM Watson IoT Platform
A Gateway uses this request to become a managed device. It should be the first device management request sent by the Gateway after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway to IBM Watson IoT Platform if its not connected already
lifetime - The length of time in seconds within
which the Gateway must send another Manage device request.
if set to 0, the managed Gateway will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the Gateway supports firmware actions or not.
The Gateway must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the Gateway supports Device actions or not.
The Gateway must add a Device action handler to handle the reboot and factory reset requests.bundleIds - List of bundle Ids to uniquely identify the device management extensions that this gateway supports,
The device must add a Custom action handler to handle the custom action requestsorg.eclipse.paho.client.mqttv3.MqttException - when failurepublic boolean sendDeviceManageRequest(String typeId, String deviceId, long lifetime, boolean supportFirmwareActions, boolean supportDeviceActions) throws org.eclipse.paho.client.mqttv3.MqttException
Sends a device manage request to IBM Watson IoT Platform
A Gateway uses this request to manage the device connected to it, It should be the first device management request sent for the device after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway/Device to IBM Watson IoT Platform if its not connected already
typeId - The typeId of the device connected to the gatewaydeviceId - The deviceId of the device connected to the gatewaylifetime - The length of time in seconds within
which the device must send another Manage device request.
if set to 0, the managed device will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the device supports firmware actions or not.
The device must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the device supports Device actions or not.
The device must add a Device action handler to handle the reboot and factory reset requests.org.eclipse.paho.client.mqttv3.MqttException - when failurepublic boolean sendDeviceManageRequest(String typeId, String deviceId, long lifetime, boolean supportFirmwareActions, boolean supportDeviceActions, List<String> bundleIds) throws org.eclipse.paho.client.mqttv3.MqttException
Sends a device manage request to IBM Watson IoT Platform
A Gateway uses this request to manage the device connected to it, It should be the first device management request sent for the device after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway/Device to IBM Watson IoT Platform if its not connected already
typeId - The typeId of the device connected to the gatewaydeviceId - The deviceId of the device connected to the gatewaylifetime - The length of time in seconds within
which the device must send another Manage device request.
if set to 0, the managed device will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the device supports firmware actions or not.
The device must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the device supports Device actions or not.
The device must add a Device action handler to handle the reboot and factory reset requests.bundleIds - array of bundle Ids to uniquely identify the device management extensionsorg.eclipse.paho.client.mqttv3.MqttException - when failurepublic boolean sendDeviceManageRequest(String typeId, String deviceId, DeviceData deviceData, long lifetime, boolean supportFirmwareActions, boolean supportDeviceActions) throws org.eclipse.paho.client.mqttv3.MqttException
Sends a device manage request to IBM Watson IoT Platform
A Gateway uses this request to manage the device connected to it, It should be the first device management request sent for the device after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway/Device to IBM Watson IoT Platform if its not connected already
typeId - The typeId of the device connected to the gatewaydeviceId - The deviceId of the device connected to the gatewaydeviceData - The DeviceData containing the information about the devicelifetime - The length of time in seconds within
which the device must send another Manage device request.
if set to 0, the managed device will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the device supports firmware actions or not.
The device must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the device supports Device actions or not.
The device must add a Device action handler to handle the reboot and factory reset requests.org.eclipse.paho.client.mqttv3.MqttException - when failurepublic boolean sendDeviceManageRequest(String typeId, String deviceId, DeviceData deviceData, long lifetime, boolean supportFirmwareActions, boolean supportDeviceActions, List<String> bundleIds) throws org.eclipse.paho.client.mqttv3.MqttException
Sends a device manage request to IBM Watson IoT Platform
A Gateway uses this request to manage the device connected to it, It should be the first device management request sent for the device after connecting to the IBM Watson IoT Platform. It would be usual for a device management agent to send this whenever is starts or restarts.
This method connects the Gateway/Device to IBM Watson IoT Platform if its not connected already
typeId - The typeId of the device connected to the gatewaydeviceId - The deviceId of the device connected to the gatewaydeviceData - The DeviceData containing the information about the devicelifetime - The length of time in seconds within
which the device must send another Manage device request.
if set to 0, the managed device will not become dormant.
When set, the minimum supported setting is 3600 (1 hour).supportFirmwareActions - Tells whether the device supports firmware actions or not.
The device must add a firmware handler to handle the firmware requests.supportDeviceActions - Tells whether the device supports Device actions or not.
The device must add a Device action handler to handle the reboot and factory reset requests.bundleIds - List of bundle Ids to uniquely identify the device management extensions that this device supports,
The device must add a Custom action handler to handle the custom action requestsorg.eclipse.paho.client.mqttv3.MqttException - when failurepublic int updateGatewayLocation(Double latitude, Double longitude, Double elevation)
latitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84public int updateDeviceLocation(String typeId, String deviceId, Double latitude, Double longitude, Double elevation)
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the Gatewaylatitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84public int updateGatewayLocation(Double latitude, Double longitude, Double elevation, Date measuredDateTime)
latitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84measuredDateTime - When the location information is retrievedpublic int updateDeviceLocation(String typeId, String deviceId, Double latitude, Double longitude, Double elevation, Date measuredDateTime)
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the Gatewaylatitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84measuredDateTime - When the location information is retrievedpublic int updateGatewayLocation(Double latitude, Double longitude, Double elevation, Date measuredDateTime, Date updatedDateTime, Double accuracy)
latitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84measuredDateTime - When the location information is retrievedupdatedDateTime - When the location information is updatedaccuracy - Accuracy of the position in meterspublic int updateDeviceLocation(String typeId, String deviceId, Double latitude, Double longitude, Double elevation, Date measuredDateTime, Date updatedDateTime, Double accuracy)
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the Gatewaylatitude - Latitude in decimal degrees using WGS84longitude - Longitude in decimal degrees using WGS84elevation - Elevation in meters using WGS84measuredDateTime - Date of location measurementupdatedDateTime - Date of the update to the device informationaccuracy - Accuracy of the position in meterspublic int clearGatewayErrorCodes()
public int clearDeviceErrorCodes(String typeId, String deviceId)
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the Gatewaypublic int clearGatewayLogs()
public int clearDeviceLogs(String typeId, String deviceId)
typeId - the device type of the attached devicedeviceId - the device Id of the attached devicepublic int addGatewayErrorCode(int errorCode)
errorCode - The "errorCode" is a current device error code that
needs to be added to the IBM Watson IoT Platform.public int addDeviceErrorCode(String typeId, String deviceId, int errorCode)
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the GatewayerrorCode - The "errorCode" is a current device error code that
needs to be added to the IBM Watson IoT Platform.public int addGatewayLog(String message, Date timestamp, LogSeverity severity)
message - The Log message that needs to be added to the IBM Watson IoT Platform.timestamp - The Log timestamp.severity - the LogSeverity.public int addGatewayLog(String message, Date timestamp, LogSeverity severity, String data)
message - The Log message that needs to be added to the IBM Watson IoT Platform.timestamp - The Log timestamp.severity - The LogSeverity.data - The optional diagnostic string data -
The library will encode the data in base64 format as required by the Platform.public int addDeviceLog(String typeId, String deviceId, String message, Date timestamp, LogSeverity severity)
typeId - The device type of the device connected to the Gateway.deviceId - The deviceId of the device connected to the Gateway.message - The Log message that needs to be added to the IBM Watson IoT Platform.timestamp - The Log timestamp.severity - The LogSeverity.public int addDeviceLog(String typeId, String deviceId, String message, Date timestamp, LogSeverity severity, String data)
typeId - The device type of the device connected to the Gateway.deviceId - The deviceId of the device connected to the Gateway.message - The Log message that needs to be added to the IBM Watson IoT Platform.timestamp - The Log timestampseverity - The LogSeveritydata - The optional diagnostic string data -
The library will encode the data in base64 format as required by the Platform .public boolean sendGatewayUnmanageRequet()
throws org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttException - When failurepublic boolean sendDeviceUnmanageRequet(String typeId, String deviceId) throws org.eclipse.paho.client.mqttv3.MqttException
typeId - The device type of the device connected to the GatewaydeviceId - The deviceId of the device connected to the Gatewayorg.eclipse.paho.client.mqttv3.MqttException - when failureprotected org.eclipse.paho.client.mqttv3.IMqttDeliveryToken publish(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) throws org.eclipse.paho.client.mqttv3.MqttException
org.eclipse.paho.client.mqttv3.MqttExceptionpublic void disconnect()
disconnect in class AbstractClientprotected void reconnect()
throws KeyManagementException,
NoSuchAlgorithmException
reconnect in class DeviceClientNoSuchAlgorithmException - TLS issuesKeyManagementException - TLS issuespublic void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message)
GatewayClientThis method is called by the MQTT library when a message(command) is sent by the IBM Watson IoT Platform.
The message(command) will be processed by this class and corresponding callback method will be called if registered.messageArrived in interface org.eclipse.paho.client.mqttv3.IMqttMessageListenermessageArrived in interface org.eclipse.paho.client.mqttv3.MqttCallbackmessageArrived in class GatewayClientpublic void addFirmwareHandler(DeviceFirmwareHandler fwHandler) throws Exception
Adds a firmware handler for both Gateway and devices connected through the gateway,
that is of type DeviceFirmwareHandler
If the Gateway/device supports firmware update, the abstract class
DeviceFirmwareHandler should be extended by the Gateway code.
The DeviceFirmwareHandler.downloadFirmware(com.ibm.wiotp.sdk.devicemgmt.DeviceFirmware) and
DeviceFirmwareHandler.updateFirmware(com.ibm.wiotp.sdk.devicemgmt.DeviceFirmware)
must be implemented to handle the firmware actions.
fwHandler - DeviceFirmwareHandler that handles the Firmware actionsException - throws an exception if a handler is already addedpublic void addDeviceActionHandler(DeviceActionHandler actionHandler) throws Exception
Adds a device action handler which is of type DeviceActionHandler
If the gateway or device supports device actions like reboot and factory reset,
the abstract class DeviceActionHandler
should be extended by the device code. The DeviceActionHandler.handleReboot(com.ibm.wiotp.sdk.devicemgmt.DeviceAction) and
DeviceActionHandler.handleFactoryReset(com.ibm.wiotp.sdk.devicemgmt.DeviceAction)
must be implemented to handle the actions.
actionHandler - DeviceActionHandler that handles the Reboot and Factory reset actionsException - throws an exception if a handler is already addedpublic void addCustomActionHandler(CustomActionHandler actionHandler) throws Exception
ExceptionCopyright © 2019. All rights reserved.