Wiki source code of MQTT Forward Instruction

Version 54.1 by Kilight Cao on 2024/08/31 16:20

Hide last authors
Xiaoling 44.2 1 **~ Table of Contents:**
Xiaoling 1.2 2
Xiaoling 1.4 3 {{toc/}}
Xiaoling 1.3 4
Xiaoling 1.4 5
Xiaoling 44.2 6 = 1.  Introduction =
Xiaoling 1.3 7
Xiaoling 44.2 8
Xiaoling 1.2 9 Dragino LoRa/LoRaWAN gateway support MQTT forwarding. It can forward the sensor data from LoRa network to MQTT server , and vice verse.
10
Xiaoling 3.2 11
Xiaoling 44.2 12 == 1.1  Support Devices ==
Xiaoling 1.2 13
Xiaoling 44.2 14
Xiaoling 1.2 15 This MQTT forward instruction is for below devices:
16
Xiaoling 50.1 17 * LG01N, OLG01N ((% style="color:red" %)**Warning**(%%): LG01-P LG01-S use another instruction: [[MQTT for LG01-P/LG01S>>doc:Main.Through MQTT to upload data.WebHome]])
Xiaoling 1.2 18 * LG02, OLG02
Kilight Cao 52.1 19 * LG308, DLOS8, LPS8, LIG16
Xiaoling 1.2 20 * MS14 series if installed with the same firmware. (in this case, the MQTT forward will work , but no LoRa support)
Kilight Cao 52.1 21 * LG308N, DLOS8N, LPS8N
22 * LPS8V2
Xiaoling 1.2 23
Xiaoling 49.2 24
Kilight Cao 52.1 25 The MQTT Client Utility used in Dragino is **mosquitto_pub** and **mosquitto_sub**. User can add more options to the mqtt commands.
Xiaoling 44.2 26
Kilight Cao 52.1 27 Check out this link for more mosquito-related directives **[[https:~~/~~/mosquitto.org/man/mosquitto_pub-1.html>>https://mosquitto.org/man/mosquitto_pub-1.html]]**
Xiaoling 44.2 28
Xiaoling 1.2 29
Kilight Cao 52.1 30 = 2.  Example to communicate to a simple MQTT server =
Xiaoling 1.2 31
Kilight Cao 52.1 32 == 2.1  Overview ==
Xiaoling 49.2 33
Xiaoling 1.2 34
35 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>>url:http://www.steves-internet-guide.com/install-mosquitto-broker/]].
36
Xiaoling 8.2 37
Kilight Cao 52.1 38 == 2.2  Simulate via MQTT.fx utility ==
Xiaoling 1.2 39
Xiaoling 44.6 40
Xiaoling 1.2 41 The [[MQTT.fx>>url:http://mqttfx.jensd.de/index.php/download]] 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.
42
Xiaoling 1.14 43 (((
Xiaoling 1.2 44 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.
Xiaoling 1.14 45 )))
Xiaoling 1.2 46
Xiaoling 8.2 47 [[image:image-20220527134929-6.png]]
Xiaoling 1.2 48
49 Connect to MQTT Broker
50
Xiaoling 9.2 51
Xiaoling 1.2 52 After connected, use publish to public some thing to MQTT server. This to simulate upsteam
53
Xiaoling 9.2 54 [[image:image-20220527135037-7.png]]
Xiaoling 1.2 55
56 Upstream: Publish message to MQTT Broker
57
Xiaoling 9.2 58
Xiaoling 1.2 59 To simulate a downstream, use MQTT.fx to subscribe a topic, and publish something to this topic. as Below:
60
Xiaoling 10.2 61 [[image:image-20220527135215-8.png]]
Xiaoling 1.2 62
63 Downstream: Subscribe a topic to get downstream
64
65
Xiaoling 44.6 66
Kilight Cao 52.1 67 = 3. Add LoRa support to communicate with remote sensor =
Xiaoling 47.1 68
Xiaoling 1.2 69
70 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.
71
Xiaoling 19.3 72
Xiaoling 49.2 73
Kilight Cao 52.1 74 == 3.1  Use LoRa Raw protocol for communication ~-~- For LG01/LG02 ==
Xiaoling 1.2 75
Xiaoling 45.2 76
Xiaoling 1.20 77 (((
Kilight Cao 52.1 78 We can use **[[LoRa Shield>>url:http://www.dragino.com/products/lora/item/102-lora-shield.html]]** to send LoRa Raw data to Gateway and receive data from gateway.
Xiaoling 1.20 79 )))
Xiaoling 1.2 80
Xiaoling 1.20 81 (((
Kilight Cao 52.1 82 The example Sketch for LoRa Shield +Arduino is here: **[[LoRa_Shield_Sketch_For_MQTT>>url:http://www.dragino.com/downloads/index.php?dir=LoraShield/]]**
Xiaoling 1.20 83 )))
Xiaoling 1.2 84
Xiaoling 1.20 85 (((
Kilight Cao 52.1 86 And this link is the required library: **[[arduino-LoRa-master>>url:http://www.dragino.com/downloads/index.php?dir=LoraShield/]]**. Unzip this library and put in Arduino library location.
Xiaoling 45.2 87
88
Xiaoling 1.20 89 )))
Xiaoling 1.2 90
Xiaoling 1.20 91 (((
Xiaoling 1.2 92 What does the Arduino Sketch do? The Arduino Sketch will:
Xiaoling 1.20 93 )))
Xiaoling 1.2 94
95 * 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).
96 * Downstream: Listening broadcast message from gateway, and print it in console.
97 * The LoRa parameter settings in Arduino should match the LoRa settings in gateway, as below:
98
Xiaoling 21.2 99 [[image:image-20220527140354-18.png]]
Xiaoling 1.2 100
101 LoRa Parameter should match
102
103
104 Below is the test result after the Arduino Sketch is running.
105
Xiaoling 21.2 106 [[image:image-20220527140459-19.png]]
Xiaoling 1.2 107
108 Upstream Data Flow
109
Xiaoling 21.2 110
Xiaoling 22.2 111 [[image:image-20220527140542-20.png]]
Xiaoling 1.2 112
113 Downstream Data Flow
114
115
Kilight Cao 52.1 116 == 3.2  Use LoRaWAN Protocol for communication ~-~- For LG308/LPS8/DLOS8/LG308N/LPS8N/DLOS8N ==
Xiaoling 45.2 117
118
Xiaoling 1.20 119 (((
Xiaoling 23.2 120 Since firmware (% style="color:#4f81bd" %)**LG02_LG08~-~-build-v5.3.1585192026-20200326-1109,**(%%) Dragino LoRaWAN gateways support the communication to LoRaWAN (% style="color:#4f81bd" %)**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.
Xiaoling 1.20 121 )))
Xiaoling 1.2 122
Xiaoling 1.20 123 (((
Xiaoling 23.2 124 When use test this feature, please use the version higher then : (% style="color:#4f81bd" %)**LG02_LG08~-~-build-v5.4.1593400722-20200629-1120**(%%), in this version, the upload format is changed and readable, which is easier for integration.
Xiaoling 45.2 125
126
Xiaoling 47.1 127 (% style="color:blue" %)**Video Instruction**(%%): (% style="color:blue" %)[[https:~~/~~/youtu.be/qJTY441-t90>>url:https://youtu.be/qJTY441-t90]]
Xiaoling 1.20 128 )))
Xiaoling 1.2 129
Xiaoling 1.20 130 (((
Xiaoling 47.1 131 (% style="color:blue" %)**Step 1**(%%): Refer [[Communicate with ABP End Node>>Communicate with ABP End Node without LoRaWAN Network Server --- LG308]] to know how to set up LG308 to work with LoRaWAN End node.
Xiaoling 1.20 132 )))
Xiaoling 1.2 133
Xiaoling 1.20 134 (((
Xiaoling 45.2 135 (% style="color:blue" %)**Step 2**(%%): Make sure your Radio settings match the End Node settings.
Xiaoling 1.20 136 )))
Xiaoling 1.2 137
Xiaoling 23.2 138 [[image:image-20220527141235-21.png]]
Xiaoling 1.2 139
140 Use Same Frequency Band as End Node
141
142
Xiaoling 1.20 143 (((
Xiaoling 2.5 144 (((
Xiaoling 45.2 145 (% style="color:blue" %)**Step 3**(%%): Set up publish format and MQTT channel. The LG308 will store the Data from End node in (% style="color:#4f81bd" %)**HEX format**(%%) in the file.
Xiaoling 1.20 146 )))
Xiaoling 2.5 147 )))
Xiaoling 1.2 148
Kilight Cao 44.1 149 [[image:image-20220613191345-4.png]]
Xiaoling 1.2 150
151
Xiaoling 45.2 152 (% style="color:blue" %)**Step 4**(%%): Map the Device Address to Remote ID in MQTT server.
Xiaoling 1.2 153
Kilight Cao 44.1 154 [[image:image-20220613190635-2.png]]
Xiaoling 1.2 155
156
Xiaoling 45.2 157 (% style="color:blue" %)**Step 5: Upstream**(%%): Save the change, we can see the log info via "sytem log", End Node and MQTT Server
Xiaoling 1.2 158
Xiaoling 26.2 159 [[image:image-20220527141843-24.png]]
Xiaoling 1.2 160
161
Xiaoling 28.2 162 [[image:image-20220527141933-25.png]]
Xiaoling 1.2 163
164 Choose ASCII Format
165
166
Xiaoling 28.2 167 [[image:image-20220527142028-26.png]]
168
Xiaoling 1.2 169 LHT65 Decoder
170
171
Xiaoling 45.2 172 (% style="color:blue" %)**Step 6: Set up subscribe**(%%)**:** Subscribe a topci for downstream.
Xiaoling 2.3 173
Kilight Cao 44.1 174 [[image:image-20220613191426-5.png]]
Xiaoling 1.2 175
176
Xiaoling 45.2 177 (% style="color:blue" %)**Step 7: Downstream**(%%): Save the change, we can see the log info via "sytem log", End Node and MQTT Server.
Xiaoling 1.2 178
Xiaoling 30.2 179 [[image:image-20220527142239-28.png]]
Xiaoling 1.2 180
181
Kilight Cao 44.1 182
183 mosquitto_pub -h $server_address -p $server_port -t $Client_ID -m "**dev_addr,imme/time,txt/hex,payload**"
184
185 (% class="box infomessage" %)
186 (((
Xiaoling 45.2 187 **mosquitto_pub -h 10.130.2.192 -p 1883 -t dragino-1d25dc/ -m "260211D,time,txt,hello"**
Kilight Cao 44.1 188 )))
189
190 mosquitto_pub -h $server_address -p $server_port -t $Client_ID -m "**dev_addr,imme/time,txt/hex,payload,txpw,txbw,SF,frequency,rxwindow**"
191
192 (% class="box infomessage" %)
193 (((
Kilight Cao 48.1 194 **mosquitto_pub -h 10.130.2.192 -p 1883 -t dragino-1d25dc/ -m "260211D,time,txt,hello,20,1,SF12,923300000,2"**
Kilight Cao 44.1 195 )))
196
Kilight Cao 52.1 197 (% style="color:red" %)**Notice: The text use for Downstream must meet the requirement from [[LG308 Downstream Payload>>Communicate with ABP End Node without LoRaWAN Network Server --- LG308||anchor="H2.2Downstream"]]**
198
Kilight Cao 44.1 199 Or use [[MQTT.fx>>https://mqttfx.jensd.de/index.php/download]]
200
201 [[image:image-20220613192816-6.png||height="440" width="1056"]]
202
Xiaoling 45.2 203
Kilight Cao 52.1 204 == 3.3 Use LoRaWAN Protocol for communication ~-~- For LPS8V2 ==
Xiaoling 1.2 205
Xiaoling 45.2 206
Xiaoling 1.2 207
208
Kilight Cao 52.1 209 = 4.  How to ask for Support =
Xiaoling 45.2 210
211
Xiaoling 1.2 212 If a user still not have trouble making it works. please send a mail to support@dragino.com with the below info:
213
214 * Detail of your LoRaWAN end node.
215 * Gateway Model and firmware version
216 * A set of screenshots you configure in the gateway according to our instruction
217 * A full log of "logread -f"