pdf-icon

UIFlow - Integration - Azure

Overview

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.

Create a Project

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

Create an IoT Hub and register a new device through the Azure portal. Detailed steps can be found in the Azure official documentation.

Connection Information

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.

  • The Primary Connection String can be directly seen in the device property interface (as shown below).

Primary Connection String is visible in the device property interface.

Burn Firmware

Burn UIFlow firmware to your device (firmware version 1.7.3 and above required), click the document link below to view detailed burning steps.

UIFlow firmware burning steps

Write the Program

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.

Drag and drop code blocks in UIFlow as shown to write the program. The uploaded data format is JSON for easy expansion and transmission.

    Connection String: "Primary Connection String"
    SAS Token: "SAS Token"

Micropython API IoT_Hub

# 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()

Micropython API IoT_Central

# 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()

Send Messages to the Device

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.

Add connection in Azure-IoT-Explorer and enter the connection key.

Enter the connection key in Azure-IoT-Explorer to connect.

After configuration, you can get the list of devices contained in the current application.

Get the list of devices contained in the application using Azure-IoT-Explorer.

Select a device to enter its details page, and use the Cloud-to-device message feature to implement information distribution.

View Device Uploaded Data

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

On This Page