Changes for page MQTT Forward Instruction
Last modified by Kilight Cao on 2024/08/31 16:26
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -24,7 +24,6 @@ 24 24 25 25 26 26 27 - 28 28 = 2. Firmware Change Log for MQTT feature = 29 29 30 30 ... ... @@ -37,7 +37,6 @@ 37 37 38 38 39 39 40 - 41 41 = 3. MQTT forward operating principle = 42 42 43 43 ... ... @@ -54,12 +54,13 @@ 54 54 General MQTT structure 55 55 56 56 57 -== 3.2 How sensor data is forwarded == 55 +== 3.2 How sensor data is forwarded == 58 58 57 + 59 59 In this MQTT forward feature, the key point is how the gateway process the sensor data. 60 60 61 61 62 -=== 3.2.1 Upstream === 61 +=== 3.2.1 Upstream === 63 63 64 64 Assume there are two sensor nodes, their ID are Node1 ID: 6734 , Node2 ID: 7456. In the remote MQTT broker there are two topics: Topic1: /channel/765800, Topic2: /channel/367860. We can set up in the gateway to map Node1 to Topic1 and Node2 to Topic2. So when there is a sensor data from Node1, the gateway will forward the data to Topic1, when there is sensor data from Node2, the gateway will forward to Topic2. 65 65 ... ... @@ -71,10 +71,12 @@ 71 71 72 72 ((( 73 73 Upstream path 73 + 74 + 74 74 ))) 75 75 76 76 ((( 77 -Note: The sensor data can base or LoRa or other method, as long as there are data on the file /var/iot/channels. /span> 78 +(% style="color:red" %)**Note: The sensor data can base or LoRa or other method, as long as there are data on the file /var/iot/channels. /span>** 78 78 ))) 79 79 80 80 ((( ... ... @@ -81,8 +81,9 @@ 81 81 82 82 ))) 83 83 84 -=== 3.2.2 Downstream === 85 +=== 3.2.2 Downstream === 85 85 87 + 86 86 The gateway subscribes to a topic of the remote MQTT broker topic. When there is some one publish a value on this topic. The gateway will get it and broadcast to local LoRa Network. 87 87 88 88 ((( ... ... @@ -94,8 +94,9 @@ 94 94 Downstream path 95 95 96 96 97 -== 3.3 Macro Definition == 99 +== 3.3 Macro Definition == 98 98 101 + 99 99 The MQTT publish command use Macro settings to generate flexible upstream payload for MQTT publish. 100 100 101 101 ((( ... ... @@ -104,8 +104,9 @@ 104 104 105 105 ))) 106 106 107 -=== 3.3.1 -t topic macro === 110 +=== 3.3.1 -t topic macro === 108 108 112 + 109 109 * CHANNEL: Remote Channel ID 110 110 * CLIENTID: Client ID , Same as -i 111 111 * WRITE_API: Remote Channel Write API ... ... @@ -112,8 +112,12 @@ 112 112 * USERNAME: User ID (-u) 113 113 * HOSTNAME: Device Hostname 114 114 115 -=== 3.3.2 -m message macro === 116 116 120 + 121 + 122 +=== 3.3.2 -m message macro === 123 + 124 + 117 117 * HOSTNAME: Device Hostname 118 118 * CHANNEL: Remote Channel ID 119 119 * DATA: Sensor Data without time stamp and rssi ... ... @@ -120,14 +120,18 @@ 120 120 * META: Completely sensor data with time stamp and rssi 121 121 * JSON: Convert META to json format. 122 122 123 -=== 3.3.3 Example for Macro === 124 124 132 + 133 + 134 +=== 3.3.3 Example for Macro === 135 + 136 + 125 125 [[image:image-20220527134251-4.png]] 126 126 127 127 MQTT Publish configure 128 128 129 129 130 -Above screen shots shows below format: 142 +**Above screen shots shows below format:** 131 131 132 132 * -t: CLIENTID/CHANNEL/data 133 133 * -m: DATA ... ... @@ -144,8 +144,10 @@ 144 144 ))) 145 145 146 146 147 -== 3.4 Modify the MQTT to support more options == 148 148 160 +== 3.4 Modify the MQTT to support more options == 161 + 162 + 149 149 The MQTT Client Utility used in Dragino is **mosquitto_pub** and **mosquitto_sub**. User can add more options to the mqtt commands. User can check the valid options by command mosquitto_pub ~-~-help. as below: 150 150 151 151 (% class="box" %) ... ... @@ -163,9 +163,9 @@ 163 163 [-u username [-P password]] 164 164 [~-~-will-topic [~-~-will-payload payload] [~-~-will-qos qos] [~-~-will-retain]] 165 165 [{~-~-cafile file | ~-~-capath dir} [~-~-cert file] [~-~-key file] 166 - 167 - 168 - 180 + [~-~-ciphers ciphers] [~-~-insecure] 181 + [~-~-tls-alpn protocol] 182 + [~-~-tls-engine engine] [~-~-keyform keyform] [~-~-tls-engine-kpass-sha1]] 169 169 [~-~-psk hex-key ~-~-psk-identity identity [~-~-ciphers ciphers]] 170 170 [~-~-proxy socks-url] 171 171 [~-~-property command identifier value] ... ... @@ -270,15 +270,19 @@ 270 270 ))) 271 271 272 272 273 -= 4. Example to communicate to a simple MQTT server = 274 274 275 -= =4.1Overview==288 += 4. Example to communicate to a simple MQTT server = 276 276 290 + 291 +== 4.1 Overview == 292 + 293 + 277 277 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/]]. 278 278 279 279 280 -== 4.2 Simulate via MQTT.fx utility == 297 +== 4.2 Simulate via MQTT.fx utility == 281 281 299 + 282 282 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. 283 283 284 284 ((( ... ... @@ -304,14 +304,15 @@ 304 304 Downstream: Subscribe a topic to get downstream 305 305 306 306 307 -== 4.3 Simulate via Dragino Command Line == 308 308 326 +== 4.3 Simulate via Dragino Command Line == 327 + 309 309 For first try of MQTT connection, simulate via command line is recommend, there are many servers / connection type for MQTT. They are using different connection parameters. Simulating the connection via command line will help us rapidly connect to server and debug. 310 310 311 311 In the Dragino Gateway, we use [[mosquitto client>>url:https://mosquitto.org/]] for MQTT connection. 312 312 313 313 314 -(% style="color: #4f81bd" %)**For Upstream**333 +(% style="color:blue" %)**For Upstream** 315 315 316 316 command is [[mosquitto_pub>>url:https://mosquitto.org/man/mosquitto_pub-1.html]] 317 317 ... ... @@ -324,8 +324,9 @@ 324 324 mosquitto_pub 325 325 326 326 327 -(% style="color:#4f81bd" %)**For Downstream** 328 328 347 +(% style="color:blue" %)**For Downstream** 348 + 329 329 Use [[mosquitto_sub>>url:https://mosquitto.org/man/mosquitto_sub-1.html]] to subscribe the change on the topic. 330 330 331 331 [[image:image-20220527135440-10.png]]