Need a quote? A specific configuration, a project? Contact us on 02 51 99 13 03 .

How to Remotely Control Devices via MQTT on Milesight Gateway

Comment contrôler à distance des appareils via MQTT sur Milesight Gateway

luna fouilleul |

Description

When operating as an integrated network server, Milesight LoRaWAN gateways support both sending data packets to a third-party MQTT/HTTP/HTTPS server or receiving downlink commands to forward to LoRaWAN endpoints.

Requirement

  • Milesight LoRaWAN Gateway: UG56, UG63 V1, UG65, UG67, UG8x (firmware version 80.0.0.64 or later)
  • MQTT server/broker
  • MQTT client tool: take MQTT Explorer as an example

Configuration

Step 1. Connect the gateway to the MQTT broker .

See the article How to connect LoRaWAN gateway to MQTT broker? to connect the gateway to the MQTT broker and ensure that the MQTT broker and client can receive uplinks from the devices.

Step 2. Send a downlink command from the gateway

Configure the gateway to send downlink commands directly to the device to check whether the device can receive the downlink commands and perform actions.

Device EUI: The device EUI for sending downlink commands

Type: Downlink command type. For Milesight devices, please select hexadecimal type .

Payload: Contents of the downlink command (obtained from the device manufacturer). For Milesight devices, please refer to the contents of downlink commands in the corresponding user guides

Port: Application port of the device. It is 85 by default for Milesight devices.

Confirmed: Once enabled, the device will send the confirmed packet back to the gateway if it receives the command. If not received, the gateway will resend the downlink command a maximum of 3 times.

Note: For Class A devices, the gateway will add the command to the queue and send it when the Class A device sends uplinks.

Step 3. Post the topic to MQTT Explorer to send downlink data to the device.

Define a downlink data subject. If you need to send an MQTT downlink to a specific device, please add "$deveui" to the subject.

Example : /milesight/downlink/$deveui

Post topic format:

/milesight/downlink/[devEUI]

Example :

From the gateway we can obtain the EUI of the device we want to control:

We can therefore publish a topic on MQTT Explorer as below:

Subject: /milesight/downlink/24e124126a148401

Format: json

Content:

send as below format and replace data content with downlink command

{"confirmed": true, "fport": 85, "data": "CQEA/w=="}
JavaScript

After clicking Publish , we can go to Network Server > Packets to check. If the gateway has successfully subscribed the corresponding downlink subject data, there will be at least one grayed out message packet record.

Milesight Device Command Examples

The MQTT downlink command format is fixed as below:

 { 
"confirmed" : true , //Set as true or false
 "fport" : 85 , //application port of device
 "data" : "BwAA/w==" //base64 format downlink command 
}  
JavaScript

For Milesight devices, click here to convert the command from hexadecimal to base64 format. Here are common Milesight controller commands:

Model

Order

Command (hexadecimal)

Command (base64)

UC50x

Set GPIO1 low

Set GPIO1 to high

Set GPIO2 low

Set GPIO2 to a high level

030000ff

030100ff

040000ff

040100 and following

AwAA/w==
AwEA/w==
BAAA/w==
BAEA/w==

UC300

Set DO1 low

Set DO1 high

Set DO2 low

Set DO2 high

070000ff

070100ff

080000ff

080100 and following

BwAA/w==
BwEA/w==
CAAA/w==
CAEA/w==

UC11xx

Set DO1 low

Set DO1 high

Set DO2 low

Set DO2 high

090000ff

090100 and following

0a0000ff

0a0100ff

CQAA/w==
CQEA/w==
CgAA/w==
CgEA/w==