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

From version 25.1
edited by Xiaoling
on 2022/05/31 14:11
Change comment: Uploaded new attachment "image-20220531141150-24.png", version {1}
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,23 +183,48 @@
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  
188 -1. [[~[~[image:https://wiki.dragino.com/images/8/84/3_1.png~|~|height="99" width="93"~]~]>>url:https://wiki.dragino.com/index.php/File:3_1.png]](((
256 +
257 +1. [[image:image-20220531141150-24.png]](((
258 +
259 +
189 189  Open this Application.
261 +
262 +
263 +
190 190  )))
191 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/6/6e/MQTT_Command_2.png/400px-MQTT_Command_2.png~|~|height="76" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Command_2.png]](((
265 +1. (((
266 +[[image:image-20220531141400-27.png]]
267 +
268 +
192 192  Check the settings.
270 +
271 +
272 +
193 193  )))
194 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/8/8d/MQTT_Command_1.png/400px-MQTT_Command_1.png~|~|height="343" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Command_1.png]](((
274 +1. (((
275 +[[image:image-20220531141601-30.png]]
276 +
277 +
195 195  input this command.
279 +
280 +
281 +
196 196  )))
197 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/d/de/MQTT_Command_3.png/400px-MQTT_Command_3.png~|~|height="207" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Command_3.png]](((
283 +1. [[image:image-20220531141515-29.png]](((
284 +
285 +
198 198  Check the result.
287 +
288 +
289 +
199 199  )))
200 200  
201 201  == 4.7 Updata data to Server(Through MQTT) ==
202 202  
294 +
203 203  * This version of Sketch implements these features:
204 204  
205 205  1. Read the LG01 configuration information from Linux.
... ... @@ -208,46 +208,86 @@
208 208  1. Sketch will write active content to /tmp/iot/status periodically (every 5 minutes).(Watchdog feature)
209 209  
210 210  
211 -1. [[~[~[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]](((
303 +
304 +1. [[image:image-20220531143822-49.png]](((
305 +
306 +
212 212  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.
308 +
309 +
310 +
213 213  )))
214 -1. [[~[~[image:https://wiki.dragino.com/images/thumb/7/73/MQTT_Sketch2.png/400px-MQTT_Sketch2.png~|~|height="540" width="400"~]~]>>url:https://wiki.dragino.com/index.php/File:MQTT_Sketch2.png]](((
312 +1. [[image:image-20220531141800-32.png]](((
313 +
314 +
215 215  Open Serial monitor.
316 +
317 +
318 +
216 216  )))
217 -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 +
218 218  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 +
219 219  )))
220 -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 +
221 221  Open Serial monitor.
332 +
333 +
334 +
222 222  )))
223 223  1. Go to IoT Server to check the result.
224 224  1. (((
225 -[[~[~[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 +
226 226  )))
227 227  1. (((
228 -[[~[~[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 +
229 229  )))
230 230  
231 231  = 5. FAQ =
232 232  
352 +
233 233  == 5.1 Configure to support general mqtt server ==
234 234  
355 +
235 235  First, try to run **mosquitto_pub** in Linux console to send a data to MQTT server.
236 236  
237 237  For example: for ThingSpeak, a MQTT publish command is:
238 238  
239 -{{{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"
240 -}}}
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 +)))
241 241  
242 242  What now we need to put in the LG01 is how to combine this command.
243 243  
244 244  1. LG01 web console -> Sensor -> MQTT
245 245  1. Choose general Server
246 -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 +
247 247  Refer to your server to fill in.
373 +
374 +
375 +
248 248  )))
249 -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 +
250 250  Ex:ThingSpeak Server
381 +
382 +
251 251  )))
252 252  
253 253  According to MQTT commands: mosquitto_pub, we need to put
... ... @@ -266,29 +266,54 @@
266 266  
267 267  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:
268 268  
269 -[[~[~[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]]
270 270  
403 +
271 271  MQTT Logread example
272 272  
273 273  
407 +
274 274  == 5.2 What is Watchdog feature? ==
275 275  
410 +
276 276  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.
277 277  
278 -* [[~[~[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]](((
279 279  Enable Sensor->Micro-Controller settings
416 +
417 +
418 +
280 280  )))
281 -* [[~[~[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 +
282 282  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 +
283 283  )))
284 -* [[~[~[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 +
285 285  Each time the function loops, it uses the watchdog function once.
432 +
433 +
434 +
286 286  )))
287 -* [[~[~[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 +
288 288  Open SSH and check watchdog result.If the result change constantly,the feature enable successfully.
440 +
441 +
442 +
289 289  )))
290 -* [[~[~[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 +
291 291  If the time doesnt's change,you can refer it to calculate for checking status.
292 292  )))
293 293  
294 -== ==
450 +(% class="wikigeneratedid" id="H" %)
451 +
image-20220531141303-26.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +35.4 KB
Content
image-20220531141400-27.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +17.0 KB
Content
image-20220531141515-29.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +36.1 KB
Content
image-20220531141601-30.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +34.5 KB
Content
image-20220531141656-31.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +38.8 KB
Content
image-20220531141800-32.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Xiaoling
Size
... ... @@ -1,0 +1,1 @@
1 +32.9 KB
Content
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