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

From version 31.2
edited by Xiaoling
on 2022/05/31 14:18
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,18 @@
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 +
35 +(((
26 26  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.
27 27  
38 +
39 +)))
40 +
28 28  [[image:image-20220531135402-1.png]]
29 29  
30 30  Message Queuing Telemetry Transport
... ... @@ -35,26 +35,41 @@
35 35  working principle
36 36  
37 37  
51 +
38 38  [[image:image-20220531135521-3.png]]
39 39  
54 +(((
40 40  Schematic diagram: uplink.In this section, we will try to program LG01 to uplink data to ThingSpeak. The data flow in this example.We have already tried ① and ② in the above simple LoRa example. Now we will try the step ③ first, after it work as expect, we will integrate these three steps together for a complete uplink example.
56 +)))
41 41  
42 42  
43 43  
44 44  [[image:image-20220531135607-4.png]]
45 45  
62 +
63 +(((
46 46  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.
65 +)))
47 47  
67 +(((
48 48  MQTT agreement to achieve the need: client and server There are three identities in the MQTT protocol: Publish, Broker (server), Subscribe. Among them, the publisher and the subscriber of the message are all clients, the broker is the server, and the publisher can be both the subscriber and the subscriber. MQTT transmission of information is divided into: Topic and payload in two parts Topic, can be understood as the type of message subscribers Subscribe, you will receive the theme of the message content (payload) The payload, which can be understood as the content of the message, refers to the specific content to be used by the subscribers.
69 +)))
49 49  
71 +(((
50 50  To use the server, we need to register an account on [[ThingSpeak>>url:https://thingspeak.com/]] . Then create a channel and type the channel info. As shown below, the Channel ID is the unique ID to store our data in [[ThingSpeak>>url:https://thingspeak.com/]] .
73 +)))
51 51  
52 52  
76 +
53 53  = 4. Preparation =
54 54  
79 +
55 55  == 4.1 Hardware ==
56 56  
82 +
57 57  1. [[image:image-20220531135650-5.png]](((
84 +
85 +
58 58  Listening on the LoRa wireless channel, while there is new LoRa packet arrives, parse it and send out to IoT Server.
59 59  
60 60  
... ... @@ -61,12 +61,17 @@
61 61  
62 62  )))
63 63  1. [[image:image-20220531135750-6.png]](((
92 +
93 +
64 64  The LoRa End node keeps getting temperature and humidity from the sensor and sends out via LoRa periodically.
65 -)))
66 66  
67 67  
97 +
98 +)))
99 +
68 68  == 4.2 Software ==
69 69  
102 +
70 70  1. [[4.3.4 version>>url:http://www.dragino.com/downloads/index.php?dir=motherboards/ms14/Firmware/IoT/]]
71 71  1. [[MQTT_Client>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/IoTServer/ThingSpeak/MQTT_Client]]
72 72  1. [[MQTT_Simple_Server MQTT_Simeple_Server>>url:https://github.com/dragino/Arduino-Profile-Examples/tree/master/libraries/Dragino/examples/LoRa/MQTT_Simple_Server]]
... ... @@ -73,13 +73,21 @@
73 73  1. [[DHTlib>>url:https://github.com/goodcheney/Lora/blob/patch-1/Lora%20Shield/Examples/DHTlib.zip]]
74 74  
75 75  
109 +
110 +
111 +
76 76  == 4.3 Server(For example) ==
77 77  
114 +
78 78  * [[ThingSpeak>>url:https://thingspeak.com/]]
79 79  
80 80  
118 +
119 +
120 +
81 81  == 4.4 Configure IoT Server ==
82 82  
123 +
83 83  * Need this keys:
84 84  
85 85  1. [[image:image-20220531140054-8.png]](((
... ... @@ -89,6 +89,8 @@
89 89  
90 90  )))
91 91  1. [[image:image-20220531140326-13.png]](((
133 +
134 +
92 92  Account->My Profile,MQTT API Key
93 93  
94 94  
... ... @@ -96,13 +96,17 @@
96 96  )))
97 97  1. (((
98 98  [[image:image-20220531140304-12.png]]
99 -)))
100 100  
101 101  
144 +
145 +)))
146 +
102 102  == 4.5 Configure LG01 settings ==
103 103  
104 -Tips:Please confirm that your LG01 version is 4.3.3.
105 105  
150 +Tips:  Please confirm that your LG01 version is 4.3.3.
151 +
152 +
106 106  [[image:image-20220531140248-11.png]]
107 107  
108 108  **Overview**
... ... @@ -114,6 +114,7 @@
114 114  **Senosor->IOT Server**
115 115  
116 116  
164 +
117 117  [[image:image-20220531140458-15.png]]
118 118  
119 119  **MQTT->Configure MQTT Server**
... ... @@ -134,29 +134,44 @@
134 134  
135 135  [[image:image-20220531140651-18.png]]
136 136  
185 +
137 137  Configure network access.**Network->Internet Access**
138 138  
139 139  
189 +
140 140  == 4.6 Try MQTT API call with LG01 Linux command ==
141 141  
192 +
142 142  === 4.6.1 Input the command at the console ===
143 143  
195 +
144 144  1. [[image:image-20220531140811-19.png]](((
197 +
198 +
145 145  Open this Application.
146 146  
201 +
147 147  
148 148  )))
149 149  1. [[image:image-20220531140842-20.png]](((
205 +
206 +
150 150  Input passward(dragino).After into the console.
151 151  
209 +
152 152  
153 153  )))
154 154  1. [[image:image-20220531140915-21.png]](((
213 +
214 +
155 155  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
156 156  
217 +
157 157  
158 158  )))
159 159  1. [[image:image-20220531140955-22.png]](((
221 +
222 +
160 160  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.
161 161  
162 162  
... ... @@ -163,7 +163,11 @@
163 163  
164 164  )))
165 165  1. [[image:image-20220531141026-23.png]](((
229 +
230 +
166 166  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 +
167 167  )))
168 168  
169 169  * This command:
... ... @@ -183,9 +183,13 @@
183 183  )))
184 184  
185 185  
253 +
186 186  === 4.6.2 Input the command at the console(LG01 new version:4.3.4) ===
187 187  
256 +
188 188  1. [[image:image-20220531141150-24.png]](((
258 +
259 +
189 189  Open this Application.
190 190  
191 191  
... ... @@ -194,6 +194,7 @@
194 194  1. (((
195 195  [[image:image-20220531141400-27.png]]
196 196  
268 +
197 197  Check the settings.
198 198  
199 199  
... ... @@ -202,6 +202,7 @@
202 202  1. (((
203 203  [[image:image-20220531141601-30.png]]
204 204  
277 +
205 205  input this command.
206 206  
207 207  
... ... @@ -208,6 +208,8 @@
208 208  
209 209  )))
210 210  1. [[image:image-20220531141515-29.png]](((
284 +
285 +
211 211  Check the result.
212 212  
213 213  
... ... @@ -216,6 +216,7 @@
216 216  
217 217  == 4.7 Updata data to Server(Through MQTT) ==
218 218  
294 +
219 219  * This version of Sketch implements these features:
220 220  
221 221  1. Read the LG01 configuration information from Linux.
... ... @@ -224,7 +224,10 @@
224 224  1. Sketch will write active content to /tmp/iot/status periodically (every 5 minutes).(Watchdog feature)
225 225  
226 226  
227 -1. [[image:image-20220531141656-31.png]](((
303 +
304 +1. [[image:image-20220531143822-49.png]](((
305 +
306 +
228 228  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.
229 229  
230 230  
... ... @@ -231,45 +231,76 @@
231 231  
232 232  )))
233 233  1. [[image:image-20220531141800-32.png]](((
313 +
314 +
234 234  Open Serial monitor.
235 235  
236 236  
237 237  
238 238  )))
239 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/9/98/MQTT_Sketch_1.png/400px-MQTT_Sketch_1.png~|~|height="261" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Sketch_1.png]](((
320 +1. [[image:image-20220531143748-48.png]](((
321 +
322 +
240 240  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.
324 +
325 +
326 +
241 241  )))
242 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/3/3d/MQTT_Sketch3.png/400px-MQTT_Sketch3.png~|~|height="371" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Sketch3.png]](((
328 +1. [[image:image-20220531141927-34.png]](((
329 +
330 +
243 243  Open Serial monitor.
332 +
333 +
334 +
244 244  )))
245 245  1. Go to IoT Server to check the result.
246 246  1. (((
247 -[[~[~[image:https://wiki.dragino.com/images/thumb/4/43/MQTT_result_1.png/400px-MQTT_result_1.png~|~|alt="MQTT result 1.png" height="181" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_result_1.png]]
338 +[[image:image-20220531143707-47.png]]
339 +
340 +
341 +
248 248  )))
249 249  1. (((
250 -[[~[~[image:https://wiki.dragino.com/images/thumb/7/70/MQTT_result_2.png/400px-MQTT_result_2.png~|~|alt="MQTT result 2.png" height="190" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_result_2.png]]
344 +[[image:image-20220531143632-46.png]]
345 +
346 +
347 +
251 251  )))
252 252  
253 253  = 5. FAQ =
254 254  
352 +
255 255  == 5.1 Configure to support general mqtt server ==
256 256  
355 +
257 257  First, try to run **mosquitto_pub** in Linux console to send a data to MQTT server.
258 258  
259 259  For example: for ThingSpeak, a MQTT publish command is:
260 260  
261 -{{{mosquitto_pub -h mqtt.thingspeak.com -p 1883 -u dragino -P QZXTAKE88V3S7O2J -i dragino_Client -t channels/200893/publish/B9Z0R25QNVEBKIFY -m "field1=34&field2=89&status=MQTTPUBLISH"
262 -}}}
360 +(% class="box infomessage" %)
361 +(((
362 +**mosquitto_pub -h mqtt.thingspeak.com -p 1883 -u dragino -P QZXTAKE88V3S7O2J  -i dragino_Client -t channels/200893/publish/B9Z0R25QNVEBKIFY -m "field1=34&field2=89&status=MQTTPUBLISH"**
363 +)))
263 263  
264 264  What now we need to put in the LG01 is how to combine this command.
265 265  
266 266  1. LG01 web console -> Sensor -> MQTT
267 267  1. Choose general Server
268 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/e/ea/MQTT_Configure1.png/600px-MQTT_Configure1.png~|~|height="367" width="600"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Configure1.png]](((
369 +1. [[image:image-20220531142342-37.png]](((
370 +
371 +
269 269  Refer to your server to fill in.
373 +
374 +
375 +
270 270  )))
271 -1. [[~[~[image:https://wiki.dragino.com/images/0/07/MQTT_Configure2.png~|~|height="93" width="538"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Configure2.png]](((
377 +1. [[image:image-20220531142447-38.png]](((
378 +
379 +
272 272  Ex:ThingSpeak Server
381 +
382 +
273 273  )))
274 274  
275 275  According to MQTT commands: mosquitto_pub, we need to put
... ... @@ -288,29 +288,54 @@
288 288  
289 289  User can also enable MQTT debug in the LG01 ~-~-> IoT Server settings and run logread in Linux console to see how the mqtt command is compose. below is an example:
290 290  
291 -[[~[~[image:https://wiki.dragino.com/images/thumb/8/81/MQTT_Configure3.png/600px-MQTT_Configure3.png~|~|height="114" width="600"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Configure3.png]]
401 +[[image:image-20220531142525-39.png]]
292 292  
403 +
293 293  MQTT Logread example
294 294  
295 295  
407 +
296 296  == 5.2 What is Watchdog feature? ==
297 297  
410 +
298 298  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.
299 299  
300 -* [[~[~[image:https://wiki.dragino.com/images/thumb/f/f2/Wathcdog.png/400px-Wathcdog.png~|~|height="184" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:Wathcdog.png]](((
413 +
414 +* [[image:image-20220531142558-40.png]](((
301 301  Enable Sensor->Micro-Controller settings
416 +
417 +
418 +
302 302  )))
303 -* [[~[~[image:https://wiki.dragino.com/images/thumb/8/82/MQTT_Sketch_2.png/400px-MQTT_Sketch_2.png~|~|height="233" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Sketch_2.png]](((
420 +* [[image:image-20220531142629-41.png]](((
421 +
422 +
304 304  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.
424 +
425 +
426 +
305 305  )))
306 -* [[~[~[image:https://wiki.dragino.com/images/2/21/Loop.png~|~|height="181" width="388"~]~]>>url:https://wiki.dragino.com/index.php/File:Loop.png]](((
428 +* [[image:image-20220531142659-42.png]](((
429 +
430 +
307 307  Each time the function loops, it uses the watchdog function once.
432 +
433 +
434 +
308 308  )))
309 -* [[~[~[image:https://wiki.dragino.com/images/thumb/3/35/Dog.png/400px-Dog.png~|~|height="161" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:Dog.png]](((
436 +* [[image:image-20220531142720-43.png]](((
437 +
438 +
310 310  Open SSH and check watchdog result.If the result change constantly,the feature enable successfully.
440 +
441 +
442 +
311 311  )))
312 -* [[~[~[image:https://wiki.dragino.com/images/thumb/a/ac/Checkdog.png/400px-Checkdog.png~|~|height="222" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:Checkdog.png]](((
444 +* [[image:image-20220531142748-44.png]](((
445 +
446 +
313 313  If the time doesnt's change,you can refer it to calculate for checking status.
314 314  )))
315 315  
316 -== ==
450 +(% class="wikigeneratedid" id="H" %)
451 +
image-20220531141842-33.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +39.2 KB
Content
image-20220531141927-34.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +26.8 KB
Content
image-20220531142023-35.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +34.5 KB
Content
image-20220531142155-36.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +42.9 KB
Content
image-20220531142342-37.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +27.4 KB
Content
image-20220531142447-38.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +4.7 KB
Content
image-20220531142525-39.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +69.1 KB
Content
image-20220531142558-40.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +43.9 KB
Content
image-20220531142629-41.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +38.2 KB
Content
image-20220531142659-42.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +5.1 KB
Content
image-20220531142720-43.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +13.3 KB
Content
image-20220531142748-44.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +11.5 KB
Content
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