Changes for page 05 Lua Script

Last modified by Devin Chen on 2025/03/04 14:07

From version 21.3
edited by Hunter
on 2022/12/14 11:39
Change comment: There is no comment for this version
To version 24.1
edited by Hunter
on 2023/03/01 12:01
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -90,7 +90,7 @@
90 90  
91 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 92  
93 -Download link
93 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/MQTT%20JSON%20parse.zip]]
94 94  
95 95  And the subscribed content is like following:
96 96  
... ... @@ -227,4 +227,15 @@
227 227  (% style="text-align:center" %)
228 228  [[image:MQTTJSONparsefunction.png]]
229 229  
230 -
230 += **11 High-Low Byte Switch** =
231 +
232 +**{{code language="Lua"}}local lowByte = val & 0x00ff
233 +--take the lower 8 bits from address
234 +local shiftHigh = lowByte << 8
235 +--left shift 8 bits
236 +local highByte = val & 0xff00
237 +--take the higher 8 bits from address
238 +local shiftLow = highByte >> 8
239 +--right shift 8 bits
240 +local newVal = shiftHigh|shiftLow
241 +--bit or calculation{{/code}}**