UIFlow-Access-Azure

Overview

This tutorial will take building a temperature and humidity collection node as an example to demonstrate how to access the Azure IoT cloud service platform through a UIFlow programming device.

Create project

Before accessing, you need to create an IoT center through the Azure portal and register a new device. Click here to visit Azure official documentation for details

Connection information

After creating the device according to the official Azure documentation, before connecting to Azure IoT, we need to obtain two strings, namely Primary Connection String and SAS Token.

  • Among them, Primary Connection String, we can directly see the device property interface (as shown in the figure below).

Burn firmware

Burn UIFlow firmware for your device (firmware requires v1.7.3 and above), click the corresponding document link below to view the detailed programming steps.

UIFlow firmware burning steps

Programming

The data format uploaded in the case program is JSON, which can facilitate the subsequent expansion and transmission of data, such as extension to Power BI and other applications.

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

//direct_method information subscription
azure.subscribe_direct_method(topic, azure_direct_fun)

//Monitor cloud data callback
azure.subscribe_C2D_message(azure_C2D_cb)

//Publish data to the cloud
azure.publish_D2C_message()

//Upload data to cloud device instance (Device Twin)
azure.update_twin_reported_properties(key1='value',key2='value')

//Transfer data to the cloud device instance (Device Twin) in response to callback
azure.subscribe_twin_desired_response(azure_desired_cb)

//Get the attributes 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()

//direct_method information subscription
azure.subscribe_direct_method(topic, azure_direct_fun)

//Monitor cloud data callback
azure.subscribe_C2D_message(azure_C2D_cb)

//Publish data to the cloud
azure.publish_D2C_message()

//Upload data to cloud device instance (Device Twin)
azure.update_twin_reported_properties(key1='value',key2='value')

//Transfer data to the cloud device instance (Device Twin) in response to callback
azure.subscribe_twin_desired_response(azure_desired_cb)

//Get the attributes owned by the cloud device instance (Device Twin)
azure.retrieve_twin_properties()

Send message to device

After pushing the code to Core2, the device will start uploading data according to the content of the program. The way to view data is not unique. This case will demonstrate viewing uploaded data through the Azure-IoT-Explorer tool. Click to visit the Azure-IoT-Explorer download page

After the download is complete, double-click to open, click on Add connection to fill in the connection key, enter the corresponding key and confirm (the incoming key string can be found in the Azure portal, in the Iot Center-Settings-Shared access policy-iothubowner-Primary connection string, as shown in the figure below).

After the configuration is complete, you can get the list of devices included in the current application

Select the device to enter the details page, and use the Cloud-to-device message function to deliver information.

View device upload data

Azure-IoT-Explorer does not currently support viewing D2C data. Users can monitor and distribute data through VSCode-Azure IoT Hub plug-in . For more information, please see VSCode-Azure IoT Hub Plugin Github

On This Page