Changes for page 2 Script

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

From version 10.1
edited by Jim(Forgotten)
on 2022/07/09 16:52
Change comment: There is no comment for this version
To version 5.1
edited by Hunter
on 2022/07/08 14:11
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Jim
1 +XWiki.Hunter
Content
... ... @@ -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 -
259 +
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 -
266 +
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 -
282 +
283 283   }
284 284  \\ ~-~- ("@B_25395#CIO1.02")
285 285   mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
... ... @@ -702,326 +702,4 @@
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 -
710 -[[image:image-20220709165226-1.png]]
711 -
712 -=== **Create policy** ===
713 -
714 -Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
715 -
716 -[[image:image-20220709163750-5.png]]
717 -
718 -Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
719 -
720 -[[image:image-20220709163750-7.png]]
721 -
722 -[[image:image-20220709163750-6.png]]
723 -
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 -
756 -=== **Create things** ===
757 -
758 -Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
759 -
760 -[[image:image-20220709163750-8.png]]
761 -
762 -[[image:image-20220709163750-9.png]]
763 -
764 -Name the thing~-~-->Click “Next”
765 -
766 -[[image:image-20220709163750-10.png]]
767 -
768 -Select the way to create certificate
769 -
770 -[[image:image-20220709163750-11.png]]
771 -
772 -Select policy
773 -
774 -
775 -
776 -
777 -
778 -
779 -
780 -
781 -
782 -
783 -
784 -
785 -|
786 -| |[[image:image-20220709163750-13.png]]
787 -
788 -1. **Test with MQTT.fx tool**
789 -
790 -Click “View Setting” to get the “Broker Adress”
791 -
792 -
793 -|
794 -| |[[image:image-20220709163750-14.png]]
795 -
796 -|
797 -| |[[image:image-20220709163750-15.png]]
798 -
799 -|
800 -| |[[image:image-20220709163750-16.png]]
801 -
802 -Create one connection in MQTT.fx tool, set broker port as 8883.
803 -
804 -Upload the CA File, Client Certificate File, Client Key File
805 -
806 -
807 -|
808 -| |[[image:image-20220709163750-17.png]]
809 -
810 -Publish message to topic “TEST”
811 -
812 -
813 -|
814 -| |[[image:image-20220709163750-18.png]]
815 -
816 -|
817 -| |[[image:image-20220709163750-19.png]]
818 -
819 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
820 -
821 -And we can also send message form AWS platform to MQTT.fx tool.
822 -
823 -
824 -|
825 -| |[[image:image-20220709163750-20.png]]
826 -
827 -1. **Configurate in CloudTool**
828 -
829 -Copy the same setting in MQTT.fx to MQTT configuration
830 -
831 -
832 -|
833 -| |[[image:image-20220709163750-21.png]]
834 -
835 - Add a lua script and copy the lua demo into it.
836 -
837 -
838 -|
839 -| |[[image:image-20220709163750-22.png]]
840 -
841 -sprint = print
842 -
843 -~-~-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)
844 -
845 -local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
846 -
847 -~-~-publish to topics
848 -
849 -local pub_RE_TOPIC = string.format('TEST')
850 -
851 -~-~-Subscribe topics
852 -
853 -local Subscribe_RE_TOPIC1 = string.format('TEST')
854 -
855 -~-~-variable
856 -
857 -local last_time = 0
858 -
859 -~-~-Timing main function
860 -
861 -function aws.main()
862 -
863 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
864 -
865 - if g_mq then
866 -
867 - if g_mq:isconnected() then
868 -
869 - send_Data()
870 -
871 - else
872 -
873 - if os.time() - last_time > 5 then
874 -
875 - last_time = os.time()
876 -
877 - mymqtt_connect()
878 -
879 - end
880 -
881 - end
882 -
883 - else
884 -
885 - mymqtt_init()
886 -
887 - end
888 -
889 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
890 -
891 -end
892 -
893 -
894 -~-~- Initialize MQTT
895 -
896 -function mymqtt_init()
897 -
898 - sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
899 -
900 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
901 -
902 - if g_mq then
903 -
904 - g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
905 -
906 - sprint("mqtt init success")
907 -
908 - else
909 -
910 - sprint("mqtt init failed:", err)
911 -
912 - end
913 -
914 -end
915 -
916 -~-~- Connect to MQTT server
917 -
918 -function mymqtt_connect()
919 -
920 - sprint("mqtt connecting...")
921 -
922 - local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
923 -
924 - if stat == nil then
925 -
926 - sprint("mqtt connect failed:", err)
927 -
928 - return
929 -
930 - else
931 -
932 - sprint("mqtt connected")
933 -
934 - end
935 -
936 - g_mq:subscribe(TEST, 0)
937 -
938 -end
939 -
940 -~-~- Receive MQTT message callback function
941 -
942 -function mymqtt_msg_callback(topic, msg)
943 -
944 - print("topic:",topic)
945 -
946 - print("revdata:",msg)
947 -
948 - local revData = json.decode(msg)
949 -
950 - print (revData)
951 -
952 - if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
953 -
954 -if string.match(topic,Subscribe_RE_TOPIC1) then
955 -
956 - ~-~-if revData ~~= nil then
957 -
958 - for k,v in pairs (revData) do
959 -
960 - print("printing revdata after kv here")
961 -
962 - print (k,v)
963 -
964 - end
965 -
966 - print ("current state is",fanstate)
967 -
968 - ~-~-end
969 -
970 -end
971 -
972 -end
973 -
974 -end
975 -
976 -
977 -~-~-Get real-time data
978 -
979 -function getData()
980 -
981 - local jdata = {}
982 -
983 - local addr = bns_get_alldata()
984 -
985 - print(json.encode(addr))
986 -
987 - for i,v in pairs(addr) do
988 -
989 - if v[2] == 1 then
990 -
991 - jdata[v[3]] = v[4]
992 -
993 - end
994 -
995 - end
996 -
997 - return jdata
998 -
999 -end
1000 -
1001 -~-~-send data
1002 -
1003 -function send_Data()
1004 -
1005 - local pub_data =
1006 -
1007 - {
1008 -
1009 -123
1010 -
1011 -}
1012 -
1013 -sprint(json.encode(pub_data))
1014 -
1015 -print("..........",pub_RE_TOPIC)
1016 -
1017 - return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
1018 -
1019 -end
1020 -
1021 -
1022 -
1023 -Get message in AWS
1024 -
1025 -
1026 -|
1027 -| |[[image:image-20220709163750-23.png]]
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]]
image-20220709165226-1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -1.2 MB
Content