Changes for page 2 Script

Last modified by Devin Chen on 2025/06/06 14:03

From version 6.1
edited by Jim(Forgotten)
on 2022/07/09 16:45
Change comment: There is no comment for this version
To version 2.1
edited by Leo
on 2022/06/16 16:07
Change comment: Renamed back-links.

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Jim
1 +XWiki.Leo
Content
... ... @@ -7,25 +7,25 @@
7 7  )))
8 8  
9 9  (% style="text-align:center" %)
10 -[[image:1624245865976-320.png||height="182" width="1000" class="img-thumbnail"]]
10 +[[image:1624245865976-320.png||class="img-thumbnail" height="182" width="1000"]]
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
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.1\.User 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 script function.WebHome]]
17 17  
18 18  == **1.2 Arithmetic** ==
19 19  
20 20  (% style="text-align:center" %)
21 -[[image:1624249623612-177.png||height="337" width="400" class="img-thumbnail"]]
21 +[[image:1624249623612-177.png||class="img-thumbnail" height="337" width="400"]]
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||height="135" width="400" class="img-thumbnail"]]
26 +[[image:1624249693457-742.png||class="img-thumbnail" height="135" width="400"]]
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||height="385" width="400" class="img-thumbnail"]]
35 +[[image:1645535936750-316.png||class="img-thumbnail" height="385" width="400"]]
36 36  
37 37  Script is as below:
38 38  
... ... @@ -66,76 +66,6 @@
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 -
139 139  = **2 V-Box connect with third part server** =
140 140  
141 141  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.
... ... @@ -256,7 +256,7 @@
256 256   sv=addr_getshort("@SV Silicone")/10,
257 257   pv=addr_getshort("@PV Silicone")/10,
258 258   product1=addr_getshort("@Product 1")/10,
259 -
189 +
260 260   product2=addr_getshort("@Product 2")/10,
261 261   product3=addr_getshort("@Product 3")/10,
262 262   product4=addr_getshort("@Product 4")/10,
... ... @@ -263,7 +263,7 @@
263 263   ice1=addr_getshort("@Ice condenser 1")/10,
264 264   ice2=addr_getshort("@Ice condenser 2")/10,
265 265   vacuum=addr_getfloat("@Vacuum")
266 -
196 +
267 267   }
268 268   local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"),
269 269   ODPC = addr_getbit("@B_25395#W0.01"),
... ... @@ -279,7 +279,7 @@
279 279   FSE=addr_getbit("@B_25395#W2.04"),
280 280   AVVSVV=addr_getbit("@B_25395#W1.12"),
281 281   ICHT=addr_getbit("@B_25395#W3.06")
282 -
212 +
283 283   }
284 284  \\ ~-~- ("@B_25395#CIO1.02")
285 285   mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
... ... @@ -441,7 +441,7 @@
441 441  3.Create product
442 442  
443 443  (% style="text-align:center" %)
444 -[[image:1624433478954-859.png||height="497" width="1100" class="img-thumbnail"]]
374 +[[image:1624433478954-859.png||class="img-thumbnail" height="497" width="1100"]]
445 445  
446 446  4.Product name,manufacturer,device type and industry,set according to your own needs.
447 447  
... ... @@ -452,7 +452,7 @@
452 452  After finishing configuration,please click "OK"
453 453  
454 454  (% style="text-align:center" %)
455 -[[image:1624433531968-337.png||height="568" width="700" class="img-thumbnail"]]
385 +[[image:1624433531968-337.png||class="img-thumbnail" height="568" width="700"]]
456 456  
457 457  5.Device
458 458  
... ... @@ -472,10 +472,10 @@
472 472  After configuration, click OK to generate a device ID and password, which will be used for device access later.
473 473  
474 474  (% style="text-align:center" %)
475 -[[image:1624436421499-613.png||height="499" width="700" class="img-thumbnail"]]
405 +[[image:1624436421499-613.png||class="img-thumbnail" height="499" width="700"]]
476 476  
477 477  (% style="text-align:center" %)
478 -[[image:1624437798012-126.png||height="366" width="500" class="img-thumbnail"]]
408 +[[image:1624437798012-126.png||class="img-thumbnail" height="366" width="500"]]
479 479  
480 480  6. Connection authentication (use MQTT.fx tool to access the IoT platform)
481 481  
... ... @@ -484,7 +484,7 @@
484 484  **[[Download>>https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Huawei/mqttClientIdGenerator-19.2.0.zip]]**
485 485  
486 486  (% style="text-align:center" %)
487 -[[image:1624437573798-815.png||height="351" width="700" class="img-thumbnail"]]
417 +[[image:1624437573798-815.png||class="img-thumbnail" height="351" width="700"]]
488 488  
489 489  (2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message
490 490  
... ... @@ -491,7 +491,7 @@
491 491  Client ID, user name, password
492 492  
493 493  (% style="text-align:center" %)
494 -[[image:1624437756866-251.png||height="405" width="700" class="img-thumbnail"]]
424 +[[image:1624437756866-251.png||class="img-thumbnail" height="405" width="700"]]
495 495  
496 496  (3) Download certificate file"North-Beijing4"
497 497  
... ... @@ -498,10 +498,10 @@
498 498  [[https:~~/~~/support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html>>https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html]]
499 499  
500 500  (% style="text-align:center" %)
501 -[[image:1624438225398-363.png||height="403" width="800" class="img-thumbnail"]]
431 +[[image:1624438225398-363.png||class="img-thumbnail" height="403" width="800"]]
502 502  
503 503  (% style="text-align:center" %)
504 -[[image:1624438260025-610.png||height="408" width="700" class="img-thumbnail"]]
434 +[[image:1624438260025-610.png||class="img-thumbnail" height="408" width="700"]]
505 505  
506 506  7.Run MQTTfx tool to connect with Huawei
507 507  
... ... @@ -510,7 +510,7 @@
510 510  (1)Click on the setting ICON
511 511  
512 512  (% style="text-align:center" %)
513 -[[image:1624438821280-974.png||height="198" width="500" class="img-thumbnail"]]
443 +[[image:1624438821280-974.png||class="img-thumbnail" height="198" width="500"]]
514 514  
515 515  (2)Fill in IIOT MQTT device access address, and configure authentication parameters.
516 516  First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface.
... ... @@ -525,7 +525,7 @@
525 525  Client ID: check step 6
526 526  
527 527  (% style="text-align:center" %)
528 -[[image:1624439672168-492.png||height="458" width="600" class="img-thumbnail"]]
458 +[[image:1624439672168-492.png||class="img-thumbnail" height="458" width="600"]]
529 529  
530 530  (3)Upload SSL certificate file,check step 6
531 531  
... ... @@ -532,15 +532,15 @@
532 532  Select folder java~-~->DigiCertGlobalRootCA.crt.pem and click OK or apply button
533 533  
534 534  (% style="text-align:center" %)
535 -[[image:1624439912938-659.png||height="458" width="600" class="img-thumbnail"]]
465 +[[image:1624439912938-659.png||class="img-thumbnail" height="458" width="600"]]
536 536  
537 537  (4)Connect and test publish and subscribe
538 538  
539 539  (% style="text-align:center" %)
540 -[[image:1624440014872-688.png||height="232" width="700" class="img-thumbnail"]]
470 +[[image:1624440014872-688.png||class="img-thumbnail" height="232" width="700"]]
541 541  
542 542  (% style="text-align:center" %)
543 -[[image:1624440026937-386.png||height="215" width="700" class="img-thumbnail"]]
473 +[[image:1624440026937-386.png||class="img-thumbnail" height="215" width="700"]]
544 544  
545 545  Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report
546 546  
... ... @@ -564,20 +564,20 @@
564 564  ②Custom model: used to display the service ID name of the configuration report.
565 565  
566 566  (% style="text-align:center" %)
567 -[[image:1624440793982-974.png||height="410" width="700" class="img-thumbnail"]]
497 +[[image:1624440793982-974.png||class="img-thumbnail" height="410" width="700"]]
568 568  
569 569  (% style="text-align:center" %)
570 -[[image:1624440883015-105.png||height="370" width="600" class="img-thumbnail"]]
500 +[[image:1624440883015-105.png||class="img-thumbnail" height="370" width="600"]]
571 571  
572 572  ③Add property, ID of monitoring point, and data format:
573 573  
574 574  (% style="text-align:center" %)
575 -[[image:1624441052296-108.png||height="477" width="600" class="img-thumbnail"]]
505 +[[image:1624441052296-108.png||class="img-thumbnail" height="477" width="600"]]
576 576  
577 577  ④After the configuration is complete, check the received data on the device
578 578  
579 579  (% style="text-align:center" %)
580 -[[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]]
510 +[[image:1624441186851-536.png||class="img-thumbnail" height="434" width="700"]]
581 581  
582 582  == **2.4 V-Box connect with Huawei platform** ==
583 583  
... ... @@ -588,7 +588,7 @@
588 588  2.configure MQTT configuration
589 589  
590 590  (% style="text-align:center" %)
591 -[[image:1624506363847-661.png||height="507" width="1000" class="img-thumbnail"]]
521 +[[image:1624506363847-661.png||class="img-thumbnail" height="507" width="1000"]]
592 592  
593 593  3.Create a script with the demo as below.
594 594  
... ... @@ -695,350 +695,11 @@
695 695  4.Download project access into V-Box to test in debug page
696 696  
697 697  (% style="text-align:center" %)
698 -[[image:1624506710354-406.png||height="658" width="1000" class="img-thumbnail"]]
628 +[[image:1624506710354-406.png||class="img-thumbnail" height="658" width="1000"]]
699 699  
700 700  (% style="text-align:center" %)
701 -[[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]]
631 +[[image:1624506666650-161.png||class="img-thumbnail" height="547" width="1000"]]
702 702  
703 703  == **2.5 V-Box connect with AWS platform** ==
704 704  
705 -=== **Log in AWS** ===
706 -
707 -Login aws account and click“Connect an IoT device”
708 -
709 -[[image:image-20220709163750-3.png]]
710 -
711 -[[image:image-20220709163750-4.png]]
712 -
713 -=== **Create policy** ===
714 -
715 -Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
716 -
717 -[[image:image-20220709163750-5.png]]
718 -
719 -Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
720 -
721 -[[image:image-20220709163750-7.png]]
722 -
723 -[[image:image-20220709163750-6.png]]
724 -
725 -{
726 -
727 - "Version": "2012-10-17",
728 -
729 - "Statement": [
730 -
731 - {
732 -
733 - "Effect": "Allow",
734 -
735 - "Action": [
736 -
737 - "iot:Connect",
738 -
739 - "iot:Publish",
740 -
741 - "iot:Subscribe",
742 -
743 - "iot:Receive",
744 -
745 - "greengrass:Discover"
746 -
747 - ],
748 -
749 - "Resource": "*"
750 -
751 - }
752 -
753 - ]
754 -
755 -}
756 -
757 -=== **Create things** ===
758 -
759 -Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
760 -
761 -[[image:image-20220709163750-8.png]]
762 -
763 -[[image:image-20220709163750-9.png]]
764 -
765 -Name the thing~-~-->Click “Next”
766 -
767 -[[image:image-20220709163750-10.png]]
768 -
769 -Select the way to create certificate
770 -
771 -[[image:image-20220709163750-11.png]]
772 -
773 -Select policy
774 -
775 -
776 -
777 -
778 -
779 -
780 -
781 -
782 -
783 -
784 -
785 -
786 -|
787 -| |[[image:image-20220709163750-13.png]]
788 -
789 -
790 -
791 -
792 -
793 -
794 -1. **Test with MQTT.fx tool**
795 -
796 -Click “View Setting” to get the “Broker Adress”
797 -
798 -
799 -|
800 -| |[[image:image-20220709163750-14.png]]
801 -
802 -|
803 -| |[[image:image-20220709163750-15.png]]
804 -
805 -
806 -
807 -
808 -
809 -
810 -
811 -
812 -|
813 -| |[[image:image-20220709163750-16.png]]
814 -
815 -Create one connection in MQTT.fx tool, set broker port as 8883.
816 -
817 -Upload the CA File, Client Certificate File, Client Key File
818 -
819 -
820 -|
821 -| |[[image:image-20220709163750-17.png]]
822 -
823 -
824 -Publish message to topic “TEST”
825 -
826 -
827 -|
828 -| |[[image:image-20220709163750-18.png]]
829 -
830 -|
831 -| |[[image:image-20220709163750-19.png]]
832 -
833 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
834 -
835 -And we can also send message form AWS platform to MQTT.fx tool.
836 -
837 -
838 -|
839 -| |[[image:image-20220709163750-20.png]]
840 -
841 -
842 -1. **Configurate in CloudTool**
843 -
844 -Copy the same setting in MQTT.fx to MQTT configuration
845 -
846 -
847 -|
848 -| |[[image:image-20220709163750-21.png]]
849 -
850 - Add a lua script and copy the lua demo into it.
851 -
852 -
853 -|
854 -| |[[image:image-20220709163750-22.png]]
855 -
856 -
857 -
858 -sprint = print
859 -
860 -~-~-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)
861 -
862 -local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
863 -
864 -~-~-publish to topics
865 -
866 -local pub_RE_TOPIC = string.format('TEST')
867 -
868 -~-~-Subscribe topics
869 -
870 -local Subscribe_RE_TOPIC1 = string.format('TEST')
871 -
872 -~-~-variable
873 -
874 -local last_time = 0
875 -
876 -~-~-Timing main function
877 -
878 -function aws.main()
879 -
880 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
881 -
882 - if g_mq then
883 -
884 - if g_mq:isconnected() then
885 -
886 - send_Data()
887 -
888 - else
889 -
890 - if os.time() - last_time > 5 then
891 -
892 - last_time = os.time()
893 -
894 - mymqtt_connect()
895 -
896 - end
897 -
898 - end
899 -
900 - else
901 -
902 - mymqtt_init()
903 -
904 - end
905 -
906 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
907 -
908 -end
909 -
910 -
911 -~-~- Initialize MQTT
912 -
913 -function mymqtt_init()
914 -
915 - sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
916 -
917 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
918 -
919 - if g_mq then
920 -
921 - g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
922 -
923 - sprint("mqtt init success")
924 -
925 - else
926 -
927 - sprint("mqtt init failed:", err)
928 -
929 - end
930 -
931 -end
932 -
933 -~-~- Connect to MQTT server
934 -
935 -function mymqtt_connect()
936 -
937 - sprint("mqtt connecting...")
938 -
939 - local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
940 -
941 - if stat == nil then
942 -
943 - sprint("mqtt connect failed:", err)
944 -
945 - return
946 -
947 - else
948 -
949 - sprint("mqtt connected")
950 -
951 - end
952 -
953 - g_mq:subscribe(TEST, 0)
954 -
955 -end
956 -
957 -~-~- Receive MQTT message callback function
958 -
959 -function mymqtt_msg_callback(topic, msg)
960 -
961 - print("topic:",topic)
962 -
963 - print("revdata:",msg)
964 -
965 - local revData = json.decode(msg)
966 -
967 - print (revData)
968 -
969 - if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
970 -
971 -if string.match(topic,Subscribe_RE_TOPIC1) then
972 -
973 - ~-~-if revData ~~= nil then
974 -
975 - for k,v in pairs (revData) do
976 -
977 - print("printing revdata after kv here")
978 -
979 - print (k,v)
980 -
981 - end
982 -
983 - print ("current state is",fanstate)
984 -
985 - ~-~-end
986 -
987 -end
988 -
989 -end
990 -
991 -end
992 -
993 -
994 -~-~-Get real-time data
995 -
996 -function getData()
997 -
998 - local jdata = {}
999 -
1000 - local addr = bns_get_alldata()
1001 -
1002 - print(json.encode(addr))
1003 -
1004 - for i,v in pairs(addr) do
1005 -
1006 - if v[2] == 1 then
1007 -
1008 - jdata[v[3]] = v[4]
1009 -
1010 - end
1011 -
1012 - end
1013 -
1014 - return jdata
1015 -
1016 -end
1017 -
1018 -~-~-send data
1019 -
1020 -function send_Data()
1021 -
1022 - local pub_data =
1023 -
1024 - {
1025 -
1026 -123
1027 -
1028 -}
1029 -
1030 -sprint(json.encode(pub_data))
1031 -
1032 -print("..........",pub_RE_TOPIC)
1033 -
1034 - return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
1035 -
1036 -end
1037 -
1038 -
1039 -
1040 -Get message in AWS
1041 -
1042 -
1043 -|
1044 -| |[[image:image-20220709163750-23.png]]
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]]