How to Connect LoRaWAN Gateway to MQTT Broker?

Andy Chen
Related Product: IOT-G65 IOT-G67

Description

When working as embedded network server, Linovision LoRaWAN gateways support sending data packets to third party MQTT/HTTP/HTTPS server. We can create a new application on gateway, which can define the method of decoding the data sent from LoRaWAN end-device and choosing MQTT data transport protocol to send data to MQTT server.

 

 

Requirement

  •  LoRaWAN Gateway: IOT-G8x (Firmware version 80.0.0.64 or later), IOT-G65, IOT-G67, IOT-G56, IOT-G63 V1
  • MQTT Server/Broker
  • MQTT client tool: take MQTT Explorer as example

 

Configuration

Step1. Enable the gateway built-in network server.

Go to Packet Forwarder > General to enable the localhost server address.

 

 

Enable the Network server on Network Server > General page.

 

 

 

Step2. Add an Application

Go to Network Server>Applications to add a new application, click save.

Name: user-defined, arbitrary value

Description: user-defined, arbitrary value

 

 

 

 

Step3. Connect gateway to MQTT broker.

Go to Network Server > Applications to add a “data transmission” for the application. One application can add only one MQTT integration.

 

 

 

 

 

Fill in the MQTT broker information and create topic to store different data type, click save.

Broker Address: IP address/domain of MQTT broker

Broker Port: communication port of MQTT broker

Client ID: user-defined, a unique ID identity of the client to the server.

User Credentials and TLS should be enabled and configured as required.

Note: if MQTT broker is HiveMQ, please do enable TLS and set the option as CA signed server certificate.

 

 

After MQTT configuration complete, you can check connection status here:

 

 

Step4. Add LoRaWAN nodes to the gateway.

Go to Network Server>Profiles to add a new profile, then click save. You can also use pre-defined profiles.

Name: user-defined, arbitrary value

Max TXPower: default value

Other parameters can be checked from LoRaWAN nodes user guide or you can keep all settings by default.

 

 

 

Go to Network Server>Device to add a new device, click Save&Apply.

Device Name: user-defined, arbitrary value

Description: user-defined, arbitrary value

Device-Profile: choose one of corresponding profiles added before.

Application: choose one of corresponding applications added before.

Other parameters can be confirmed with the LoRaWAN node manufacturers.

 

 

When the status shows as below, that’s mean above steps are done correctly.

 

 

 

Step5. Add uplink data topic.

Customize the uplink data to publish to MQTT broker and save the settings. If you add “$deveui” on your topic, you can replace it as real device EUI when subscribing topics. 

Example: /linovision/uplink/$deveui

 

 

 

 

Step6. Subscribe topic from MQTT client to get uplinks.

MQTT explorer is a comprehensive MQTT client and it can be replaced to other kinds of MQTT client tools(MQTT.fx, MQTT Box, etc.)

Open the MQTT Explorer, and fill in related MQTT server information in the popup window.

Name: user-defined

Protocol: mqtt://

Host: MQTT broker address

Port: broker port

User name/Password: if there is user credentials, please fill in it. If not, keep them blank.

 

 

Click ADVANCED,copy the Uplink data topic on the gateway, and paste it on the MQTT explorer, click +ADD.

 

  

 

Keep MQTT client ID by default,then click BACK and click CONNECT.

 

 

After while, the data will be forwarded to MQTT broker and the MQTT Exploerer can receive the data from MQTT server.

 

The uplink format is fixed as json and the content is as below.

 

{
  "applicationID": 1,                   // application ID
  "applicationName": "cloud",           // application name
  "deviceName": "24e1641092176759",     // device name
  "devEUI": "24e1641092176759",         // device EUI
  "time": "2020-0327T12:39:05.547336Z", // uplink receive time
  "rxInfo": [                           // lorawan gateway information related to lora
    {
      "mac": "24e124fffef021be",        // ID of the receiving gateway
      "rssi": -57,                      // signal strength (dBm)
      "loRaSNR": 10,                    // signal to noise ratio
      "name": "local_gateway",          // name of the receiving gateway
      "latitude": 0,                    // latitude of the receiving gateway
      "longitude": 0,                   // longitude of the receiving gateway
      "altitude": 0                     // altitude of the receiving gateway
    }
  ],
  "txInfo": {                           // lorawan node tx info
    "frequency": 868300000,             // frequency used for transmission
    "dataRate": {
      "modulation": "LORA",             // LORA module
      "bandwidth": 125,                 // bandwidth used for transmission
      "spreadFactor": 7                 // spreadFactor used for transmission
    },
    "adr": false,                       // device ADR status
    "codeRate": "4/5"                   // code rate
  },
  "fCnt": 0,                            // frame counter
  "fPort": 85,                          // application port
  "data": "AWcAAAJoAA=="                // base64 encoded payload (decrypted)
}

 

 

If you need to send downlink commands from MQTT client, please refer to article How to Remotely Control Devices via MQTT on Linovision Gateway.

 

 

FAQ

Q1.How to send decoded or customize uplink content to MQTT broker?

A1:  Yes, this needs to use Payload Codec feature on the gateway. Reference articles:

IOT-G56/G65/G67: How to Use Payload Codec on Linovision Gateway

IOT-G63 V1/G8x: How to Use Payload Codec on Linovision Gateway (Old)

 

Q2.What’s the troubleshooting when the status of MQTT server connection is “Disconnected”.

 

 

A2: 

1) Go to Maintenance > Tools >Ping , check if the gateway can ping to the broker address successfully.

 

 

 

2) Check if your MQTT client tool can connect to MQTT broker well, then follow the settings of MQTT client tool to configure the gateway.
3) Check if the gateway MQTT client ID is conflict with other MQTT clients.
4) Check if CPU load is too high, and if there is little available RAM and eMMC.
5) Change the log severity to Debug and replicate the disconnection problem, then download all log files and send them to support@linovision.com.

 

 

 

Q3.Why the connection status shows “connected” but MQTT client does not receive any data?
A3:
1)Ensure the devices has been added to gateway and go to Network Server > Packets to check if there are uplink packets from devices regularly.
2) Ensure the devices has been added to the correct Application.
3) Ensure the gateway firmware is upgraded to latest version. 
4) Change the log severity to Debug and replicate the disconnection problem, then download all log files and send them to support@linovision.com.