Changes for page 2 Script

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

From version 5.1
edited by Hunter
on 2022/07/08 14:11
Change comment: There is no comment for this version
To version 18.1
edited by Stone Wu
on 2022/07/25 11:32
Change comment: Renamed back-links.

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Hunter
1 +XWiki.Stone
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.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.04 Lua Script.01 Lua Functions.WebHome]]
17 17  
18 18  == **1.2 Arithmetic** ==
19 19  
... ... @@ -256,15 +256,13 @@
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 -
260 - product2=addr_getshort("@Product 2")/10,
259 +\\ product2=addr_getshort("@Product 2")/10,
261 261   product3=addr_getshort("@Product 3")/10,
262 262   product4=addr_getshort("@Product 4")/10,
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 -
267 - }
265 +\\ }
268 268   local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"),
269 269   ODPC = addr_getbit("@B_25395#W0.01"),
270 270   MTPC=addr_getbit("@B_25395#W0.02"),
... ... @@ -279,8 +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 -
283 - }
280 +\\ }
284 284  \\ ~-~- ("@B_25395#CIO1.02")
285 285   mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
286 286   mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
... ... @@ -702,4 +702,302 @@
702 702  
703 703  == **2.5 V-Box connect with AWS platform** ==
704 704  
705 -[[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]]
702 +=== **Log in AWS** ===
703 +
704 +Login aws account and click“Connect an IoT device”
705 +
706 +[[image:image-20220709165402-1.png]]
707 +
708 +[[image:image-20220709165402-2.png]]
709 +
710 +
711 +=== **Create policy** ===
712 +
713 +Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
714 +
715 +[[image:image-20220709165402-3.png]]
716 +
717 +Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
718 +
719 +[[image:image-20220709165402-5.png]]
720 +
721 +[[image:image-20220709165402-4.png]]
722 +
723 +{{code language="java"}}
724 +{
725 +
726 +  "Version": "2012-10-17",
727 +
728 +  "Statement": [
729 +
730 +    {
731 +
732 +      "Effect": "Allow",
733 +
734 +      "Action": [
735 +
736 +        "iot:Connect",
737 +
738 +        "iot:Publish",
739 +
740 +        "iot:Subscribe",
741 +
742 +        "iot:Receive",
743 +
744 +        "greengrass:Discover"
745 +
746 +      ],
747 +
748 +      "Resource": "*"
749 +
750 +    }
751 +
752 +  ]
753 +
754 +}
755 +{{/code}}
756 +
757 +=== **Create things** ===
758 +
759 +Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
760 +
761 +[[image:image-20220709165402-6.png]]
762 +
763 +[[image:image-20220709165402-7.png]]
764 +
765 +Name the thing~-~-->Click “Next”
766 +
767 +[[image:image-20220709165402-8.png]]
768 +
769 +Select the way to create certificate
770 +
771 +[[image:image-20220709165402-9.png]]
772 +
773 +Select policy
774 +
775 +[[image:image-20220709165402-10.png]]
776 +
777 +[[image:image-20220709165402-11.png]]
778 +
779 +
780 +=== **Test with MQTT.fx tool** ===
781 +
782 +Click “View Setting” to get the “Broker Adress”
783 +
784 +[[image:image-20220709165402-13.png]]
785 +
786 +[[image:image-20220709165402-12.png]]
787 +
788 +Create one connection in MQTT.fx tool, set broker port as 8883.
789 +
790 +[[image:image-20220709165402-14.png]]
791 +
792 +Upload the CA File, Client Certificate File, Client Key File
793 +
794 +[[image:image-20220709165402-15.png]]
795 +
796 +Publish message to topic “TEST”
797 +
798 +[[image:image-20220709165402-17.png]]
799 +
800 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
801 +
802 +[[image:image-20220709173500-1.png]]
803 +
804 +And we can also send message form AWS platform to MQTT.fx tool.
805 +
806 +[[image:image-20220709165402-18.png]]
807 +
808 +=== **Configurate in CloudTool** ===
809 +
810 +Copy the same setting in MQTT.fx to MQTT configuration
811 +
812 +[[image:image-20220709165402-19.png]]
813 +
814 + Add a lua script and copy the lua demo into it.
815 +
816 +[[image:image-20220709165402-20.png]]
817 +
818 +sprint = print
819 +
820 +~-~-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)
821 +
822 +local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
823 +
824 +~-~-publish to topics
825 +
826 +local pub_RE_TOPIC = string.format('TEST')
827 +
828 +~-~-Subscribe topics
829 +
830 +local Subscribe_RE_TOPIC1 = string.format('TEST')
831 +
832 +~-~-variable
833 +
834 +local last_time = 0
835 +
836 +~-~-Timing main function
837 +
838 +function aws.main()
839 +
840 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
841 +
842 + if g_mq then
843 +
844 + if g_mq:isconnected() then
845 +
846 + send_Data()
847 +
848 + else
849 +
850 + if os.time() - last_time > 5 then
851 +
852 + last_time = os.time()
853 +
854 + mymqtt_connect()
855 +
856 + end
857 +
858 + end
859 +
860 + else
861 +
862 + mymqtt_init()
863 +
864 + end
865 +
866 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
867 +
868 +end
869 +
870 +
871 +~-~- Initialize MQTT
872 +
873 +function mymqtt_init()
874 +
875 + sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
876 +
877 + g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
878 +
879 + if g_mq then
880 +
881 + g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
882 +
883 + sprint("mqtt init success")
884 +
885 + else
886 +
887 + sprint("mqtt init failed:", err)
888 +
889 + end
890 +
891 +end
892 +
893 +~-~- Connect to MQTT server
894 +
895 +function mymqtt_connect()
896 +
897 + sprint("mqtt connecting...")
898 +
899 + local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
900 +
901 + if stat == nil then
902 +
903 + sprint("mqtt connect failed:", err)
904 +
905 + return
906 +
907 + else
908 +
909 + sprint("mqtt connected")
910 +
911 + end
912 +
913 + g_mq:subscribe(TEST, 0)
914 +
915 +end
916 +
917 +~-~- Receive MQTT message callback function
918 +
919 +function mymqtt_msg_callback(topic, msg)
920 +
921 + print("topic:",topic)
922 +
923 + print("revdata:",msg)
924 +
925 + local revData = json.decode(msg)
926 +
927 + print (revData)
928 +
929 + if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
930 +
931 +if string.match(topic,Subscribe_RE_TOPIC1) then
932 +
933 + ~-~-if revData ~~= nil then
934 +
935 + for k,v in pairs (revData) do
936 +
937 + print("printing revdata after kv here")
938 +
939 + print (k,v)
940 +
941 + end
942 +
943 + print ("current state is",fanstate)
944 +
945 + ~-~-end
946 +
947 +end
948 +
949 +end
950 +
951 +end
952 +
953 +
954 +~-~-Get real-time data
955 +
956 +function getData()
957 +
958 + local jdata = {}
959 +
960 + local addr = bns_get_alldata()
961 +
962 + print(json.encode(addr))
963 +
964 + for i,v in pairs(addr) do
965 +
966 + if v[2] == 1 then
967 +
968 + jdata[v[3]] = v[4]
969 +
970 + end
971 +
972 + end
973 +
974 + return jdata
975 +
976 +end
977 +
978 +~-~-send data
979 +
980 +function send_Data()
981 +
982 + local pub_data =
983 +
984 + {
985 +
986 +123
987 +
988 +}
989 +
990 +sprint(json.encode(pub_data))
991 +
992 +print("..........",pub_RE_TOPIC)
993 +
994 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
995 +
996 +end
997 +
998 +Get message in AWS
999 +
1000 +[[image:image-20220709165402-21.png]]
image-20220709165226-1.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +1.2 MB
Content
image-20220709165402-1.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +200.2 KB
Content
image-20220709165402-10.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +19.0 KB
Content
image-20220709165402-11.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +105.9 KB
Content
image-20220709165402-12.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +29.0 KB
Content
image-20220709165402-13.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +158.8 KB
Content
image-20220709165402-14.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +48.1 KB
Content
image-20220709165402-15.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +46.9 KB
Content
image-20220709165402-16.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +140.7 KB
Content
image-20220709165402-17.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +12.5 KB
Content
image-20220709165402-18.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +32.2 KB
Content
image-20220709165402-19.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +66.6 KB
Content
image-20220709165402-2.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +188.5 KB
Content
image-20220709165402-20.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +33.3 KB
Content
image-20220709165402-21.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +124.8 KB
Content
image-20220709165402-3.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +103.9 KB
Content
image-20220709165402-4.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +4.0 KB
Content
image-20220709165402-5.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +66.5 KB
Content
image-20220709165402-6.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +110.0 KB
Content
image-20220709165402-7.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +25.4 KB
Content
image-20220709165402-8.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +64.2 KB
Content
image-20220709165402-9.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +37.5 KB
Content
image-20220709173500-1.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.Jim
Size
... ... @@ -1,0 +1,1 @@
1 +1.5 MB
Content