Purpose
- Use Wi-Fi module and network based on MQTT protocol
- Upload the temperature and humidity sensor data to the cloud platform
- Process the command to turn on the buzzer issued by the platform
- 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
2. Create a device on HUAWEI CLOUD IoTDA
Fill in the registration information according to the form below:
3. Fill in the platform connection information in iot_main.h
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.
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.
5. Add a header file to the original lab4.c
6. Add the missing temperature and humidity data format conversion code in lab4.c
7. Add the assembly humidity data logic in lab4.c
8. Add the logic of reporting sensor data missing in lab4.c to the platform
9. Add the missing buzzer code in lab4.c
10. Add the code to close the buzzer service in lab4.c
11. Add the business code for command execution in lab4.c
12. Add the code for reporting command response in lab4.c
13. Add the code to call lab4 in app_main.c
14. Compile, burn and reset the development board
Compilation is successful as shown below:
Burning
After successful burning, the result of reset: