The actual development of the IoT platform "device shadow"

Introduction: The actual development of IoT platform "device shadow"

image.png

The IoT platform provides the device shadow function, and reports the status value and the expected value of the business system through a JSON file persistent storage device in the cloud . Each device has one and only one device shadow. The device can obtain the expected value desired and set the device status reported through the MQTT protocol , and the business system obtains the device status reported and set the expected value of the device through the HTTPS protocol .

 

  • The device can actively report the running status, and the business system can read it at any time without caring whether the device is online.
  • After the cloud business system sets the expected value for the specified device, if the device is online, it can receive the cloud expected value change in real time; the device is offline and online again to actively pull the cloud expected value.

 

Two topics of device shadow communication:

image.png

 

Device shadow JSON

In the IoT IoT platform console, you can view the device shadow for device details , the default shadow JSON data, as shown below:

image.png

 

1. Update device status reported

The IoT device can actively update the current state data to the cloud device shadow (reported) node, and the communication message is as follows:

image.png

 

After successfully updating the cloud device shadow, the device will receive a response message from the cloud, as follows:

image.png

 

We can view the complete device shadow JSON file in the device shadow of the device details in the IoT console, as shown below

image.png

 

2. Get device status reported

The business system can obtain the device status data (reported) by calling the GetDeviceShadow API of the device shadow . The sample code is as follows (Node.js):

image.png

 

The returned result is as follows, where ShadowMessage is the string form of device shadow JSON, as shown in the figure below:

image.png

 

3. Set equipment expectations desired

The business system calls the UpdateDeviceShadow API to set the desired value (desired) for the device. The code example is as follows (Node.js):

image.png

 

After the setting is successful, we can view the latest shadow file in the device shadow of the device details in the IoT console, as shown below:

image.png

 

At the same time, the online device will receive the device shadow message push in real time, the content is as follows:

image.png

Offline devices can actively obtain device shadows when they go online again

image.png

 

The cloud responds to the device shadow message push, the content is as follows:

image.png

 

4. Delete the device shadow

The device can actively delete device shadow attributes, where method is delete and the value of the attribute to be deleted is null .

image.png

 

After the deletion is successful, we can view the device shadow in the console as shown below:

image.png

 

When the device reports, set reported to null to delete all attribute values.

image.png

 

After the deletion is successful, we can view the device shadow in the console as shown below:

image.png

 

5. Incremental delta and rule engine events

The device shadow of the Alibaba Cloud IoT platform does not support incremental delta push . After the device updates the shadow state, it will not trigger the rule engine to transfer message events, and the business system cannot perceive the device status (reported) changes in real time .

 

Recommended in the past

 

1. 39 GIF diagrams of sensor working principle

2. Development practice of smart handheld temperature measuring gun

3. JMeter pressure measurement MQTT service performance actual combat

4. Detailed explanation of log service of IoT platform

5. Self-built MQTT cluster migration practice of Alibaba Cloud IoT

6. Industrial Modbus power 104 protocol access to IoT platform

7. The device does not need to burn the triplet, and the solution is registered immediately

8. IoT+TSDB+Quick BI builds building environment monitoring

9. JS full-stack development to build smart home applets

 

Guess you like

Origin blog.csdn.net/weixin_43970890/article/details/115230658