Table of Contents:

1.  Introduction

Dragino LoRa/LoRaWAN gateway support MQTT forwarding. It can forward the sensor data from LoRa network to MQTT server , and vice verse.

1.1  Support Devices

This MQTT forward instruction is for below devices:

  • LG01N, OLG01N (Warning: LG01-P LG01-S use another instruction: MQTT for LG01-P/LG01S)
  • LG02, OLG02
  • LG308, DLOS8, LPS8, LIG16
  • MS14 series if installed with the same firmware. (in this case, the MQTT forward will work , but no LoRa support)
  • LG308N, DLOS8N, LPS8N
  • LPS8V2

The MQTT Client Utility used in Dragino is mosquitto_pub and mosquitto_sub. User can add more options to the mqtt commands.

Check out this link for more mosquito-related directives https://mosquitto.org/man/mosquitto_pub-1.html

2.  Example to communicate to a simple MQTT server

2.1  Overview

This section is an example to show how to set up LG01-N to communicate with a MQTT server. The MQTT server is a simple utility set up in a local PC. Note: User can set up same server via this instruction.

2.2  Simulate via MQTT.fx utility

The MQTT.fx is a MQTT client tool. We can use this to simulate a MQTT connection to our MQTT broker first to make sure the MQTT broker works. This will also help us understand how it works.

In this test, the MQTT broker and MQTT.fx are installed in the same PC, so the MQTT server address in MQTT.fx should be localhost. Below shows how to connect to the server.

image-20220527134929-6.png

Connect to MQTT Broker

After connected, use publish to public some thing to MQTT server. This to simulate upsteam

image-20220527135037-7.png

Upstream: Publish message to MQTT Broker

To simulate a downstream, use MQTT.fx to subscribe a topic, and publish something to this topic. as Below:

image-20220527135215-8.png

Downstream: Subscribe a topic to get downstream

3. Add LoRa support to communicate with remote sensor

In above section, we have configured the UI to support MQTT upstream and downstream. We can simulate via Linux command. In this section, we will guide how to communicate with remote LoRa End Node for upstream and downstream.

3.1  Use LoRa Raw protocol for communication -- For LG01/LG02

We can use LoRa Shield to send LoRa Raw data to Gateway and receive data from gateway.

The example Sketch for LoRa Shield +Arduino is here: LoRa_Shield_Sketch_For_MQTT

And this link is the required library: arduino-LoRa-master. Unzip this library and put in Arduino library location.

 

What does the Arduino Sketch do? The Arduino Sketch will:

  • Upstream: Keep sending a LoRa Message every minutes with this payload : <4567>tem=xx&hum=yy (Where xx and yy are temperature and humidity value generated randomly).
  • Downstream: Listening broadcast message from gateway, and print it in console.
  • The LoRa parameter settings in Arduino should match the LoRa settings in gateway, as below:

image-20220527140354-18.png

LoRa Parameter should match

Below is the test result after the Arduino Sketch is running.

image-20220527140459-19.png

Upstream Data Flow

image-20220527140542-20.png

Downstream Data Flow

3.2  Use LoRaWAN Protocol for communication -- For LG308/LPS8/DLOS8/LG308N/LPS8N/DLOS8N

Since firmware LG02_LG08--build-v5.3.1585192026-20200326-1109, Dragino LoRaWAN gateways support the communication to LoRaWAN ABP end node locally without the need of LoRaWAN server. This feature allow us to integrate MQTT in the gateway to support LoRaWAN to MQTT forwarding or visa verse.

When use test this feature, please use the version higher then : LG02_LG08--build-v5.4.1593400722-20200629-1120, in this version, the upload format is changed and readable, which is easier for integration.

Video Instructionhttps://youtu.be/qJTY441-t90

Step 1: Refer Communicate with ABP End Node to know how to set up LG308 to work with LoRaWAN End node.

Step 2: Make sure your Radio settings match the End Node settings.

image-20220527141235-21.png

Use Same Frequency Band as End Node

Step 3: Set up publish format and MQTT channel. The LG308 will store the Data from End node in HEX format in the file. 

image-20220613191345-4.png

Step 4: Map the Device Address to Remote ID in MQTT server.

image-20220613190635-2.png

Step 5: Upstream: Save the change, we can see the log info via "sytem log", End Node and MQTT Server

image-20220527141843-24.png

image-20220527141933-25.png

Choose ASCII Format

image-20220527142028-26.png

LHT65 Decoder

Step 6: Set up subscribe: Subscribe a topci for downstream.

image-20220613191426-5.png

Step 7: Downstream: Save the change, we can see the log info via "sytem log", End Node and MQTT Server.

image-20220527142239-28.png

mosquitto_pub -h $server_address -p $server_port -t $Client_ID -m "dev_addr,imme/time,txt/hex,payload"

mosquitto_pub -h 10.130.2.192 -p 1883 -t dragino-1d25dc/ -m "260211D,time,txt,hello"

mosquitto_pub -h $server_address -p $server_port -t $Client_ID -m "dev_addr,imme/time,txt/hex,payload,txpw,txbw,SF,frequency,rxwindow"

mosquitto_pub -h 10.130.2.192 -p 1883 -t dragino-1d25dc/ -m "260211D,time,txt,hello,20,1,SF12,923300000,2"

Notice: The text use for Downstream must meet the requirement from LG308 Downstream Payload

Or use MQTT.fx

image-20220613192816-6.png

3.3  Use LoRaWAN Protocol for communication -- For LPS8V2

 

Step 1: Refer Register Node to Chirpstack and Register Gateway to Chirpstackto know How do register node devices and gateways to the built-in chirpstack server

Step 2: Make sure your node data is normal on the built-in server

Click "Event" on the node device interface on chirpstack, and then click "+up" to view the detailed data information of the node device

image-20240831160038-1.png

Step 3: Set up MQTT Forworder.

image-20240831162021-2.png

Step 4: Check result

Users can check the data through the MQTT server, or use the MQtt.fx tool.

image-20240831162254-3.png

image-20240831162454-4.png

4.  How to ask for Support

If a user still not have trouble making it works. please send a mail to support@dragino.com with the below info:

  • Detail of your LoRaWAN end node.
  • Gateway Model and firmware version
  • A set of screenshots you configure in the gateway according to our instruction
  • A full log of "logread -f"
Tags:
Created by Xiaoling on 2022/05/12 15:36
    
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0