Changes for page 05 Lua Script
Last modified by Devin Chen on 2025/03/04 14:07
From version 21.2
edited by Hunter
on 2022/12/13 12:04
on 2022/12/13 12:04
Change comment:
There is no comment for this version
To version 31.1
edited by Theodore Xu
on 2023/04/20 17:36
on 2023/04/20 17:36
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 2 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Hunter1 +XWiki.AiXia - Content
-
... ... @@ -88,7 +88,10 @@ 88 88 89 89 = 10** How to parse value from subscribing MQTT topic** = 90 90 91 -This example shows how to parse value from subscribing MQTT topic. The testing topic name is "testtopic/test/no1/123456". 91 +This example shows how to parse value from subscribing MQTT topic. Get the value and calculate the average value for group F1, F2, F3 and F4. The testing topic name is "testtopic/test/no1/123456". 92 + 93 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/MQTT%20JSON%20parse.zip]] 94 + 92 92 And the subscribed content is like following: 93 93 94 94 {{code language="json"}} ... ... @@ -209,9 +209,43 @@ 209 209 } 210 210 {{/code}} 211 211 212 - So we decode this json into lua object, and then assign the values from "Value" field into addresses HDW1~~HDW101, HDW112~~HDW202, HDW213~~HDW313, HDW324~~HDW424. 215 + So we decode this json into lua object, and then assign the values from "Value" field into table (addresses HDW1~~HDW101, HDW112~~HDW202, HDW213~~HDW313, HDW324~~HDW424). 213 213 214 214 (% style="text-align:center" %) 215 215 [[image:MQTTScreen.png]] 216 216 217 - 220 +Due to the MQTT code is not able to running on the simulator from PC, following picture is the testing result from actual HMI screen: 221 + 222 +(% style="text-align:center" %) 223 +[[image:MQTTactualtestingresult.png]] 224 + 225 +The JSON parser function is located on mqttAction.lua, called mqtt_msg_callback. 226 + 227 +(% style="text-align:center" %) 228 +[[image:MQTTJSONparsefunction.png]] 229 + 230 += **11 High-Low Byte Switch** = 231 + 232 +The example shows how to convert high bytes and low bytes for one 16bit address. Main function is like following: 233 + 234 +{{code language="lua"}} 235 +local lowByte = val & 0x00ff 236 +local shiftHigh = lowByte << 8 237 +local highByte = val & 0xff00 238 +local shiftLow = highByte >> 8 239 +local newVal = shiftHigh|shiftLow 240 +{{/code}} 241 + 242 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/byteswitch.zip]] 243 + 244 += **12 Week time setting** = 245 + 246 +The example shows how to use day time to control functions: 247 + 248 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/week%20time.zip]] 249 + 250 += **13 MQTT Multi-link** = 251 + 252 +The example shows use mqtt realize multi-machine function: 253 + 254 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/MQTT%20Multi-link.zip]]
- MQTTJSONparsefunction.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.Hunter - Size
-
... ... @@ -1,0 +1,1 @@ 1 +124.0 KB - Content
- MQTTactualtestingresult.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.Hunter - Size
-
... ... @@ -1,0 +1,1 @@ 1 +945.6 KB - Content