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. Hunter1 +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.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 ... ... @@ -160,7 +160,7 @@ 160 160 161 161 Demo1: 162 162 163 -{{code language=" lua"}}162 +{{code language="Lua"}} 164 164 -- Meta class 165 165 --main 166 166 function mq.main() ... ... @@ -281,7 +281,7 @@ 281 281 FSE=addr_getbit("@B_25395#W2.04"), 282 282 AVVSVV=addr_getbit("@B_25395#W1.12"), 283 283 ICHT=addr_getbit("@B_25395#W3.06") 284 - 283 + 285 285 } 286 286 287 287 -- ("@B_25395#CIO1.02") ... ... @@ -313,126 +313,129 @@ 313 313 314 314 Script is as below 315 315 316 -(% class="box infomessage" %) 317 -((( 318 -~-~-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 319 319 sprint = print 320 320 321 - ~-~-Get custom configuration parameters (vbox custom information)322 - ~-~-local CUSTOM = bns_get_config("bind")323 - ~-~-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" 324 324 325 325 326 -~-~-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) 327 327 local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg() 328 328 329 - ~-~-MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON'330 - ~-~-MQTT_CFG.password='wecon123'331 - ~-~-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' 332 332 333 - ~-~-publish to topics332 +--publish to topics 334 334 local pub_RE_TOPIC = string.format('devices/wecon_02/messages/events/') 335 - ~-~-Subscribe topics334 +--Subscribe topics 336 336 local Subscribe_RE_TOPIC1 = string.format('devices/wecon_02/messages/devicebound/#') 337 337 338 - ~-~-variable337 +--variable 339 339 local last_time = 0 340 340 341 341 342 -~-~-Timing main function 341 + 342 +--Timing main function 343 343 function Azure.main() 344 344 345 - 346 - 347 - 348 - 349 - 350 - 351 - 352 - 353 - 354 - 355 - 356 - 357 - 358 - 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") 359 359 end 360 360 361 - ~-~- Initialize MQTT361 +-- Initialize MQTT 362 362 function mymqtt_init() 363 - 364 - ~-~- Create the object and declare it as a global variable365 - 366 - ~-~- Register to receive message callbacks367 - 368 - 369 - 370 - 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 371 371 end 372 372 373 - ~-~- Connect to MQTT server373 +-- Connect to MQTT server 374 374 function mymqtt_connect() 375 - 376 - 377 - 378 - 379 - 380 - 381 - 382 - 383 - 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) 384 384 end 385 385 386 - ~-~- Receive MQTT message callback function386 +-- Receive MQTT message callback function 387 387 function mymqtt_msg_callback(topic, msg) 388 - 389 - 390 - ~-~- local revData = json.decode(msg)391 - ~-~-~-~-Process topic information subscribed from the cloud392 - ~-~- if string.match(topic,Subscribe_RE_TOPIC1) then393 - ~-~-394 - 395 - ~-~- 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 396 396 end 397 397 398 - ~-~-Process the received data399 - ~-~-function setValue(revData)400 - ~-~- if revData ~~=nil then401 - ~-~-402 - ~-~-403 - ~-~-404 - ~-~- end405 - ~-~-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 406 406 407 - ~-~-Get real-time data407 +--Get real-time data 408 408 function getData() 409 - 410 - 411 - 412 - 413 - 414 - 415 - 416 - 417 - 418 -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 419 419 420 420 421 -~-~-send data 421 + 422 +--send data 422 422 function send_Data() 423 - local pub_data = {100 424 - ~-~- services=~{~{ 425 -\\ ~-~-serviceId ='Temperature', 426 - ~-~- properties={ 427 - ~-~- value = 55 428 - ~-~- }, 429 - ~-~- }} 424 + local pub_data = {100 425 + -- services={{ 426 + 427 + --serviceId ='Temperature', 428 + -- properties={ 429 + -- value = 55 430 + -- }, 431 + -- }} 430 430 } 431 431 sprint(json.encode(pub_data)) 432 432 print("..........",pub_RE_TOPIC) 433 - 435 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0) 434 434 end 435 - )))437 +{{/code}} 436 436 437 437 == **2.3 How 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)** == 438 438 ... ... @@ -761,67 +761,102 @@ 761 761 } 762 762 {{/code}} 763 763 764 - ===**Create things**===766 +1. **Create things** 765 765 766 766 Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing” 767 767 768 -[[image:image-20220709165402-6.png]] 769 769 770 -[[image:image-20220709165402-7.png]] 771 +| 772 +| |[[image:image-20220709165402-6.png]] 771 771 774 +| 775 +| |[[image:image-20220709165402-7.png]] 776 + 777 +| 778 +| |[[image:image-20220709165402-8.png]] 779 + 772 772 Name the thing~-~-->Click “Next” 773 773 774 -[[image:image-20220709165402-8.png]] 775 775 776 776 Select the way to create certificate 777 777 778 -[[image:image-20220709165402-9.png]] 779 779 786 +| 787 +| |[[image:image-20220709165402-9.png]] 788 + 780 780 Select policy 781 781 782 -[[image:image-20220709165402-10.png]] 783 783 784 -[[image:image-20220709165402-11.png]] 792 +| 793 +| |[[image:image-20220709165402-10.png]] 785 785 786 786 787 -=== **Test with MQTT.fx tool** === 788 788 797 + 798 + 799 + 800 +| 801 +| |[[image:image-20220709165402-11.png]] 802 + 803 + 804 + 805 +1. **Test with MQTT.fx tool** 806 + 789 789 Click “View Setting” to get the “Broker Adress” 790 790 791 -[[image:image-20220709165402-13.png]] 792 792 793 -[[image:image-20220709165402-12.png]] 810 +| 811 +| |[[image:image-20220709165402-12.png]] 794 794 795 -Create one connection in MQTT.fx tool, set broker port as 8883. 813 +| 814 +| |[[image:image-20220709165402-13.png]] 796 796 797 -[[image:image-20220709165402-14.png]] 798 798 817 + 818 + 819 + 820 +| 821 +| |[[image:image-20220709165402-14.png]] 822 + 823 +Create one connection in MQTT.fx tool, set broker port as 8883. 824 + 799 799 Upload the CA File, Client Certificate File, Client Key File 800 800 801 -[[image:image-20220709165402-15.png]] 802 802 828 +| 829 +| |[[image:image-20220709165402-15.png]] 830 + 803 803 Publish message to topic “TEST” 804 804 805 -[[image:image-20220709165402-17.png]] 806 806 807 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 834 +| 835 +| |[[image:image-20220709165402-16.png]] 808 808 809 -[[image:image-20220709173500-1.png]] 837 +| 838 +| |[[image:image-20220709165402-17.png]] 810 810 840 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 841 + 811 811 And we can also send message form AWS platform to MQTT.fx tool. 812 812 813 -[[image:image-20220709165402-18.png]] 814 814 815 -=== **Configurate in CloudTool** === 845 +| 846 +| |[[image:image-20220709165402-18.png]] 816 816 848 +1. **Configurate in CloudTool** 849 + 817 817 Copy the same setting in MQTT.fx to MQTT configuration 818 818 819 -[[image:image-20220709165402-19.png]] 820 820 853 +| 854 +| |[[image:image-20220709165402-19.png]] 855 + 821 821 Add a lua script and copy the lua demo into it. 822 822 823 -[[image:image-20220709165402-20.png]] 824 824 859 +| 860 +| |[[image:image-20220709165402-20.png]] 861 + 825 825 sprint = print 826 826 827 827 ~-~-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) ... ... @@ -1002,6 +1002,10 @@ 1002 1002 1003 1003 end 1004 1004 1042 + 1043 + 1005 1005 Get message in AWS 1006 1006 1007 -[[image:image-20220709165402-21.png]] 1046 + 1047 +| 1048 +| |[[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