Last modified by Xiaoling on 2022/09/02 18:11

From version 44.3
edited by Xiaoling
on 2022/05/31 14:33
Change comment: There is no comment for this version
To version 50.3
edited by Xiaoling
on 2022/09/02 18:11
Change comment: Renamed from xwiki:Through MQTT to upload data.WebHome

Summary

Details

Page properties
Content
... ... @@ -1,4 +1,4 @@
1 -**Contents: **
1 +**Table of Contents: **
2 2  
3 3  {{toc/}}
4 4  
... ... @@ -7,11 +7,14 @@
7 7  
8 8  = 1. What is MQTT API? =
9 9  
10 -{{{MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL.}}}
11 11  
11 +MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL.
12 12  
13 +
14 +
13 13  = 2. MQTT Features =
14 14  
17 +
15 15  The MQTT protocol runs on TCP / IP or other network protocols and provides an ordered, lossless, bidirectional connection. Features include:
16 16  
17 17  * The publish / subscribe messaging pattern used, which provides one-to-many messaging for decoupling from the application.
... ... @@ -24,10 +24,15 @@
24 24  
25 25  
26 26  
30 +
31 +
27 27  = 3. What does this example shows? How it works? =
28 28  
34 +
29 29  (((
30 30  The server we use here is ThingSpeak which has an intuitive chart to show the test result for our test.The ThingSpeak IoT service now supports MQTT subscriptions to receive instant updates when [[ThingSpeak>>url:https://thingspeak.com/]] channel gets updated. The method here is general and can be used with other IoT servers for MQTT connection as well.
37 +
38 +
31 31  )))
32 32  
33 33  [[image:image-20220531135402-1.png]]
... ... @@ -40,6 +40,7 @@
40 40  working principle
41 41  
42 42  
51 +
43 43  [[image:image-20220531135521-3.png]]
44 44  
45 45  (((
... ... @@ -50,6 +50,7 @@
50 50  
51 51  [[image:image-20220531135607-4.png]]
52 52  
62 +
53 53  (((
54 54  Schematic diagram:downlink.In this section, we will try to program LG01 to fetch download data from ThingSpeak, then broadcast this data to local LoRa network. The end node will get this message and check if they need to do something. Similar with Uplink Example, we will first try to do it in PC, then do it in Linux side, and finally integrate it with LoRa.
55 55  )))
... ... @@ -66,9 +66,13 @@
66 66  
67 67  = 4. Preparation =
68 68  
79 +
69 69  == 4.1 Hardware ==
70 70  
82 +
71 71  1. [[image:image-20220531135650-5.png]](((
84 +
85 +
72 72  Listening on the LoRa wireless channel, while there is new LoRa packet arrives, parse it and send out to IoT Server.
73 73  
74 74  
... ... @@ -75,22 +75,38 @@
75 75  
76 76  )))
77 77  1. [[image:image-20220531135750-6.png]](((
92 +
93 +
78 78  The LoRa End node keeps getting temperature and humidity from the sensor and sends out via LoRa periodically.
95 +
96 +
97 +
79 79  )))
80 80  
81 81  == 4.2 Software ==
82 82  
102 +
83 83  1. [[4.3.4 version>>url:http://www.dragino.com/downloads/index.php?dir=motherboards/ms14/Firmware/IoT/]]
84 84  1. [[MQTT_Client>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client]]
85 85  1. [[MQTT_Simple_Server MQTT_Simeple_Server>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/LoRa/MQTT_Simple_Server]]
86 86  1. [[DHTlib>>url:https://github.com/goodcheney/Lora/blob/patch-1/Lora%20Shield/Examples/DHTlib.zip]]
87 87  
108 +
109 +
110 +
111 +
88 88  == 4.3 Server(For example) ==
89 89  
114 +
90 90  * [[ThingSpeak>>url:https://thingspeak.com/]]
91 91  
117 +
118 +
119 +
120 +
92 92  == 4.4 Configure IoT Server ==
93 93  
123 +
94 94  * Need this keys:
95 95  
96 96  1. [[image:image-20220531140054-8.png]](((
... ... @@ -100,6 +100,8 @@
100 100  
101 101  )))
102 102  1. [[image:image-20220531140326-13.png]](((
133 +
134 +
103 103  Account->My Profile,MQTT API Key
104 104  
105 105  
... ... @@ -107,12 +107,17 @@
107 107  )))
108 108  1. (((
109 109  [[image:image-20220531140304-12.png]]
142 +
143 +
144 +
110 110  )))
111 111  
112 112  == 4.5 Configure LG01 settings ==
113 113  
114 -Tips:Please confirm that your LG01 version is 4.3.3.
115 115  
150 +Tips:  Please confirm that your LG01 version is 4.3.3.
151 +
152 +
116 116  [[image:image-20220531140248-11.png]]
117 117  
118 118  **Overview**
... ... @@ -124,6 +124,7 @@
124 124  **Senosor->IOT Server**
125 125  
126 126  
164 +
127 127  [[image:image-20220531140458-15.png]]
128 128  
129 129  **MQTT->Configure MQTT Server**
... ... @@ -144,29 +144,44 @@
144 144  
145 145  [[image:image-20220531140651-18.png]]
146 146  
185 +
147 147  Configure network access.**Network->Internet Access**
148 148  
149 149  
189 +
150 150  == 4.6 Try MQTT API call with LG01 Linux command ==
151 151  
192 +
152 152  === 4.6.1 Input the command at the console ===
153 153  
195 +
154 154  1. [[image:image-20220531140811-19.png]](((
197 +
198 +
155 155  Open this Application.
156 156  
201 +
157 157  
158 158  )))
159 159  1. [[image:image-20220531140842-20.png]](((
205 +
206 +
160 160  Input passward(dragino).After into the console.
161 161  
209 +
162 162  
163 163  )))
164 164  1. [[image:image-20220531140915-21.png]](((
213 +
214 +
165 165  First, we need to make sure the LG01 has internet access. We can log in the SSH and ping an Internet address and see if it get through. As below
166 166  
217 +
167 167  
168 168  )))
169 169  1. [[image:image-20220531140955-22.png]](((
221 +
222 +
170 170  LG01 has built-in Linux tool mosquitto. It is a very powerful tool for http communication. We can use this tool to handle MQTT API call in LG01. Input this command and replace your keys.
171 171  
172 172  
... ... @@ -173,7 +173,11 @@
173 173  
174 174  )))
175 175  1. [[image:image-20220531141026-23.png]](((
229 +
230 +
176 176  Go to Server check out result.We success to use LG01 to uplink data to ThingSpeak,the mosquitto_pub command is executed in the Linux side, finally, we will have to call mosquitto_pub command with sensor data variable in Arduino side. This is through the process class in Arduino and we will show it in the final sketch.
232 +
233 +
177 177  )))
178 178  
179 179  * This command:
... ... @@ -193,9 +193,13 @@
193 193  )))
194 194  
195 195  
253 +
196 196  === 4.6.2 Input the command at the console(LG01 new version:4.3.4) ===
197 197  
256 +
198 198  1. [[image:image-20220531141150-24.png]](((
258 +
259 +
199 199  Open this Application.
200 200  
201 201  
... ... @@ -204,6 +204,7 @@
204 204  1. (((
205 205  [[image:image-20220531141400-27.png]]
206 206  
268 +
207 207  Check the settings.
208 208  
209 209  
... ... @@ -212,6 +212,7 @@
212 212  1. (((
213 213  [[image:image-20220531141601-30.png]]
214 214  
277 +
215 215  input this command.
216 216  
217 217  
... ... @@ -218,6 +218,8 @@
218 218  
219 219  )))
220 220  1. [[image:image-20220531141515-29.png]](((
284 +
285 +
221 221  Check the result.
222 222  
223 223  
... ... @@ -226,6 +226,7 @@
226 226  
227 227  == 4.7 Updata data to Server(Through MQTT) ==
228 228  
294 +
229 229  * This version of Sketch implements these features:
230 230  
231 231  1. Read the LG01 configuration information from Linux.
... ... @@ -233,7 +233,11 @@
233 233  1. Send reply after then receive LoRa node data.
234 234  1. Sketch will write active content to /tmp/iot/status periodically (every 5 minutes).(Watchdog feature)
235 235  
236 -1. [[image:image-20220531141656-31.png]](((
302 +
303 +
304 +1. [[image:image-20220531143822-49.png]](((
305 +
306 +
237 237  Open the sketch [[MQTT_Simple_Server>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/LoRa/MQTT_Simple_Server]].(Board:Dragino Yun + UNO or LG01/OLG01,Port:Network ports.)and upload.
238 238  
239 239  
... ... @@ -240,12 +240,16 @@
240 240  
241 241  )))
242 242  1. [[image:image-20220531141800-32.png]](((
313 +
314 +
243 243  Open Serial monitor.
244 244  
245 245  
246 246  
247 247  )))
248 -1. [[image:image-20220531141842-33.png]](((
320 +1. [[image:image-20220531143748-48.png]](((
321 +
322 +
249 249  Open the Sketch [[MQTT_Client>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client]]. (Board:Arduino/Genuino Uno.Port:Serial ports.)and upload.
250 250  
251 251  
... ... @@ -252,6 +252,8 @@
252 252  
253 253  )))
254 254  1. [[image:image-20220531141927-34.png]](((
329 +
330 +
255 255  Open Serial monitor.
256 256  
257 257  
... ... @@ -259,13 +259,13 @@
259 259  )))
260 260  1. Go to IoT Server to check the result.
261 261  1. (((
262 -[[image:image-20220531142023-35.png]]
338 +[[image:image-20220531143707-47.png]]
263 263  
264 264  
265 265  
266 266  )))
267 267  1. (((
268 -[[image:image-20220531142155-36.png]]
344 +[[image:image-20220531143632-46.png]]
269 269  
270 270  
271 271  
... ... @@ -273,8 +273,10 @@
273 273  
274 274  = 5. FAQ =
275 275  
352 +
276 276  == 5.1 Configure to support general mqtt server ==
277 277  
355 +
278 278  First, try to run **mosquitto_pub** in Linux console to send a data to MQTT server.
279 279  
280 280  For example: for ThingSpeak, a MQTT publish command is:
... ... @@ -289,6 +289,8 @@
289 289  1. LG01 web console -> Sensor -> MQTT
290 290  1. Choose general Server
291 291  1. [[image:image-20220531142342-37.png]](((
370 +
371 +
292 292  Refer to your server to fill in.
293 293  
294 294  
... ... @@ -295,6 +295,8 @@
295 295  
296 296  )))
297 297  1. [[image:image-20220531142447-38.png]](((
378 +
379 +
298 298  Ex:ThingSpeak Server
299 299  
300 300  
... ... @@ -318,13 +318,17 @@
318 318  
319 319  [[image:image-20220531142525-39.png]]
320 320  
403 +
321 321  MQTT Logread example
322 322  
323 323  
407 +
324 324  == 5.2 What is Watchdog feature? ==
325 325  
410 +
326 326  LG01 for 4.3.3 version,we have added watchdog feature. In order to avoid the gateway running process will get stuck. So add writing action on every times.
327 327  
413 +
328 328  * [[image:image-20220531142558-40.png]](((
329 329  Enable Sensor->Micro-Controller settings
330 330  
... ... @@ -332,6 +332,8 @@
332 332  
333 333  )))
334 334  * [[image:image-20220531142629-41.png]](((
421 +
422 +
335 335  Open the sketch [[MQTT_Simple_Server>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/LoRa/MQTT_Simple_Server]].(Board:Dragino Yun + UNO or LG01/OLG01,Port:Network ports.)and upload.
336 336  
337 337  
... ... @@ -338,6 +338,8 @@
338 338  
339 339  )))
340 340  * [[image:image-20220531142659-42.png]](((
429 +
430 +
341 341  Each time the function loops, it uses the watchdog function once.
342 342  
343 343  
... ... @@ -344,6 +344,8 @@
344 344  
345 345  )))
346 346  * [[image:image-20220531142720-43.png]](((
437 +
438 +
347 347  Open SSH and check watchdog result.If the result change constantly,the feature enable successfully.
348 348  
349 349  
... ... @@ -350,6 +350,8 @@
350 350  
351 351  )))
352 352  * [[image:image-20220531142748-44.png]](((
445 +
446 +
353 353  If the time doesnt's change,you can refer it to calculate for checking status.
354 354  )))
355 355  
image-20220531143604-45.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +42.6 KB
Content
image-20220531143632-46.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +42.4 KB
Content
image-20220531143707-47.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +34.2 KB
Content
image-20220531143748-48.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +38.8 KB
Content
image-20220531143822-49.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +38.1 KB
Content