Microsoft Azure is a cloud computing platform and an online portal that allows you to access and manage cloud services and resources provided by Microsoft. These services and resources include storing your data and transforming it, depending on your requirements. To get access to these resources and services, all you need to have is an active internet connection and the ability to connect to the Azure portal.

Azure Platform supports to forward the data through HTTPs and MQTT, this article describes how to connect Milesight LoRaWAN Gateway to Microsoft Azure using MQTT.

Note: Milesight gateways only support sending uplinks to Azure via MQTT, downlink is not supported.


1. Milesight LoRaWAN Gateway (UG56/UG6x/UG8x)

2. Microsoft Account

3. Visual Studio Code App installed in windows


Step1. Apply for Azure Account and Login the Portal

Step2. Create IoT Hub after Login

Step3. Create a Device

Step4. Configure the MQTT Details in Milesight Gateway

Step5. Create SAS Token for Gateway in Visual Studio Code

Step6. Check the Device Status

Step7. Check the Sensor Data

Trouble Shooting


Step1. Apply for Azure Account and Login the Portal

Create a Microsoft account then login Azure by the following URL:

Step2. Create IoT Hub after Login

From the Azure homepage, select the + Create a resource button, and then enter IoT Hub in the Search the Marketplace field. Select IoT Hub from the search results, and then select Create

You will need to input and choose the subscription, Region and set the IoT Hub name there.

Step3. Create a Device

You will need to input the Device ID, which will be used in the Gateway's 'Client ID' field for MQTT communication. In this example, the name is UG85

Click save, then the configuration in Microsoft Azure side is finished.

More detailed info about the portal configuration, you can also refer to this page

Step4. Configure the MQTT Details in Milesight Gateway

Login Milesight Gateway’s web interface, create an application in ‘Network Server->Applications’ page.

Input the application name and the description, then click Save

Edit the Application we created just now, then choose MQTT in the Type list.

You will find the options below

In this page we can configure the MQTT details here:

Here are the details for Azure Portal.

Broker: hostname:8883

ClientID: {device-id}

Username: hostname/{device-id}

Password: SAS Token (Generate by Connecting string, the Token will be generated in Step5.

TLS: enabled and select as CA signed server certificate

Publish topic: devices/{device-id}/messages/events/

For more info about the MQTT details definition, try to click this URL.

Note: The Client ID should be Unique for each gateway you want to configure in Azure.

Step5. Create SAS Token for Gateway in Visual Studio Code

Download Visual Studio Code, and install it into your Windows PC, search and install the Azure IoT Hub in the Visual Studio code.

Login using your Microsoft account, you can see the IoT Hub here.

Press ctrl+shift+p key, Choose 'generate SAS Token for device'.

Choose the device UG85 in this example. If you create other device in the same portal, it will display here as well.

Configure the expiration time, in this example is 300

You will get the SAS Token

Note: To extend the SAS token’s expire time, you can set 31,536,000 seconds for one year or more, then you will not need to worry about renewing it.


Step6. Check the Device Status

Copy the Token in the MQTT configuration, click Save, then we can check the MQTT connection status here:

You can also get the device status info in Visual Studio Code as well by Get Device Info.

Step7. Check the Sensor Data

Try to add a LoRaWAN sensor in Device page, input the DevEUI, AppKey, choose the Application we create just now.

Click Save&Apply, then power on the sensor. When the sensor is online. You will see these real-time output in Azure Console.

Here is an example log output:

naytelwmykt@Azure:~$ az extension add --name Azure-cli-iot-ext 

naytelwmykt@Azure:~$ az iot hub monitor-events --hub-name sway-iothub --output table Starting event monitor, use ctrl-c to stop...

You will get the event like this, which is the uplink data from the Gateway.

event: origin: ug85 payload: '{"applicationID":"1","applicationName":"app","data":"AwAABAEA","devEUI":"24E124C0002A1234","deviceName":"n1","fCnt":5,"fPort":85,"rxInfo":[{"altitude":0,"latitude":0,"loRaSNR":8.5,"longitude":0,"mac":"24e124fffef0395d","name":"local_gateway","rssi":-28,"time":"2020-06-03T08:14:23.868355Z"}],"time":"2020-06-03T08:14:23.868355Z","txInfo":{"adr":true,"codeRate":"4/5","dataRate":{"bandwidth":125,"modulation":"LORA","spreadFactor":7},"frequency":868300000}}'


Since the Data here is still the original one, we need to load the decode to make it understandable. In this example, the sensor is AM107, you can find the decoder here:

Edit the Application.

Choose Custom in the Payload Codec field.

Then copy the decoder and paste it in Payload Decoder Function page.

Click Save, then you will see the data print in Visual Studio Code in next uplink.

event: origin: ug85 payload:
"battery": 92,
"temperature": 30.8,
"humidity": 50.5,
"activity": 73,
"illumination": 28,
"infrared": 20,
"infrared_and_visible": 121,
"co2": 1255,
"tvoc": 7,
"pressure": 1004.7

Note: If you configure the sensor from other company, you need to contact their support to get the Decoder Script (Java Script), then configure it there.

For more commands about Azure CLI, try to refer to this page.


Trouble Shooting

If MQTT connection status is Connect Failed, you will need to check the network settings of the gateway, make sure you can ping the MQTT Broker’s address correctly. Then check the MQTT configuration details, make sure the value you input follows the rule.

If you didn't find the data output when the MQTT is connected, try to check the "lora-app-server.log" inside the Gateway's system log, and check whether you can see the logs like this. You can download it through Maintenance->Log page.

 This is the log that shows the gateway has forwarded the data to Azure through MQTT

time="2020-06-03T16:15:26+08:00" level=info msg="urhandler/mqtt: publishing message" deveui=24E124C0002A1234 qos=0 topic=devices/ug85/messages/events/

You can also Deliver Ticket and attach the full description and the log package for a deeper check.