Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
From version 39.1
edited by Hunter
on 2023/03/17 15:50
on 2023/03/17 15:50
Change comment:
There is no comment for this version
To version 60.1
edited by Theodore Xu
on 2023/08/24 17:17
on 2023/08/24 17:17
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Hunter1 +XWiki.AiXia - Content
-
... ... @@ -1,9 +1,9 @@ 1 1 = **1 General Script Demo** = 2 2 3 -== **1.1 Address Operation :Write/Read data from address A to B** ==3 +== **1.1 Address Operation** == 4 4 5 5 ((( 6 -For example:transfer D2 to D0 6 +Write/Read data from address A to B**. **For example:transfer D2 to D0 7 7 ))) 8 8 9 9 (% style="text-align:center" %) ... ... @@ -27,25 +27,19 @@ 27 27 28 28 == **1.4 Short message** == 29 29 30 - When the alarm condition is reached: temp1 > 5 & temp2 >10 & temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms.30 +The following demo shows that when the alarm condition is reached: temp1 > 5 & temp2 >10 & temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms. 31 31 32 -When the alarm condition is released,then send an "alarm release" sms. 32 +When the alarm condition is released,then send an "alarm release" sms. Script is as below: 33 33 34 -(% style="text-align:center" %) 35 -[[image:1645535936750-316.png||height="385" width="400" class="img-thumbnail"]] 36 - 37 -Script is as below: 38 - 39 -(% class="box infomessage" %) 40 -((( 34 +{{code language="lua"}} 41 41 function sms.main() 42 - ~-~-~-~-~-~-send condition~-~-~-~-~-~-36 +------send condition------ 43 43 local temp1 = addr_getword("@Temperature1") 44 44 local temp2 = addr_getword("@Temperature2") 45 45 local temp3 = addr_getword("@Temperature3") 46 46 local timer = addr_getword("@Timer") 47 47 local tag = addr_getbit("@Tag") 48 - ~-~-~-~-~-~-lasting time~-~-~-~-~-~-42 +------lasting time------ 49 49 if temp1 > 5 and temp2 > 10 and temp3 < 20 then 50 50 timer = timer + 1 51 51 addr_setword("@Timer",timer) ... ... @@ -53,7 +53,7 @@ 53 53 timer = 0 54 54 addr_setword("@Timer",timer) 55 55 end 56 - ~-~-~-~-~-~-send sms & output Y0~-~-~-~-~-~-50 +------send sms & output Y0------ 57 57 if timer > 5 then 58 58 if tag == 0 then 59 59 send_sms_ira("19859254700","alarm trigger") ... ... @@ -64,7 +64,7 @@ 64 64 addr_setbit("@Tag",0) 65 65 end 66 66 end 67 - )))61 +{{/code}} 68 68 69 69 == **1.5 Telegram notification** == 70 70 ... ... @@ -145,7 +145,7 @@ 145 145 146 146 This example shows how to use the LINE Notify to send message into LINE group. When monitoring bit "@test" changes, it will trigger and send the message. Please replace with your own Token. 147 147 148 -{{code}} 142 +{{code language="lua"}} 149 149 local tempBit = 0 150 150 local tempWord = 0 151 151 ... ... @@ -447,8 +447,39 @@ 447 447 end 448 448 {{/code}} 449 449 450 -= ** 2V-Boxconnect withthird part server** =444 +== **1.9 High-Low Byte Switch** == 451 451 446 +The following example is converting the floating number from order 1234 to order 3412, and formating output the number with 2 decimal point. About which high-low word order corresponding to which value, please refer to the [[Address Operation Table>>doc:V-BOX.V-Net.Manual.04 Lua Script.01 Lua Functions.WebHome||anchor="H2Addressoperation"]]. 447 + 448 +{{code language="lua"}} 449 +function highLowByteSwitch(floatNumber) 450 + addr_setfloat("@W_0#HDW23036",floatNumber,0,2) 451 + local newFloat = addr_getfloat("@W_0#HDW23036") 452 + local formattedFloat = string.format("%.2f",newFloat) 453 + print("The formatted float value is the : "..formattedFloat) 454 + return formattedFloat 455 +end 456 +{{/code}} 457 + 458 +== **1.10 Read 64bits Unsigned Value** == 459 + 460 +In our built-in function library doesn't have the function for reading 64-bit unsigned format value, so the following function is for solve this. But if the number is greater 2^53, the precision will be lost. So the final result will be a little bit different from the original value. 461 + 462 +{{code language="lua"}} 463 +function addr_getquatra(address) 464 + local highAddress = addr_newnoaddr(address,2) 465 + local low32 = addr_getdword(address) 466 + local high32 = addr_getdword(highAddress) 467 + --print("the low number is "..low32) 468 + --print("the high number is "..high32) 469 + local formatVal = string.format("%64.0f",2^32*high32+low32) 470 + print("the format value is ".. formatVal) 471 + return formatVal 472 +end 473 +{{/code}} 474 + 475 += **2 Third part server** = 476 + 452 452 V-Box have two mode.One is for V-Net,User need to use WECON server to store data.We call this V-NET platform. 453 453 454 454 (% class="mark" %)1.Europe server:eu.v-box.net ... ... @@ -472,11 +472,31 @@ 472 472 (% class="wikigeneratedid" %) 473 473 Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]** 474 474 475 -== **2.1 V-Box connect with test server(General Example)** ==500 +== **2.1 Test server(General Example)** == 476 476 502 +The following example is trying to publish to the topic "testtopic/test/no1/7890", and subscribe the topic "testtopic/test/no1/123456". 503 + 504 +And the JSON message is like follows: 505 + 506 +{{code language="JSON"}} 507 +{ 508 + "timestamp": 1631152760, 509 + "messageId": 1, 510 + "event": "test_data", 511 + "mfrs": "HMI/box", 512 + "data": 513 + { 514 + "id" : 1436217747670454274, 515 + "waterlevel" : 48, 516 + "temperture" : 23 517 + } 518 +} 519 +{{/code}} 520 + 477 477 {{code language="lua"}} 478 478 --MQTT configuration table 479 479 local MQTT_CFG={} 524 +--if there is no need the username and password, please put them as "" 480 480 MQTT_CFG.username = "weconsupport" 481 481 MQTT_CFG.password = "123456" 482 482 MQTT_CFG.netway = 0 ... ... @@ -516,7 +516,7 @@ 516 516 function mqtt_init() 517 517 print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID)) 518 518 if g_mq then 519 - mqtt.close() --Close mqtt object 564 + mqtt.close(g_mq) --Close mqtt object 520 520 end 521 521 g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable 522 522 if g_mq then ... ... @@ -541,6 +541,11 @@ 541 541 g_mq:subscribe(SUBSCRIBE_TOPIC, 0) 542 542 end 543 543 589 +--Offline callback function 590 +function mqtt_msg_offline(cause) 591 + print("mqtt offline, cause:", cause) 592 +end 593 + 544 544 -- Received message callback function 545 545 function mqtt_msg_callback(topic, msg) 546 546 print("topic:", topic) ... ... @@ -596,7 +596,7 @@ 596 596 end 597 597 {{/code}} 598 598 599 -== **2.2 V-Box connect with customer server:grouprobotinfo.com** ==649 +== **2.2 Customer server:grouprobotinfo.com** == 600 600 601 601 This demo does not use SSL certification. Script is as below 602 602 ... ... @@ -737,7 +737,7 @@ 737 737 end 738 738 {{/code}} 739 739 740 -== **2.3 V-Box connect withAzure platform** ==790 +== **2.3 Azure platform** == 741 741 742 742 In this demo,V-Box connects with Azure by SSL certification. 743 743 ... ... @@ -868,8 +868,12 @@ 868 868 end 869 869 ))) 870 870 871 -== **2.4 H ow to configure the Huawei platform?(✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register)** ==921 +== **2.4 Huawei platform** == 872 872 923 +{{info}} 924 +**✎Note**:**Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register** 925 +{{/info}} 926 + 873 873 1.Register a account: [[https:~~/~~/www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ>>https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ]] 874 874 875 875 2.log in the Huawei IOTDA ... ... @@ -1017,10 +1017,8 @@ 1017 1017 (% style="text-align:center" %) 1018 1018 [[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]] 1019 1019 1020 -== **2.5V-Boxconnectwith Huaweiplatform**==1074 +=== Huawei by SSL certification. === 1021 1021 1022 -In this demo,V-Box connects with Huawei by SSL certification. 1023 - 1024 1024 1.Create a project access for Huawei IOT 1025 1025 1026 1026 2.configure MQTT configuration ... ... @@ -1138,7 +1138,7 @@ 1138 1138 (% style="text-align:center" %) 1139 1139 [[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]] 1140 1140 1141 -== **2.6 V-Box connect withAWS platform** ==1193 +== **2.6 AWS platform** == 1142 1142 1143 1143 === **Log in AWS** === 1144 1144 ... ... @@ -1203,7 +1203,7 @@ 1203 1203 [[image:image-20220709165402-11.png]] 1204 1204 1205 1205 1206 -=== ** Test withMQTT.fx tool** ===1258 +=== **MQTT.fx tool** === 1207 1207 1208 1208 Click “View Setting” to get the “Broker Adress” 1209 1209 ... ... @@ -1231,7 +1231,7 @@ 1231 1231 1232 1232 [[image:image-20220709165402-18.png]] 1233 1233 1234 -=== **C onfigurate in CloudTool** ===1286 +=== **CloudTool** === 1235 1235 1236 1236 Copy the same setting in MQTT.fx to MQTT configuration 1237 1237