Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
To version 7.1
edited by Jim(Forgotten)
on 2022/07/09 16:46
on 2022/07/09 16:46
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. Leo1 +XWiki.Jim - Content
-
... ... @@ -7,7 +7,7 @@ 7 7 ))) 8 8 9 9 (% style="text-align:center" %) 10 -[[image:1624245865976-320.png|| class="img-thumbnail" height="182" width="1000"]]10 +[[image:1624245865976-320.png||height="182" width="1000" class="img-thumbnail"]] 11 11 12 12 Depend on diffferent format of data.V-Box use different script functions. 13 13 for example. addr_setshort(addr,num) Function: Write 16-bit signed decimal address ... ... @@ -18,14 +18,14 @@ 18 18 == **1.2 Arithmetic** == 19 19 20 20 (% style="text-align:center" %) 21 -[[image:1624249623612-177.png|| class="img-thumbnail" height="337" width="400"]]21 +[[image:1624249623612-177.png||height="337" width="400" class="img-thumbnail"]] 22 22 23 -== **1.3 set 100 to D0~-~-D19** ==23 +== **1.3 Set 100 to D0~-~-D19** == 24 24 25 25 (% style="text-align:center" %) 26 -[[image:1624249693457-742.png|| class="img-thumbnail" height="135" width="400"]]26 +[[image:1624249693457-742.png||height="135" width="400" class="img-thumbnail"]] 27 27 28 -== **1.4 short message** ==28 +== **1.4 Short message** == 29 29 30 30 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,7 +32,7 @@ 32 32 When the alarm condition is released,then send an "alarm release" sms. 33 33 34 34 (% style="text-align:center" %) 35 -[[image:1645535936750-316.png|| class="img-thumbnail" height="385" width="400"]]35 +[[image:1645535936750-316.png||height="385" width="400" class="img-thumbnail"]] 36 36 37 37 Script is as below: 38 38 ... ... @@ -66,6 +66,76 @@ 66 66 end 67 67 ))) 68 68 69 +== **1.5 Telegram notification** == 70 + 71 +This example shows how to use the Bot API to send message into Telegram group or channel. When monitoring bit "@HDX" changes, it will trigger and send the message. Please replace with your own Token and chat id. 72 + 73 +{{code language="Lua"}} 74 +local tempBit = 0 75 +local tempWord = 0 76 + 77 +local botToken = "5504549693:AAEy6a5G-sOF3CINONxMNABeYnoS4ABVlfg" 78 +local chatID = "-641959124"--The chat id from Channel or Group 79 + 80 +local https = require("https") 81 +local json = require("json") 82 + 83 +-- Send http.get request and return response result 84 +function getHttpsUrl(url) 85 + local body = {} 86 + local bodyJson = json.encode(body) 87 + local header = {} 88 + header["content-type"] = "application/json" 89 + local result_table, code, headers, status = https.request(url, bodyJson) 90 + print("code:"..code) 91 + if code~= 200 then 92 + return 93 + else 94 + return body 95 + end 96 +end 97 + 98 +function sendAlarm(telegramBotToken, message, telegramChatID) 99 + local url = "https://api.telegram.org/bot"..telegramBotToken.."/sendMessage?text="..message.."&chat_id="..telegramChatID 100 + --local url = 'http://v-box.net' 101 + --local url = 'https://www.google.com/' 102 + print("Get the link:"..url) 103 + getHttpsUrl(url) 104 +end 105 + 106 + 107 +function AlarmNotificate.main() 108 + local bitValue = addr_getbit("@HDX"); 109 + local message = '' 110 + print("b=="..bitValue) 111 + if bitValue == 1 and bitValue ~= tempBit then 112 + message = 'Alarm triggered, the monitoring point test value is '.. bitValue 113 + sendAlarm(botToken, message, chatID) 114 + print("Notification pushed of triggering alarm,"..bitValue) 115 + elseif bitValue == 0 and bitValue ~= tempBit then 116 + message = 'Alarm dismissed, the monitoring point test value is '.. bitValue 117 + sendAlarm(botToken, message, chatID) 118 + print("Notification pushed of dismissing alarm,"..bitValue) 119 + end 120 + tempBit = bitValue----Prevent monitoring values from continuous being sent to the platform 121 + 122 + local wordValue = addr_getword("@HDW10") 123 + print("w=="..wordValue) 124 + --dosomething 125 + if wordValue >= 100 and wordValue ~= tempWord and tempWord <= 100 then 126 + message = 'Word alarm triggered, the word value is '.. wordValue 127 + sendAlarm(botToken, message, chatID) 128 + print("Notification pushed of triggering alarm,"..wordValue) 129 + elseif wordValue < 100 and wordValue ~= tempWord and tempWord >= 100 then 130 + message = 'Word alarm dismissed, the word value is '.. wordValue 131 + sendAlarm(botToken, message, chatID) 132 + print("Notification pushed of dismissing alarm,"..wordValue) 133 + end 134 + tempWord = wordValue----Prevent monitoring values from continuous being sent to the platform 135 +end 136 +{{/code}} 137 + 138 + 69 69 = **2 V-Box connect with third part server** = 70 70 71 71 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. ... ... @@ -186,7 +186,7 @@ 186 186 sv=addr_getshort("@SV Silicone")/10, 187 187 pv=addr_getshort("@PV Silicone")/10, 188 188 product1=addr_getshort("@Product 1")/10, 189 - 259 + 190 190 product2=addr_getshort("@Product 2")/10, 191 191 product3=addr_getshort("@Product 3")/10, 192 192 product4=addr_getshort("@Product 4")/10, ... ... @@ -193,7 +193,7 @@ 193 193 ice1=addr_getshort("@Ice condenser 1")/10, 194 194 ice2=addr_getshort("@Ice condenser 2")/10, 195 195 vacuum=addr_getfloat("@Vacuum") 196 - 266 + 197 197 } 198 198 local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 199 199 ODPC = addr_getbit("@B_25395#W0.01"), ... ... @@ -209,7 +209,7 @@ 209 209 FSE=addr_getbit("@B_25395#W2.04"), 210 210 AVVSVV=addr_getbit("@B_25395#W1.12"), 211 211 ICHT=addr_getbit("@B_25395#W3.06") 212 - 282 + 213 213 } 214 214 \\ ~-~- ("@B_25395#CIO1.02") 215 215 mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) ... ... @@ -371,7 +371,7 @@ 371 371 3.Create product 372 372 373 373 (% style="text-align:center" %) 374 -[[image:1624433478954-859.png|| class="img-thumbnail" height="497" width="1100"]]444 +[[image:1624433478954-859.png||height="497" width="1100" class="img-thumbnail"]] 375 375 376 376 4.Product name,manufacturer,device type and industry,set according to your own needs. 377 377 ... ... @@ -382,7 +382,7 @@ 382 382 After finishing configuration,please click "OK" 383 383 384 384 (% style="text-align:center" %) 385 -[[image:1624433531968-337.png|| class="img-thumbnail" height="568" width="700"]]455 +[[image:1624433531968-337.png||height="568" width="700" class="img-thumbnail"]] 386 386 387 387 5.Device 388 388 ... ... @@ -402,10 +402,10 @@ 402 402 After configuration, click OK to generate a device ID and password, which will be used for device access later. 403 403 404 404 (% style="text-align:center" %) 405 -[[image:1624436421499-613.png|| class="img-thumbnail" height="499" width="700"]]475 +[[image:1624436421499-613.png||height="499" width="700" class="img-thumbnail"]] 406 406 407 407 (% style="text-align:center" %) 408 -[[image:1624437798012-126.png|| class="img-thumbnail" height="366" width="500"]]478 +[[image:1624437798012-126.png||height="366" width="500" class="img-thumbnail"]] 409 409 410 410 6. Connection authentication (use MQTT.fx tool to access the IoT platform) 411 411 ... ... @@ -414,7 +414,7 @@ 414 414 **[[Download>>https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Huawei/mqttClientIdGenerator-19.2.0.zip]]** 415 415 416 416 (% style="text-align:center" %) 417 -[[image:1624437573798-815.png|| class="img-thumbnail" height="351" width="700"]]487 +[[image:1624437573798-815.png||height="351" width="700" class="img-thumbnail"]] 418 418 419 419 (2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message 420 420 ... ... @@ -421,7 +421,7 @@ 421 421 Client ID, user name, password 422 422 423 423 (% style="text-align:center" %) 424 -[[image:1624437756866-251.png|| class="img-thumbnail" height="405" width="700"]]494 +[[image:1624437756866-251.png||height="405" width="700" class="img-thumbnail"]] 425 425 426 426 (3) Download certificate file"North-Beijing4" 427 427 ... ... @@ -428,10 +428,10 @@ 428 428 [[https:~~/~~/support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html>>https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html]] 429 429 430 430 (% style="text-align:center" %) 431 -[[image:1624438225398-363.png|| class="img-thumbnail" height="403" width="800"]]501 +[[image:1624438225398-363.png||height="403" width="800" class="img-thumbnail"]] 432 432 433 433 (% style="text-align:center" %) 434 -[[image:1624438260025-610.png|| class="img-thumbnail" height="408" width="700"]]504 +[[image:1624438260025-610.png||height="408" width="700" class="img-thumbnail"]] 435 435 436 436 7.Run MQTTfx tool to connect with Huawei 437 437 ... ... @@ -440,7 +440,7 @@ 440 440 (1)Click on the setting ICON 441 441 442 442 (% style="text-align:center" %) 443 -[[image:1624438821280-974.png|| class="img-thumbnail" height="198" width="500"]]513 +[[image:1624438821280-974.png||height="198" width="500" class="img-thumbnail"]] 444 444 445 445 (2)Fill in IIOT MQTT device access address, and configure authentication parameters. 446 446 First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface. ... ... @@ -455,7 +455,7 @@ 455 455 Client ID: check step 6 456 456 457 457 (% style="text-align:center" %) 458 -[[image:1624439672168-492.png|| class="img-thumbnail" height="458" width="600"]]528 +[[image:1624439672168-492.png||height="458" width="600" class="img-thumbnail"]] 459 459 460 460 (3)Upload SSL certificate file,check step 6 461 461 ... ... @@ -462,15 +462,15 @@ 462 462 Select folder java~-~->DigiCertGlobalRootCA.crt.pem and click OK or apply button 463 463 464 464 (% style="text-align:center" %) 465 -[[image:1624439912938-659.png|| class="img-thumbnail" height="458" width="600"]]535 +[[image:1624439912938-659.png||height="458" width="600" class="img-thumbnail"]] 466 466 467 467 (4)Connect and test publish and subscribe 468 468 469 469 (% style="text-align:center" %) 470 -[[image:1624440014872-688.png|| class="img-thumbnail" height="232" width="700"]]540 +[[image:1624440014872-688.png||height="232" width="700" class="img-thumbnail"]] 471 471 472 472 (% style="text-align:center" %) 473 -[[image:1624440026937-386.png|| class="img-thumbnail" height="215" width="700"]]543 +[[image:1624440026937-386.png||height="215" width="700" class="img-thumbnail"]] 474 474 475 475 Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report 476 476 ... ... @@ -494,20 +494,20 @@ 494 494 ②Custom model: used to display the service ID name of the configuration report. 495 495 496 496 (% style="text-align:center" %) 497 -[[image:1624440793982-974.png|| class="img-thumbnail" height="410" width="700"]]567 +[[image:1624440793982-974.png||height="410" width="700" class="img-thumbnail"]] 498 498 499 499 (% style="text-align:center" %) 500 -[[image:1624440883015-105.png|| class="img-thumbnail" height="370" width="600"]]570 +[[image:1624440883015-105.png||height="370" width="600" class="img-thumbnail"]] 501 501 502 502 ③Add property, ID of monitoring point, and data format: 503 503 504 504 (% style="text-align:center" %) 505 -[[image:1624441052296-108.png|| class="img-thumbnail" height="477" width="600"]]575 +[[image:1624441052296-108.png||height="477" width="600" class="img-thumbnail"]] 506 506 507 507 ④After the configuration is complete, check the received data on the device 508 508 509 509 (% style="text-align:center" %) 510 -[[image:1624441186851-536.png|| class="img-thumbnail" height="434" width="700"]]580 +[[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]] 511 511 512 512 == **2.4 V-Box connect with Huawei platform** == 513 513 ... ... @@ -518,7 +518,7 @@ 518 518 2.configure MQTT configuration 519 519 520 520 (% style="text-align:center" %) 521 -[[image:1624506363847-661.png|| class="img-thumbnail" height="507" width="1000"]]591 +[[image:1624506363847-661.png||height="507" width="1000" class="img-thumbnail"]] 522 522 523 523 3.Create a script with the demo as below. 524 524 ... ... @@ -625,11 +625,341 @@ 625 625 4.Download project access into V-Box to test in debug page 626 626 627 627 (% style="text-align:center" %) 628 -[[image:1624506710354-406.png|| class="img-thumbnail" height="658" width="1000"]]698 +[[image:1624506710354-406.png||height="658" width="1000" class="img-thumbnail"]] 629 629 630 630 (% style="text-align:center" %) 631 -[[image:1624506666650-161.png|| class="img-thumbnail" height="547" width="1000"]]701 +[[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]] 632 632 633 633 == **2.5 V-Box connect with AWS platform** == 634 634 635 -[[https:~~/~~/ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/AWS/AWS.zip>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/AWS/AWS.zip]] 705 +=== **Log in AWS** === 706 + 707 +Login aws account and click“Connect an IoT device” 708 + 709 +[[image:image-20220709164650-1.png]] 710 + 711 + 712 +[[image:image-20220709163750-4.png]] 713 + 714 +=== **Create policy** === 715 + 716 +Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create” 717 + 718 +[[image:image-20220709163750-5.png]] 719 + 720 +Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create” 721 + 722 +[[image:image-20220709163750-7.png]] 723 + 724 +[[image:image-20220709163750-6.png]] 725 + 726 +{ 727 + 728 + "Version": "2012-10-17", 729 + 730 + "Statement": [ 731 + 732 + { 733 + 734 + "Effect": "Allow", 735 + 736 + "Action": [ 737 + 738 + "iot:Connect", 739 + 740 + "iot:Publish", 741 + 742 + "iot:Subscribe", 743 + 744 + "iot:Receive", 745 + 746 + "greengrass:Discover" 747 + 748 + ], 749 + 750 + "Resource": "*" 751 + 752 + } 753 + 754 + ] 755 + 756 +} 757 + 758 +=== **Create things** === 759 + 760 +Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing” 761 + 762 +[[image:image-20220709163750-8.png]] 763 + 764 +[[image:image-20220709163750-9.png]] 765 + 766 +Name the thing~-~-->Click “Next” 767 + 768 +[[image:image-20220709163750-10.png]] 769 + 770 +Select the way to create certificate 771 + 772 +[[image:image-20220709163750-11.png]] 773 + 774 +Select policy 775 + 776 + 777 + 778 + 779 + 780 + 781 + 782 + 783 + 784 + 785 + 786 + 787 +| 788 +| |[[image:image-20220709163750-13.png]] 789 + 790 + 791 + 792 +1. **Test with MQTT.fx tool** 793 + 794 +Click “View Setting” to get the “Broker Adress” 795 + 796 + 797 +| 798 +| |[[image:image-20220709163750-14.png]] 799 + 800 +| 801 +| |[[image:image-20220709163750-15.png]] 802 + 803 + 804 + 805 + 806 + 807 +| 808 +| |[[image:image-20220709163750-16.png]] 809 + 810 +Create one connection in MQTT.fx tool, set broker port as 8883. 811 + 812 +Upload the CA File, Client Certificate File, Client Key File 813 + 814 + 815 +| 816 +| |[[image:image-20220709163750-17.png]] 817 + 818 +Publish message to topic “TEST” 819 + 820 + 821 +| 822 +| |[[image:image-20220709163750-18.png]] 823 + 824 +| 825 +| |[[image:image-20220709163750-19.png]] 826 + 827 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 828 + 829 +And we can also send message form AWS platform to MQTT.fx tool. 830 + 831 + 832 +| 833 +| |[[image:image-20220709163750-20.png]] 834 + 835 +1. **Configurate in CloudTool** 836 + 837 +Copy the same setting in MQTT.fx to MQTT configuration 838 + 839 + 840 +| 841 +| |[[image:image-20220709163750-21.png]] 842 + 843 + Add a lua script and copy the lua demo into it. 844 + 845 + 846 +| 847 +| |[[image:image-20220709163750-22.png]] 848 + 849 +sprint = print 850 + 851 +~-~-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) 852 + 853 +local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg() 854 + 855 +~-~-publish to topics 856 + 857 +local pub_RE_TOPIC = string.format('TEST') 858 + 859 +~-~-Subscribe topics 860 + 861 +local Subscribe_RE_TOPIC1 = string.format('TEST') 862 + 863 +~-~-variable 864 + 865 +local last_time = 0 866 + 867 +~-~-Timing main function 868 + 869 +function aws.main() 870 + 871 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start") 872 + 873 + if g_mq then 874 + 875 + if g_mq:isconnected() then 876 + 877 + send_Data() 878 + 879 + else 880 + 881 + if os.time() - last_time > 5 then 882 + 883 + last_time = os.time() 884 + 885 + mymqtt_connect() 886 + 887 + end 888 + 889 + end 890 + 891 + else 892 + 893 + mymqtt_init() 894 + 895 + end 896 + 897 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end") 898 + 899 +end 900 + 901 + 902 +~-~- Initialize MQTT 903 + 904 +function mymqtt_init() 905 + 906 + sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID)) 907 + 908 + g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable 909 + 910 + if g_mq then 911 + 912 + g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks 913 + 914 + sprint("mqtt init success") 915 + 916 + else 917 + 918 + sprint("mqtt init failed:", err) 919 + 920 + end 921 + 922 +end 923 + 924 +~-~- Connect to MQTT server 925 + 926 +function mymqtt_connect() 927 + 928 + sprint("mqtt connecting...") 929 + 930 + local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART) 931 + 932 + if stat == nil then 933 + 934 + sprint("mqtt connect failed:", err) 935 + 936 + return 937 + 938 + else 939 + 940 + sprint("mqtt connected") 941 + 942 + end 943 + 944 + g_mq:subscribe(TEST, 0) 945 + 946 +end 947 + 948 +~-~- Receive MQTT message callback function 949 + 950 +function mymqtt_msg_callback(topic, msg) 951 + 952 + print("topic:",topic) 953 + 954 + print("revdata:",msg) 955 + 956 + local revData = json.decode(msg) 957 + 958 + print (revData) 959 + 960 + if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud 961 + 962 +if string.match(topic,Subscribe_RE_TOPIC1) then 963 + 964 + ~-~-if revData ~~= nil then 965 + 966 + for k,v in pairs (revData) do 967 + 968 + print("printing revdata after kv here") 969 + 970 + print (k,v) 971 + 972 + end 973 + 974 + print ("current state is",fanstate) 975 + 976 + ~-~-end 977 + 978 +end 979 + 980 +end 981 + 982 +end 983 + 984 + 985 +~-~-Get real-time data 986 + 987 +function getData() 988 + 989 + local jdata = {} 990 + 991 + local addr = bns_get_alldata() 992 + 993 + print(json.encode(addr)) 994 + 995 + for i,v in pairs(addr) do 996 + 997 + if v[2] == 1 then 998 + 999 + jdata[v[3]] = v[4] 1000 + 1001 + end 1002 + 1003 + end 1004 + 1005 + return jdata 1006 + 1007 +end 1008 + 1009 +~-~-send data 1010 + 1011 +function send_Data() 1012 + 1013 + local pub_data = 1014 + 1015 + { 1016 + 1017 +123 1018 + 1019 +} 1020 + 1021 +sprint(json.encode(pub_data)) 1022 + 1023 +print("..........",pub_RE_TOPIC) 1024 + 1025 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0) 1026 + 1027 +end 1028 + 1029 + 1030 + 1031 +Get message in AWS 1032 + 1033 + 1034 +| 1035 +| |[[image:image-20220709163750-23.png]]