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

From version 44.1
edited by Xiaoling
on 2022/05/31 14:30
Change comment: There is no comment for this version
To version 50.2
edited by Xiaoling
on 2022/09/02 18:10
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,3 +1,5 @@
1 +**Table of Contents: **
2 +
1 1  {{toc/}}
2 2  
3 3  
... ... @@ -5,11 +5,14 @@
5 5  
6 6  = 1. What is MQTT API? =
7 7  
8 -{{{MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL.}}}
9 9  
11 +MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL.
10 10  
13 +
14 +
11 11  = 2. MQTT Features =
12 12  
17 +
13 13  The MQTT protocol runs on TCP / IP or other network protocols and provides an ordered, lossless, bidirectional connection. Features include:
14 14  
15 15  * The publish / subscribe messaging pattern used, which provides one-to-many messaging for decoupling from the application.
... ... @@ -21,10 +21,16 @@
21 21  * Notification mechanism, notify the transmission of both sides when an exception occurs
22 22  
23 23  
29 +
30 +
31 +
24 24  = 3. What does this example shows? How it works? =
25 25  
34 +
26 26  (((
27 27  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 +
28 28  )))
29 29  
30 30  [[image:image-20220531135402-1.png]]
... ... @@ -37,6 +37,7 @@
37 37  working principle
38 38  
39 39  
51 +
40 40  [[image:image-20220531135521-3.png]]
41 41  
42 42  (((
... ... @@ -47,6 +47,7 @@
47 47  
48 48  [[image:image-20220531135607-4.png]]
49 49  
62 +
50 50  (((
51 51  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.
52 52  )))
... ... @@ -60,11 +60,16 @@
60 60  )))
61 61  
62 62  
76 +
63 63  = 4. Preparation =
64 64  
79 +
65 65  == 4.1 Hardware ==
66 66  
82 +
67 67  1. [[image:image-20220531135650-5.png]](((
84 +
85 +
68 68  Listening on the LoRa wireless channel, while there is new LoRa packet arrives, parse it and send out to IoT Server.
69 69  
70 70  
... ... @@ -71,12 +71,17 @@
71 71  
72 72  )))
73 73  1. [[image:image-20220531135750-6.png]](((
92 +
93 +
74 74  The LoRa End node keeps getting temperature and humidity from the sensor and sends out via LoRa periodically.
75 -)))
76 76  
77 77  
97 +
98 +)))
99 +
78 78  == 4.2 Software ==
79 79  
102 +
80 80  1. [[4.3.4 version>>url:http://www.dragino.com/downloads/index.php?dir=motherboards/ms14/Firmware/IoT/]]
81 81  1. [[MQTT_Client>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client]]
82 82  1. [[MQTT_Simple_Server MQTT_Simeple_Server>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/LoRa/MQTT_Simple_Server]]
... ... @@ -83,13 +83,21 @@
83 83  1. [[DHTlib>>url:https://github.com/goodcheney/Lora/blob/patch-1/Lora%20Shield/Examples/DHTlib.zip]]
84 84  
85 85  
109 +
110 +
111 +
86 86  == 4.3 Server(For example) ==
87 87  
114 +
88 88  * [[ThingSpeak>>url:https://thingspeak.com/]]
89 89  
90 90  
118 +
119 +
120 +
91 91  == 4.4 Configure IoT Server ==
92 92  
123 +
93 93  * Need this keys:
94 94  
95 95  1. [[image:image-20220531140054-8.png]](((
... ... @@ -99,6 +99,8 @@
99 99  
100 100  )))
101 101  1. [[image:image-20220531140326-13.png]](((
133 +
134 +
102 102  Account->My Profile,MQTT API Key
103 103  
104 104  
... ... @@ -106,13 +106,17 @@
106 106  )))
107 107  1. (((
108 108  [[image:image-20220531140304-12.png]]
109 -)))
110 110  
111 111  
144 +
145 +)))
146 +
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.
... ... @@ -234,7 +234,10 @@
234 234  1. Sketch will write active content to /tmp/iot/status periodically (every 5 minutes).(Watchdog feature)
235 235  
236 236  
237 -1. [[image:image-20220531141656-31.png]](((
303 +
304 +1. [[image:image-20220531143822-49.png]](((
305 +
306 +
238 238  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.
239 239  
240 240  
... ... @@ -241,12 +241,16 @@
241 241  
242 242  )))
243 243  1. [[image:image-20220531141800-32.png]](((
313 +
314 +
244 244  Open Serial monitor.
245 245  
246 246  
247 247  
248 248  )))
249 -1. [[image:image-20220531141842-33.png]](((
320 +1. [[image:image-20220531143748-48.png]](((
321 +
322 +
250 250  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.
251 251  
252 252  
... ... @@ -253,6 +253,8 @@
253 253  
254 254  )))
255 255  1. [[image:image-20220531141927-34.png]](((
329 +
330 +
256 256  Open Serial monitor.
257 257  
258 258  
... ... @@ -260,13 +260,13 @@
260 260  )))
261 261  1. Go to IoT Server to check the result.
262 262  1. (((
263 -[[image:image-20220531142023-35.png]]
338 +[[image:image-20220531143707-47.png]]
264 264  
265 265  
266 266  
267 267  )))
268 268  1. (((
269 -[[image:image-20220531142155-36.png]]
344 +[[image:image-20220531143632-46.png]]
270 270  
271 271  
272 272  
... ... @@ -274,8 +274,10 @@
274 274  
275 275  = 5. FAQ =
276 276  
352 +
277 277  == 5.1 Configure to support general mqtt server ==
278 278  
355 +
279 279  First, try to run **mosquitto_pub** in Linux console to send a data to MQTT server.
280 280  
281 281  For example: for ThingSpeak, a MQTT publish command is:
... ... @@ -290,6 +290,8 @@
290 290  1. LG01 web console -> Sensor -> MQTT
291 291  1. Choose general Server
292 292  1. [[image:image-20220531142342-37.png]](((
370 +
371 +
293 293  Refer to your server to fill in.
294 294  
295 295  
... ... @@ -296,6 +296,8 @@
296 296  
297 297  )))
298 298  1. [[image:image-20220531142447-38.png]](((
378 +
379 +
299 299  Ex:ThingSpeak Server
300 300  
301 301  
... ... @@ -319,13 +319,17 @@
319 319  
320 320  [[image:image-20220531142525-39.png]]
321 321  
403 +
322 322  MQTT Logread example
323 323  
324 324  
407 +
325 325  == 5.2 What is Watchdog feature? ==
326 326  
410 +
327 327  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.
328 328  
413 +
329 329  * [[image:image-20220531142558-40.png]](((
330 330  Enable Sensor->Micro-Controller settings
331 331  
... ... @@ -333,6 +333,8 @@
333 333  
334 334  )))
335 335  * [[image:image-20220531142629-41.png]](((
421 +
422 +
336 336  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.
337 337  
338 338  
... ... @@ -339,6 +339,8 @@
339 339  
340 340  )))
341 341  * [[image:image-20220531142659-42.png]](((
429 +
430 +
342 342  Each time the function loops, it uses the watchdog function once.
343 343  
344 344  
... ... @@ -345,6 +345,8 @@
345 345  
346 346  )))
347 347  * [[image:image-20220531142720-43.png]](((
437 +
438 +
348 348  Open SSH and check watchdog result.If the result change constantly,the feature enable successfully.
349 349  
350 350  
... ... @@ -351,6 +351,8 @@
351 351  
352 352  )))
353 353  * [[image:image-20220531142748-44.png]](((
445 +
446 +
354 354  If the time doesnt's change,you can refer it to calculate for checking status.
355 355  )))
356 356  
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