This tutorial will demonstrate how to connect programming devices to the Azure IoT cloud service platform through UIFlow programming, using the construction of a temperature and humidity collection node as a case study.
Before integration, you need to create an IoT Hub and register a new device through the Azure portal. Click here to access the Azure official documentation for details
After completing the device creation according to the Azure official documentation, before connecting to Azure IoT, we need to obtain two strings: Primary Connection String
and SAS Token
.
Primary Connection String
can be directly seen in the device property interface (as shown below).Burn UIFlow firmware to your device (firmware version 1.7.3 and above required), click the document link below to view detailed burning steps.
The data format uploaded in the case program is JSON
, which facilitates the subsequent expansion and transmission of data, such as extending to applications like Power BI.
Connection String: "Primary Connection String"
SAS Token: "SAS Token"
# Initialize connection
azure = IoT_Hub(connection_string='')
# Certificate access method
azure = IoT_Hub(device_id='', host_name='', ssl=True, cert_file_path='', private_key_path='')
# Enable connection
azure.start()
# Subscribe to direct_method information
azure.subscribe_direct_method(topic, azure_direct_fun)
# Subscribe to cloud data callback
azure.subscribe_C2D_message(azure_C2D_cb)
# Publish data to the cloud
azure.publish_D2C_message()
# Upload data to the cloud device instance (Device Twin)
azure.update_twin_reported_properties(key1='value', key2='value')
# Pass data to the cloud device instance (Device Twin) response callback
azure.subscribe_twin_desired_response(azure_desired_cb)
# Retrieve properties owned by the cloud device instance (Device Twin)
azure.retrieve_twin_properties()
# Initialize connection
azure = IoT_Central(scope_id='', device_id='', device_key='')
# Enable connection
azure.start()
# Subscribe to direct_method information
azure.subscribe_direct_method(topic, azure_direct_fun)
# Subscribe to cloud data callback
azure.subscribe_C2D_message(azure_C2D_cb)
# Publish data to the cloud
azure.publish_D2C_message()
# Upload data to the cloud device instance (Device Twin)
azure.update_twin_reported_properties(key1='value', key2='value')
# Pass data to the cloud device instance (Device Twin) response callback
azure.subscribe_twin_desired_response(azure_desired_cb)
# Retrieve properties owned by the cloud device instance (Device Twin)
azure.retrieve_twin_properties()
After pushing the code to Core2, the device will start uploading data according to the program content. There are various ways to view the data; this case will demonstrate using the Azure-IoT-Explorer tool to view the uploaded data. Click to visit the Azure-IoT-Explorer download page
After downloading, double-click to open, click Add connection
and fill in the connection key. Enter the corresponding key (the key string can be obtained in Iot Hub
- Settings
- Shared access policies
- `iothub
owner-Primary connection string` in the Azure portal, as shown below) and confirm.
After configuration, you can get the list of devices contained in the current application.
Select a device to enter its details page, and use the Cloud-to-device message
feature to implement information distribution.
Azure-IoT-Explorer currently does not support viewing D2C data. Users can use the VSCode - Azure IoT Hub plugin for data listening and distribution. For more content, please see VSCode - Azure IoT Hub plugin Github