IntroductionRecently, I tried the Alibaba Cloud IoT platform, which has quite powerful features. Here are some experiences I would like to share.
Hardware
lMicrocontroller: STM32F103C8T6
lNetwork Connection: ESP8266 WIFI Module
lSensors: PM2.5 Sensor, Temperature and Humidity Sensor
The sensor drivers and the WIFI module driver are relatively simple; previous articles have also introduced them, so I won’t go into detail here.
Setting Up Alibaba Cloud IoT Platform
1. Register on the Alibaba Cloud IoT platform; details are not provided here.
2. Create a product and choose the advanced version.
3. Select the product attributes as shown in the image, then click finish. Once added, you will see the device in the product list.
4. Add product features. Click to view in the device list, check product details, and under the function definition menu, add product features. The identifier will be used in programming later.
5. Add a device. In the device menu, click to add a device, choose the product just created, give the DeviceName any name, and click confirm.
6. After adding, check the device’s detailed information, where ProductKey, DeviceName, and DeviceSecret will be used in programming later.
7. The Topic list will automatically generate some Topics; we will use the first one later.
Microcontroller Programming
With the platform set up, the next step is the microcontroller programming.
1. For the MQTT protocol porting, use paho.mqtt.embedded-c-master, which utilizes files from the MQTTPacket\src directory and the MQTTPacket\samples directory’s transport.c and .h files. The only modifications needed are in transport.c for two functions, one for sending and one for receiving.
2. Opening and closing connections have already been implemented in the ESP8266 (ESP8266 operates in TCP transparent mode), so it directly returns 0.
3. cJSON also needs to be ported; only two files, cJSON.c and cJSON.h, need to be added to the project, and you can directly call the functions inside.
4. Connect to the MQTT server; the program is as follows. Parts omitted are noted later. There is an “&” symbol in the username. The password can be generated by a tool or a function.
5. Generate cJSON strings by calling cJSON functions to create strings, where the internal parameters of params are the identifiers used when adding product features.
6. Publish messages. The function parameters char* pTopic are strings from the device Topic list’s first entry, char* PMessage is the string just generated. By checking the feedback from the published message, you can determine if the server connection is normal; if not, reconnect.
7. After successful publishing, you will see the information uploaded by the device on the management platform, as well as the historical curve.
Conclusion
The IoT platform has many features, and you can also directly generate WEB pages and mobile APP programs on the platform, although the functionality is not yet very complete. There are also many other IoT platforms, such as OneNET, which have similar functionalities, and those interested can give them a try.