Server Communicating with the Device
When you send a command to a device, it goes through the WSO2 IoT Server transport sender mechanism. For example, switching on or switching off the bulb on the RaspberryPi device type. To identify the flow of what happens when WSO2 IoT Server receives the command, and how it communicates take a look at the diagram given below:
Let's understand this clearly by using the RaspberryPi device type:
Write the API to switch the bulb on. Once WSO2 IoT Server receives the command it will call the API you have written to switch the bulb on.
For more more information, see Writing Device APIs.
Define the operation type for the API in the
<DEVICE_TYPE>SeviceImpl.java
file. WSO2 IoT Server supports the following 4 operation types.POLICY
COMMAND
CONFIG
PROFILE
Example: The
RaspberryPiServiceImpl.java
file has configured the bulb switching on and off API as aCOMMAND
operation.Operation commandOp = new CommandOperation(); commandOp.setCode("bulb"); commandOp.setType(Operation.Type.COMMAND); commandOp.setEnabled(true); commandOp.setPayLoad(actualMessage);
Assign the properties you defined in step 2 above to a publisher topic as done in the
RaspberryPiServiceImpl.java
file.Properties props = new Properties(); props.setProperty(RaspberrypiConstants.MQTT_ADAPTER_TOPIC_PROPERTY_NAME, publishTopic); commandOp.setProperties(props);
The command is then sent to the device.
Follow the steps given below to find out if the device received the command:Sign in to the WSO2 IoT Server device management console.
- Click the device you sent the command.
Example: Click virtual fire alarm. Click Operation logs, to view the status of the command you sent.
The operation status can be any of the following values:
IN-PROGRESS
- The operation is processing on the IoTS server side and has not yet been delivered to the device.PENDING
- The operation is delivered to the device but the response from the device is pending.COMPLETED
- The operation is delivered to the device and the server has received a response back from the device.ERROR
- An error has occurred while carrying out the operation.