Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 0 added, 1 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Stone1 +XWiki.admin - Content
-
... ... @@ -13,7 +13,7 @@ 13 13 for example. addr_setshort(addr,num) Function: Write 16-bit signed decimal address 14 14 addr_getshort(addr) Function:Read 16-bit signed decimal address 15 15 addr_getword(string addr)Function: Read 16-bit unsigned decimal address 16 -More script function are in the second section of [[“V-BOX Script Interface Manual”>>doc:V-BOX.V-Net.Manual.04 Lua Script.01 Lua Functions.WebHome]] 16 +More script function are in the second section of [[“V-BOX Script Interface Manual”>>doc:V-BOX.V-Net.1\.User Manual.04 Lua Script.01 Lua Functions.WebHome]] 17 17 18 18 == **1.2 Arithmetic** == 19 19 ... ... @@ -36,35 +36,34 @@ 36 36 37 37 Script is as below: 38 38 39 -(% class="box infomessage" %) 40 -((( 39 +{{code language="Lua"}} 41 41 function sms.main() 42 - ~-~-~-~-~-~-send condition~-~-~-~-~-~-41 +------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~-~-~-~-~-~-47 +------lasting time------ 49 49 if temp1 > 5 and temp2 > 10 and temp3 < 20 then 50 - 51 - 49 + timer = timer + 1 50 + addr_setword("@Timer",timer) 52 52 else 53 - 54 - 52 + timer = 0 53 + addr_setword("@Timer",timer) 55 55 end 56 - ~-~-~-~-~-~-send sms & output Y0~-~-~-~-~-~-55 +------send sms & output Y0------ 57 57 if timer > 5 then 58 - 59 - 60 - 61 - 57 + if tag == 0 then 58 + send_sms_ira("19859254700","alarm trigger") 59 + addr_setbit("@Tag",1) 60 + end 62 62 elseif tag == 1 then 63 63 send_sms_ira("19859254700","alarm release") 64 64 addr_setbit("@Tag",0) 65 65 end 66 66 end 67 - )))66 +{{/code}} 68 68 69 69 == **1.5 Telegram notification** == 70 70 ... ... @@ -154,137 +154,13 @@ 154 154 155 155 (% class="mark" %)2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate 156 156 157 -(% class="wikigeneratedid" %) 158 -**✎Note: **Before program the script of MQTT, please make sure the server(MQTT broker) can be connected through MQTT Client tool. 156 +== **2.1 V-Box connect with customer server:grouprobotinfo.com** == 159 159 160 -(% class="wikigeneratedid" %) 161 -Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]** 162 - 163 -== **2.1 V-Box connect with test server(General Example)** == 164 - 165 -{{code language="lua"}} 166 ---MQTT configuration table 167 -local MQTT_CFG={} 168 -MQTT_CFG.username = "weconsupport" 169 -MQTT_CFG.password = "123456" 170 -MQTT_CFG.netway = 0 171 -MQTT_CFG.keepalive = 60 172 -MQTT_CFG.cleansession = 1 173 ---TCP URL 174 -MQTT_URL = "tcp://mq.tongxinmao.com:1883" 175 ---Client ID 176 -MQTT_CLIENT_ID = "V-BOXH-AG" 177 - 178 ---Generate UUID 179 -function uuid() 180 - local seed = {'e','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'} 181 - local tb = {} 182 - for i=1, 32 do 183 - table.insert(tb, seed[math.random(1,16)]) 184 - end 185 - local sid=table.concat(tb) 186 - return string.format('%s', 187 - string.sub(sid,1,32) 188 - ) 189 -end 190 - 191 - 192 ---Topic name to subscribed 193 -local SUBSCRIBE_TOPIC = 'testtopic/test/no1/123456' 194 - 195 ---Topic name to be published 196 -local PUBLISH_TOPIC = 'testtopic/test/no1/7890' 197 - 198 - 199 ---real time 200 -local LAST_TIME = 0 201 - 202 - 203 ---initialize mqtt 204 -function mqtt_init() 205 - print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID)) 206 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable 207 - if g_mq then 208 - g_mq:on("message", mqtt_msg_callback) -- Register a callback for receiving messages 209 - print("mqtt init success") 210 - else 211 - print("mqtt init failed:", err) 212 - end 213 -end 214 - 215 --- connect to mqtt 216 -function mqtt_connect() 217 - print("mqtt connecting...") 218 - local stat, err = g_mq:connect(MQTT_CFG) 219 - if stat == nil then 220 - print("mqtt connect failed:", err) 221 - return 222 - else 223 - print("mqtt connected") 224 - end 225 - g_mq:subscribe(SUBSCRIBE_TOPIC, 0) 226 -end 227 - 228 --- Received message callback function 229 -function mqtt_msg_callback(topic, msg) 230 - print("topic:", topic) 231 - print("msg:", msg) 232 - local objMsg = json.decode(msg) 233 - local water = objMsg.data.waterlevel 234 - local temp = objMsg.data.temperature 235 - addr_setword("@HDW20",water) 236 - addr_setword("@HDW10",temp) 237 -end 238 - 239 ---Send data (data upload to platform and encapsulate it with custom functions) 240 -function send_data() 241 - local pub_data = { 242 - timestamp = os.time(), 243 - messageId = 1, 244 - event = 'test_data', 245 - mfrs = 'V-Box', 246 - data = { 247 - id = uuid(), 248 - waterlevel = addr_getword("@HDW10"), 249 - temperature = addr_getword("@HDW20") 250 - } 251 - } 252 - return g_mq:publish(PUBLISH_TOPIC, json.encode(pub_data), 0, 0) 253 -end 254 - 255 - 256 ---main function fixed timed execution 257 -function MQTT.main() 258 - --dosomething 259 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main start") 260 - --determine the mqtt object whether exist 261 - if g_mq then 262 - --determine the mqtt object whether has been connected or not 263 - if g_mq:isconnected() then 264 - send_data() 265 - else 266 - --if exceed 20 sec not connect, reconnect once 267 - if os.time() - LAST_TIME > 20 then 268 - LAST_TIME = os.time() 269 - --connect to mqtt or reconnect 270 - mqtt_connect() 271 - end 272 - end 273 - else 274 - --mqtt object does not exist so create new one 275 - mqtt_init() 276 - end 277 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main end") 278 -end 279 -{{/code}} 280 - 281 -== **2.2 V-Box connect with customer server:grouprobotinfo.com** == 282 - 283 283 This demo does not use SSL certification. Script is as below 284 284 285 285 Demo1: 286 286 287 -{{code language=" lua"}}162 +{{code language="Lua"}} 288 288 -- Meta class 289 289 --main 290 290 function mq.main() ... ... @@ -405,7 +405,7 @@ 405 405 FSE=addr_getbit("@B_25395#W2.04"), 406 406 AVVSVV=addr_getbit("@B_25395#W1.12"), 407 407 ICHT=addr_getbit("@B_25395#W3.06") 408 - 283 + 409 409 } 410 410 411 411 -- ("@B_25395#CIO1.02") ... ... @@ -427,7 +427,7 @@ 427 427 end 428 428 {{/code}} 429 429 430 -== **2. 3V-Box connect with Azure platform** ==305 +== **2.2 V-Box connect with Azure platform** == 431 431 432 432 In this demo,V-Box connects with Azure by SSL certification. 433 433 ... ... @@ -437,129 +437,137 @@ 437 437 438 438 Script is as below 439 439 440 -(% class="box infomessage" %) 441 -((( 442 -~-~-https:~/~/support.huaweicloud.com/qs-IoT/iot_05_0005.html mqtt.fx monitor to connect azure iot 315 +{{code language="Lua"}} 316 +--https://support.huaweicloud.com/qs-IoT/iot_05_0005.html mqtt.fx monitor to connect azure iot 443 443 sprint = print 444 444 445 - ~-~-Get custom configuration parameters (vbox custom information)446 - ~-~-local CUSTOM = bns_get_config("bind")447 - ~-~-local DS_ID = CUSTOM.DSID or "60a71ccbbbe12002c08f3a1a_WECON"319 +--Get custom configuration parameters (vbox custom information) 320 +--local CUSTOM = bns_get_config("bind") 321 +--local DS_ID = CUSTOM.DSID or "60a71ccbbbe12002c08f3a1a_WECON" 448 448 449 449 450 -~-~-Cloud mode interface to obtain the MQTT information configured by the cloud platform: (5 returns, namely the server address, client ID, connection table, last word table, certificate table) 324 + 325 +--Cloud mode interface to obtain the MQTT information configured by the cloud platform: (5 returns, namely the server address, client ID, connection table, last word table, certificate table) 451 451 local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg() 452 452 453 - ~-~-MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON'454 - ~-~-MQTT_CFG.password='wecon123'455 - ~-~-MQTT_CLIENTID = '60a71ccbbbe12002c08f3a1a_WECON_0_0_2021052110usernxame:60a71ccbbbe12002c08f3a1a_WECONpassword:a0a951581855aa8e0262129da6cf1b43f2c0ecfac4fa56117fc5a20c90be169a'328 +--MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON' 329 +--MQTT_CFG.password='wecon123' 330 +--MQTT_CLIENTID = '60a71ccbbbe12002c08f3a1a_WECON_0_0_2021052110usernxame:60a71ccbbbe12002c08f3a1a_WECONpassword:a0a951581855aa8e0262129da6cf1b43f2c0ecfac4fa56117fc5a20c90be169a' 456 456 457 - ~-~-publish to topics332 +--publish to topics 458 458 local pub_RE_TOPIC = string.format('devices/wecon_02/messages/events/') 459 - ~-~-Subscribe topics334 +--Subscribe topics 460 460 local Subscribe_RE_TOPIC1 = string.format('devices/wecon_02/messages/devicebound/#') 461 461 462 - ~-~-variable337 +--variable 463 463 local last_time = 0 464 464 465 465 466 -~-~-Timing main function 341 + 342 +--Timing main function 467 467 function Azure.main() 468 468 469 - 470 - 471 - 472 - 473 - 474 - 475 - 476 - 477 - 478 - 479 - 480 - 481 - 482 - 345 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main start") 346 + if g_mq then 347 + if g_mq:isconnected() then 348 + send_Data() 349 + else 350 + if os.time() - last_time > 20 then 351 + last_time = os.time() 352 + mymqtt_connect() 353 + end 354 + end 355 + else 356 + mymqtt_init() 357 + end 358 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main end") 483 483 end 484 484 485 - ~-~- Initialize MQTT361 +-- Initialize MQTT 486 486 function mymqtt_init() 487 - 488 - ~-~- Create the object and declare it as a global variable489 - 490 - ~-~- Register to receive message callbacks491 - 492 - 493 - 494 - 363 + sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID)) 364 + g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) -- Create the object and declare it as a global variable 365 + if g_mq then 366 + g_mq:on("message", mymqtt_msg_callback) -- Register to receive message callbacks 367 + sprint("mqtt init success") 368 + else 369 + sprint("mqtt init failed:", err) 370 + end 495 495 end 496 496 497 - ~-~- Connect to MQTT server373 +-- Connect to MQTT server 498 498 function mymqtt_connect() 499 - 500 - 501 - 502 - 503 - 504 - 505 - 506 - 507 - 375 + sprint("mqtt connecting...") 376 + local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART) 377 + if stat == nil then 378 + sprint("mqtt connect failed:", err) 379 + return 380 + else 381 + sprint("mqtt connected") 382 + end 383 + g_mq:subscribe(Subscribe_RE_TOPIC1, 0) 508 508 end 509 509 510 - ~-~- Receive MQTT message callback function386 +-- Receive MQTT message callback function 511 511 function mymqtt_msg_callback(topic, msg) 512 - 513 - 514 - ~-~- local revData = json.decode(msg)515 - ~-~-~-~-Process topic information subscribed from the cloud516 - ~-~- if string.match(topic,Subscribe_RE_TOPIC1) then517 - ~-~-518 - 519 - ~-~- end388 + print("topic:",topic) 389 + print("revdata:",msg) 390 + -- local revData = json.decode(msg) 391 + -- if topic == Subscribe_RE_TOPIC1 then --Process topic information subscribed from the cloud 392 +-- if string.match(topic,Subscribe_RE_TOPIC1) then 393 + -- print("topi11:",topic) 394 + setValue(revData) 395 + -- end 520 520 end 521 521 522 - ~-~-Process the received data523 - ~-~-function setValue(revData)524 - ~-~- if revData ~~=nil then525 - ~-~-526 - ~-~-527 - ~-~-528 - ~-~- end529 - ~-~-end398 +--Process the received data 399 +--function setValue(revData) 400 + -- if revData ~=nil then 401 + -- for i,v in pairs(revData) do 402 + -- print("Data received:",i,v) 403 + -- end 404 + -- end 405 +--end 530 530 531 - ~-~-Get real-time data407 +--Get real-time data 532 532 function getData() 533 - 534 - 535 - 536 - 537 - 538 - 539 - 540 - 541 - 542 -end 409 + local jdata = {} 410 + local addr = bns_get_alldata() 411 + print(json.encode(addr)) 412 + for i,v in pairs(addr) do 413 + if v[2] == 1 then 414 + jdata[v[3]] = v[4] 415 + end 416 + end 417 + return jdata 418 +end 543 543 544 544 545 -~-~-send data 421 + 422 +--send data 546 546 function send_Data() 547 - local pub_data = {100 548 - ~-~- services=~{~{ 549 -\\ ~-~-serviceId ='Temperature', 550 - ~-~- properties={ 551 - ~-~- value = 55 552 - ~-~- }, 553 - ~-~- }} 424 + local pub_data = {100 425 + -- services={{ 426 + 427 + --serviceId ='Temperature', 428 + -- properties={ 429 + -- value = 55 430 + -- }, 431 + -- }} 554 554 } 555 555 sprint(json.encode(pub_data)) 556 556 print("..........",pub_RE_TOPIC) 557 - 435 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0) 558 558 end 559 - )))437 +{{/code}} 560 560 561 -== **2. 4How 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)** ==439 +== **2.3 How to configure the Huawei platform?** == 562 562 441 +(% class="box infomessage" %) 442 +((( 443 +✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register 444 +))) 445 + 563 563 1.Register a account: [[https:~~/~~/www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ>>https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ]] 564 564 565 565 2.log in the Huawei IOTDA ... ... @@ -707,7 +707,7 @@ 707 707 (% style="text-align:center" %) 708 708 [[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]] 709 709 710 -== **2. 5V-Box connect with Huawei platform** ==593 +== **2.4 V-Box connect with Huawei platform** == 711 711 712 712 In this demo,V-Box connects with Huawei by SSL certification. 713 713 ... ... @@ -828,7 +828,7 @@ 828 828 (% style="text-align:center" %) 829 829 [[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]] 830 830 831 -== **2. 6V-Box connect with AWS platform** ==714 +== **2.5 V-Box connect with AWS platform** == 832 832 833 833 === **Log in AWS** === 834 834 ... ... @@ -885,67 +885,96 @@ 885 885 } 886 886 {{/code}} 887 887 888 - ===**Create things**===771 +1. **Create things** 889 889 890 890 Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing” 891 891 892 -[[image:image-20220709165402-6.png]] 893 893 894 -[[image:image-20220709165402-7.png]] 776 +| 777 +| |[[image:image-20220709165402-6.png]] 895 895 779 +| 780 +| |[[image:image-20220709165402-7.png]] 781 + 782 +| 783 +| |[[image:image-20220709165402-8.png]] 784 + 896 896 Name the thing~-~-->Click “Next” 897 897 898 -[[image:image-20220709165402-8.png]] 899 899 900 900 Select the way to create certificate 901 901 902 -[[image:image-20220709165402-9.png]] 903 903 791 +| 792 +| |[[image:image-20220709165402-9.png]] 793 + 904 904 Select policy 905 905 906 -[[image:image-20220709165402-10.png]] 907 907 908 -[[image:image-20220709165402-11.png]] 797 +| 798 +| |[[image:image-20220709165402-10.png]] 909 909 910 910 911 -=== **Test with MQTT.fx tool** === 912 912 802 + 803 +| 804 +| |[[image:image-20220709165402-11.png]] 805 + 806 +1. **Test with MQTT.fx tool** 807 + 913 913 Click “View Setting” to get the “Broker Adress” 914 914 915 -[[image:image-20220709165402-13.png]] 916 916 917 -[[image:image-20220709165402-12.png]] 811 +| 812 +| |[[image:image-20220709165402-12.png]] 918 918 919 -Create one connection in MQTT.fx tool, set broker port as 8883. 814 +| 815 +| |[[image:image-20220709165402-13.png]] 920 920 921 -[[image:image-20220709165402-14.png]] 922 922 818 + 819 +| 820 +| |[[image:image-20220709165402-14.png]] 821 + 822 +Create one connection in MQTT.fx tool, set broker port as 8883. 823 + 923 923 Upload the CA File, Client Certificate File, Client Key File 924 924 925 -[[image:image-20220709165402-15.png]] 926 926 827 +| 828 +| |[[image:image-20220709165402-15.png]] 829 + 927 927 Publish message to topic “TEST” 928 928 929 -[[image:image-20220709165402-17.png]] 930 930 931 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 833 +| 834 +| |[[image:image-20220709165402-16.png]] 932 932 933 -[[image:image-20220709173500-1.png]] 836 +| 837 +| |[[image:image-20220709165402-17.png]] 934 934 839 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 840 + 935 935 And we can also send message form AWS platform to MQTT.fx tool. 936 936 937 -[[image:image-20220709165402-18.png]] 938 938 939 -=== **Configurate in CloudTool** === 844 +| 845 +| |[[image:image-20220709165402-18.png]] 940 940 847 +1. **Configurate in CloudTool** 848 + 941 941 Copy the same setting in MQTT.fx to MQTT configuration 942 942 943 -[[image:image-20220709165402-19.png]] 944 944 852 +| 853 +| |[[image:image-20220709165402-19.png]] 854 + 945 945 Add a lua script and copy the lua demo into it. 946 946 947 -[[image:image-20220709165402-20.png]] 948 948 858 +| 859 +| |[[image:image-20220709165402-20.png]] 860 + 949 949 sprint = print 950 950 951 951 ~-~-Cloud mode interface to obtain the MQTT information configured by the cloud platform: (5 returns, namely the server address, client ID, connection table, last word table, certificate table) ... ... @@ -1126,6 +1126,10 @@ 1126 1126 1127 1127 end 1128 1128 1041 + 1042 + 1129 1129 Get message in AWS 1130 1130 1131 -[[image:image-20220709165402-21.png]] 1045 + 1046 +| 1047 +| |[[image:image-20220709165402-21.png]]
- image-20220709173500-1.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.Jim - Size
-
... ... @@ -1,1 +1,0 @@ 1 -1.5 MB - Content