Due to various reasons, the devices registered with WSO2 IoT Server might not be able to communicate with the server continuously. When the device is not actively communicating with the server you need to know of it to take necessary actions, such as checking if the device has any malfunctions and repairing it.
To get a clear understanding, let's look at how this works in WSO2 IoT Server.
If the device and the server are actively communicating, the device will be shown as active.
- If the server is unable to communicate with the device for more than 300 seconds, the device will be shown as unreachable.
- If the server is still unable to communicate with the device for more than 600 seconds, the device will be shown as inactive.
- If the device starts to communicate with the device after some time, the device status is updated back to active.
The device's status has the following lifecycle:
The device monitoring task is not applicable for all IoT devices. Therefore, you can choose to enable or disable it for your device type. Let's take a look at how you can configure WSO2 IoT Server and your device type to monitor the device status.
Open the
<IOTS_HOME>/conf/cdm-config.xml
file and make sure theDeviceStatusTaskConfig
is enabled. This configuration is enabled by default.If the
DeviceStatusTaskConfig
is enabled (or enabled on a node that is in a clustered setup) it will run the status monitoring task in the server. If the configuration is disabled, the server will not monitor the status of the devices.<DeviceStatusTaskConfig> <Enable>true</Enable> </DeviceStatusTaskConfig>
Configure the device type to go into the unreachable state and then to the inactive state after a specified time.
Navigate to the<IOTS_HOME>/repository/deployment/server/devicetype
directory, open the<DEVICE_TYPE>.xml
file, and configure the fields given below:
The default configuration in theandroid.xml
file is shown below:<DeviceStatusTaskConfig> <RequireStatusMonitoring>true</RequireStatusMonitoring> <Frequency>300</Frequency> <IdleTimeToMarkUnreachable>300</IdleTimeToMarkUnreachable> <IdleTimeToMarkInactive>600</IdleTimeToMarkInactive> </DeviceStatusTaskConfig>
RequireStatusMonitoring
If the value is set to true, it enables the status monitoring task for the device type. Else it will not monitor the status of the device type.
For the task to run on the specified device type it must be enabled on the server as shown in step 1 above .
Frequency
Define how often the server needs to communicate with the device. The value needs to be given in seconds.
Make sure to have the value above 60 seconds.IdleTimeToMarkUnreachable
Define after how long the device needs to be marked as unreachable. The value needs to be given in seconds. IdleTimeToMarkInactive
Define after how long the device needs to be marked as inactive. The value needs to be given in seconds.