Cloud to Device (C2D) messages
This article merely provides the message data structures for the C2D communication with IoTConnect Device SDK or Bring your own Custom SDK.
Device Command C2D
When receiving the C2D messages using an MQTT client implementation, ensure that MQTT messages are acknowledged at the MQTT level (QOS1). Otherwise, the device may receive repeat C2D messages if it disconnects and comes back online within a short time.
The following JSON will be received by the device when there is any command sent from the IoTConnect portal.
{ "ct": 0, "v": 2.1, "cmd": "A String represents the command text", "ack": "A string represents guid as the acknowledgement id", } ** "ack": is optional, required when command has acknowledgement
{ "ct": 0, "v": 2.1, "cmd": "A String represents the command text", "id": "A string represents child device UniqueID", "ack": "A string represents guid as the acknowledgement id", } ** "ack": is optional, required when command has acknowledgement
OTA Command C2D
The following JSON will be received by the device when there is any OTA sent from the IoTConnect portal.
{ "ct": 1, "v": 2.1, "cmd": "ota", "ack": "A string represents ota acknowledgement guid", "sw": "1.0.0", "hw": "1.0.0", "urls": [{ "url": "A string represents downloadable OTA update url with expiry", "fileName": "A string represents ota filename with extension" } ] } ** "cmd": command text, default is ota, can be changed from template
{ "ct": 1, "v": 2.1, "cmd": "ota", "ack": "A string represents ota acknowledgement guid", "sw": "1.0.0", "hw": "1.0.0", "urls": [{ "url": "A string represents downloadable OTA update url with expiry", "fileName": "A string represents ota filename with extension", "tg": "A string represents tag of device" } ] } ** "cmd": command text, default is ota, can be changed from template
Module Command C2D
The following JSON will be received by the device when there is any module push sent from IoTConnect portal.
{ "ct": 2, "v": 2.1, "ack": "A string represents ota acknowledgement guid", "urls": [{ "url": "A string represents downloadable OTA update url with expiry", "fileName": "A string represents ota filename with extension" } ] } ** "ack": is optional, required when module has acknowledgement
Other Commands C2D
The platform can send the below command to ask the device to do some operation. This can be a metadata update request or stop communication etc. All these messages will have the below format, based on the type of device that must react.
{ "ct": 101 "v": 2.1 } ** "ct": // Number represents the command type; possible values can be 101 to 111
Possible values of ct can be
ct | Command | Action |
Device Commands | ||
0 | Device command | Device command received by the device from the cloud |
1 | OTA Command | OTA Command received by the device from the cloud |
2 | Module Command | Module Command received by the device from the cloud |
101 | Refresh Attribute. | The device must send a message of type 201 to get updated attributes |
102 | Refresh Setting/Twin. | The device must send a message of type 202 to get updated settings or twin |
103 | Refresh Edge Rule. | The device must send a message of type 203 to get updated Edge rules |
104 | Refresh Child Device. | The device must send a message of type 204 to get updated child devices |
105 | Data Frequency Change | The device needs to update the frequency received in this message |
Device lifecycle Commands | ||
106 | Device Deleted | The device must stop all communication and release the MQTT connection |
107 | Device Disabled | The device must stop all communication and release the MQTT connection |
108 | Device Released | The device must stop all communication and release the MQTT connection |
109 | Stop Operation | The device must stop all communication and release the MQTT connection |
Heartbeat commands | ||
110 | Start Heartbeat | The device must start sending a heartbeat |
111 | Stop Heartbeat | The device must stop sending a heartbeat |
105 – Data Frequency Change Message: { "ct": 105, "v": 2.1, "df": 30 }
110 - Start Heartbeat command: { "ct": 110, "v": 2.1, "f": 5 } ** "f": A number (in seconds) represents new frequency of sending heartbeat from device