This tutorial will demonstrate how to connect programming devices to the Tencent Cloud platform through UIFlow programming, using the construction of a temperature and humidity collection node as a case study.
Before starting the integration, register and log in to the
Tencent Cloud - IoT Development Platform
, click Public Instance
-> Create Project
-> Fill in Project Name/Description
-> Save
A product can be understood as a collection of a certain type of devices. Users manage all devices under the product. Click on the project created in the previous step
-> Enter the Product Development Center
-> Create a Product
-> Define Your Product
-> Fill in the Basic Product Information
-> Save
.
Set the basic product information as shown in the picture, where the name can be customized, but other settings are recommended to remain consistent.
Data templates digitally describe physical entity devices, constructing their digital models. Defining a data template on the IoT development platform means defining the product's functionality. After completing the functionality definition, the system will automatically generate the data template for the product. Since we chose a custom product, it does not have standard functions, and we need to define the functions ourselves. Click on the product created
-> Create Function
.
As shown below, define the temperature and humidity functions separately. In actual applications, you can add more function definitions according to your own needs.
After defining the functions, click Device Debugging
above -> Click to Create a New Device
-> Fill in the Device Name
-> Save
. Click on the device that has been successfully created to view the details page. (This will include the keys and device-related information needed for UIFlow connection)
Burn UIFlow firmware to your device (firmware version 1.7.3 and above required). Click the document link below to view detailed burning steps.
product id: Product ID, can be viewed on the device information interface
device name: Device name, as above
device secret: Device secret, as above
keepalive: Heartbeat time 0 ~ 120 (seconds)
from IoTcloud.Tencent import Tencent
# Initialize connection
tencent = Tencent(
product_id='XXXXXXXXXXX',
- Micropython API
```python
from IoTcloud.Tencent import Tencent
//Initialize connection
tencent = Tencent(
product_id='XXXXXXXXXXX',
device_name='XXXXXXX',
username='XXXXXXXXXXXXXXXXXX;12010126;B335D;1702277766',
password='e822dc0027a1b363f9ed1a23fb77860c0b707d7d;hmacsha1',
port=1883,
keepalive=30
)
//upload data
tencent.publish_property_msg(temperature=temp,humidity=humid)
//Downlink data callback
def tencent_fun(property_data):
print(property_data)
//The subscription platform sends messages
tencent.subscribe_property_msg(tencent_fun)
The code block below is used to push data to the cloud platform, and the data is sent as a 'key-value', where the 'key' value needs to be consistent with the 'identifier' in the custom function. When the device is running, you can view the uplink data of the device in the device logs.
Tencent cloud service and the small program 'Tencent Lianlian' integration docking, users can be very convenient through the small program to view the reported data of the device. 'Device list' -> 'Device QR code'. (Open wechat mini program 'Tencent Lianlian' and click '+' to scan the code and bind the device).