Device-cloud Intercommunication Experiment Based on Smart Home Scenario——Development of Smart Home Device-Cloud Interoperability Based on MQTT Protocol

Purpose

  1. Use Wi-Fi module and network based on MQTT protocol
  2. Upload the temperature and humidity sensor data to the cloud platform
  3. Process the command to turn on the buzzer issued by the platform
  4. Report the command response to the platform

When using the MQTT protocol to connect with the platform, the IP address and port number used are 121.36.42.100:1883

Experimental procedure

1. Fill in the hotspot information in the iot_main.h file

insert image description here

2. Create a device on HUAWEI CLOUD IoTDA

insert image description here
Fill in the registration information according to the form below:
insert image description here
insert image description here
insert image description here

3. Fill in the platform connection information in iot_main.h

insert image description here
insert image description here
The IP address and port of the connected server are the IP address and port number of the HUAWEI CLOUD IoT Platform MQTT server. The ID and password of the connected device are the ID and key of the previously registered device on the platform, and these two pieces of information are saved in the DEVICES-KEY.txt file.
insert image description here

4. Modify the smart home attribute definition in iot_main.h

These attributes need to correspond to the relevant attributes and command parameters in the product model created based on the MQTT protocol.
insert image description here
insert image description here

5. Add a header file to the original lab4.c

insert image description here

6. Add the missing temperature and humidity data format conversion code in lab4.c

insert image description here

7. Add the assembly humidity data logic in lab4.c

insert image description here

8. Add the logic of reporting sensor data missing in lab4.c to the platform

insert image description here

9. Add the missing buzzer code in lab4.c

insert image description here

10. Add the code to close the buzzer service in lab4.c

insert image description here

11. Add the business code for command execution in lab4.c

insert image description here

12. Add the code for reporting command response in lab4.c

insert image description here

13. Add the code to call lab4 in app_main.c

insert image description here

14. Compile, burn and reset the development board

Compilation is successful as shown below:
insert image description here
Burning
insert image description here
After successful burning, the result of reset:
insert image description here

15. View the results on the cloud platform

insert image description here

Guess you like

Origin blog.csdn.net/ungoing/article/details/129837965