Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
From version 19.1
edited by Hunter
on 2022/07/29 15:56
on 2022/07/29 15:56
Change comment:
There is no comment for this version
To version 11.1
edited by Jim(Forgotten)
on 2022/07/09 17:01
on 2022/07/09 17:01
Change comment:
There is no comment for this version
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.Jim - 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 ... ... @@ -160,148 +160,144 @@ 160 160 161 161 Demo1: 162 162 163 -{{code language="lua"}} 164 --- Meta class 165 ---main 163 +(% class="box infomessage" %) 164 +((( 165 +~-~- Meta class 166 +~-~-main 166 166 function mq.main() 167 - if not mq.m then 168 - local err = "" 168 + if not mq.m then 169 + local err = "" 170 +\\ mq.m, err = mqtt.create("tcp:~/~/grouprobotinfo.com:1883", "ClienID") ~-~- create connection 171 + if mq.m then 172 + mq.config = { 173 + username = "",~-~- ID 174 + password = "",~-~- password 175 + netway = 1, ~-~- Ethernet connection, WIFI=1 176 + ~-~- keepalive = 100, ~-~- Optional, set the connection heartbeat interval for 100 seconds. 177 + ~-~- cleansession = 0, ~-~- Optional, keep session 178 + } 179 + mq.m:on("message", function(topic, msg) ~-~- Register for receiving message callbacks 180 + local str = string.format("%s:%s", topic, msg) 181 + ~-~- print("mqtt msg:", str) ~-~- Print out the received topics and content 182 + end 183 + ) 184 + mq.m:on("offline", function (cause) ~-~- Register for lost connection callbacks 185 + ~-~- addr_setstring("@xxx", "cause"..(cause or " got nil")) 186 + end) 187 + mq.m:on("arrived", function() ~-~- Registration for sending messages to callbacks 188 + print("msg arrived") 189 + end) 190 + else 191 + print("mqtt create failed:", err) ~-~- Create object failed 192 + end 193 + else 194 + if mq.m:isconnected() then ~-~- If online, post a message 195 + local phaseStatus ="unknow" 196 + if addr_getbit("@Standby")== 1 then 197 + phaseStatus = "Standby" 198 + elseif addr_getbit("@Pre-Freeze")==1 then 199 + phaseStatus= "Pre-Freeze" 200 + elseif addr_getbit("@Prepare")==1 then 201 + phaseStatus ="Prepare" 202 + elseif addr_getbit("@Primary Dry")==1 then 203 + phaseStatus = "Primary dry" 204 + elseif addr_getbit("@Secondary Dry")==1 then 205 + phaseStatus = "Secondary Dry" 206 + end 207 +~-~- print(addr_getbit("@Primary Dry")) 208 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-- 209 + local activating ="unknow" 210 + if addr_getbit("@Compressor")==1 then 211 + activating = ",".."Compressor" 212 + end 213 + if addr_getbit("@Silicone Pump")==1 then 214 + activating = activating..",".."Silicone Pump" 215 + end 216 + if addr_getbit("@Vacuum Pump")==1 then 217 + activating = activating..",".."Vacuum Pump" 218 + end 219 + if addr_getbit("@Root Pump")==1 then 220 + activating = activating..",".."Root Pump" 221 + end 222 + if addr_getbit("@Heater")==1 then 223 + activating = activating..",".."Heater" 224 + end 225 + if addr_getbit("@Valve Silicone")==1 then 226 + activating = activating..",".."Valve Silicone" 227 + end 228 + if addr_getbit("@Valve Ice Condenser")==1 then 229 + activating = activating..",".."Valve Ice Condenser" 230 + end 231 + if addr_getbit("@Valve Vacuum Pump")==1 then 232 + activating = activating..",".."Valve Vacuum Pump" 233 + end 234 + local pr_activating =string.sub(activating,2) 235 + ~-~- print(pr_activating) 169 169 170 - mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID") -- create connection 171 - if mq.m then 172 - mq.config = { 173 - username = "",-- ID 174 - password = "",-- password 175 - netway = 1, -- Ethernet connection, WIFI=1 176 - -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds. 177 - -- cleansession = 0, -- Optional, keep session 178 - } 179 - mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks 180 - local str = string.format("%s:%s", topic, msg) 181 - -- print("mqtt msg:", str) -- Print out the received topics and content 182 - end 183 - ) 184 - mq.m:on("offline", function (cause) -- Register for lost connection callbacks 185 - -- addr_setstring("@xxx", "cause"..(cause or " got nil")) 186 - end) 187 - mq.m:on("arrived", function() -- Registration for sending messages to callbacks 188 - print("msg arrived") 189 - end) 190 - else 191 - print("mqtt create failed:", err) -- Create object failed 192 - end 193 - else 194 - if mq.m:isconnected() then -- If online, post a message 195 - local phaseStatus ="unknow" 196 - if addr_getbit("@Standby")== 1 then 197 - phaseStatus = "Standby" 198 - elseif addr_getbit("@Pre-Freeze")==1 then 199 - phaseStatus= "Pre-Freeze" 200 - elseif addr_getbit("@Prepare")==1 then 201 - phaseStatus ="Prepare" 202 - elseif addr_getbit("@Primary Dry")==1 then 203 - phaseStatus = "Primary dry" 204 - elseif addr_getbit("@Secondary Dry")==1 then 205 - phaseStatus = "Secondary Dry" 206 - end 207 --- print(addr_getbit("@Primary Dry")) 208 -------------------------------------------------------------------------------------------------------------------------- 209 - local activating ="unknow" 210 - if addr_getbit("@Compressor")==1 then 211 - activating = ",".."Compressor" 212 - end 213 - if addr_getbit("@Silicone Pump")==1 then 214 - activating = activating..",".."Silicone Pump" 215 - end 216 - if addr_getbit("@Vacuum Pump")==1 then 217 - activating = activating..",".."Vacuum Pump" 218 - end 219 - if addr_getbit("@Root Pump")==1 then 220 - activating = activating..",".."Root Pump" 221 - end 222 - if addr_getbit("@Heater")==1 then 223 - activating = activating..",".."Heater" 224 - end 225 - if addr_getbit("@Valve Silicone")==1 then 226 - activating = activating..",".."Valve Silicone" 227 - end 228 - if addr_getbit("@Valve Ice Condenser")==1 then 229 - activating = activating..",".."Valve Ice Condenser" 230 - end 231 - if addr_getbit("@Valve Vacuum Pump")==1 then 232 - activating = activating..",".."Valve Vacuum Pump" 233 - end 234 - local pr_activating =string.sub(activating,2) 235 - -- print(pr_activating) 236 236 237 - 238 - 239 - local status_text ="unknow" 240 - if addr_getbit("@Status Run")==1 then 241 - status_text = "RUNNING" 242 - else 243 - status_text = "STOP" 244 - end 245 -------------------------------------------------------------------------------------------------------------------------- 246 - 247 - local js = {type="status", 248 - mc_name ="FD300", 249 - status=status_text, 250 - elapsed_time={ 251 - hour=addr_getword("@Elapsed Time (Hour)"), 252 - min=addr_getword("@Elapsed Time (Minute)"), 253 - sec=addr_getword("@Elapsed Time (Second)") 254 - }, 255 - phase = phaseStatus, 256 - step = addr_getword("@Step"), 257 - activating_output = pr_activating, 258 - sv=addr_getshort("@SV Silicone")/10, 259 - pv=addr_getshort("@PV Silicone")/10, 260 - product1=addr_getshort("@Product 1")/10, 261 - 262 - product2=addr_getshort("@Product 2")/10, 263 - product3=addr_getshort("@Product 3")/10, 264 - product4=addr_getshort("@Product 4")/10, 265 - ice1=addr_getshort("@Ice condenser 1")/10, 266 - ice2=addr_getshort("@Ice condenser 2")/10, 267 - vacuum=addr_getfloat("@Vacuum") 268 - 269 - } 270 - local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 271 - ODPC = addr_getbit("@B_25395#W0.01"), 272 - MTPC=addr_getbit("@B_25395#W0.02"), 273 - HTT = addr_getbit("@B_25395#W1.03"), 274 - CPC = addr_getbit("@B_25395#W0.08"), 275 - CPSP =addr_getbit("@B_25395#W1.00"), 276 - CPVP =addr_getbit("@B_25395#W0.10"), 277 - CPRP =addr_getbit("@B_25395#W0.11"), 278 - HP =addr_getbit("@B_25395#W1.01"), 279 - PP= addr_getbit("@B_25395#W1.02"), 280 - PO=addr_getbit("@B_25395#W0.07"), 281 - FSE=addr_getbit("@B_25395#W2.04"), 282 - AVVSVV=addr_getbit("@B_25395#W1.12"), 283 - ICHT=addr_getbit("@B_25395#W3.06") 284 - 285 - } 286 - 287 - -- ("@B_25395#CIO1.02") 288 - mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 289 - mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 290 - else 291 - local stat, err = mq.m:connect(mq.config) -- connection 292 - if stat == nil then --Determine whether to connect 293 - print("mqtt connect failed:", err) 294 - return -- Connection failed, return directly 295 - end 296 - mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics 297 - 298 - end 299 - -- mq.m:unsubscribe("stc/test") 300 - -- mq.m:disconnect() -- close matt 301 - -- mq.m:close() -- close clase 302 - end 238 + local status_text ="unknow" 239 + if addr_getbit("@Status Run")==1 then 240 + status_text = "RUNNING" 241 + else 242 + status_text = "STOP" 243 + end 244 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-- 245 +\\ local js = {type="status", 246 + mc_name ="FD300", 247 + status=status_text, 248 + elapsed_time={ 249 + hour=addr_getword("@Elapsed Time (Hour)"), 250 + min=addr_getword("@Elapsed Time (Minute)"), 251 + sec=addr_getword("@Elapsed Time (Second)") 252 + }, 253 + phase = phaseStatus, 254 + step = addr_getword("@Step"), 255 + activating_output = pr_activating, 256 + sv=addr_getshort("@SV Silicone")/10, 257 + pv=addr_getshort("@PV Silicone")/10, 258 + product1=addr_getshort("@Product 1")/10, 259 + 260 + product2=addr_getshort("@Product 2")/10, 261 + product3=addr_getshort("@Product 3")/10, 262 + product4=addr_getshort("@Product 4")/10, 263 + ice1=addr_getshort("@Ice condenser 1")/10, 264 + ice2=addr_getshort("@Ice condenser 2")/10, 265 + vacuum=addr_getfloat("@Vacuum") 266 + 267 + } 268 + local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 269 + ODPC = addr_getbit("@B_25395#W0.01"), 270 + MTPC=addr_getbit("@B_25395#W0.02"), 271 + HTT = addr_getbit("@B_25395#W1.03"), 272 + CPC = addr_getbit("@B_25395#W0.08"), 273 + CPSP =addr_getbit("@B_25395#W1.00"), 274 + CPVP =addr_getbit("@B_25395#W0.10"), 275 + CPRP =addr_getbit("@B_25395#W0.11"), 276 + HP =addr_getbit("@B_25395#W1.01"), 277 + PP= addr_getbit("@B_25395#W1.02"), 278 + PO=addr_getbit("@B_25395#W0.07"), 279 + FSE=addr_getbit("@B_25395#W2.04"), 280 + AVVSVV=addr_getbit("@B_25395#W1.12"), 281 + ICHT=addr_getbit("@B_25395#W3.06") 282 + 283 + } 284 +\\ ~-~- ("@B_25395#CIO1.02") 285 + mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 286 + mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 287 + else 288 + local stat, err = mq.m:connect(mq.config) ~-~- connection 289 + if stat == nil then ~-~-Determine whether to connect 290 + print("mqtt connect failed:", err) 291 + return ~-~- Connection failed, return directly 292 + end 293 + mq.m:subscribe("mqtt-v-box-epsilon", 0)~-~- Subscribe to topics 294 +\\ end 295 + ~-~- mq.m:unsubscribe("stc/test") 296 + ~-~- mq.m:disconnect() ~-~- close matt 297 + ~-~- mq.m:close() ~-~- close clase 298 + end 303 303 end 304 - {{/code}}300 +))) 305 305 306 306 == **2.2 V-Box connect with Azure platform** == 307 307 ... ... @@ -727,7 +727,7 @@ 727 727 728 728 [[image:image-20220709165402-4.png]] 729 729 730 -{{code language=" java"}}726 +{{code language="LUA"}} 731 731 { 732 732 733 733 "Version": "2012-10-17", ... ... @@ -761,67 +761,122 @@ 761 761 } 762 762 {{/code}} 763 763 764 - ===**Create things**===760 +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]] 765 +| 766 +| |[[image:image-20220709165402-6.png]] 771 771 768 + 769 +| 770 +| |[[image:image-20220709165402-7.png]] 771 + 772 +| 773 +| |[[image:image-20220709165402-8.png]] 774 + 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 781 +| 782 +| |[[image:image-20220709165402-9.png]] 783 + 780 780 Select policy 781 781 782 -[[image:image-20220709165402-10.png]] 783 783 784 -[[image:image-20220709165402-11.png]] 787 +| 788 +| |[[image:image-20220709165402-10.png]] 785 785 786 786 787 -=== **Test with MQTT.fx tool** === 788 788 792 + 793 + 794 + 795 + 796 + 797 + 798 + 799 +| 800 +| |[[image:image-20220709165402-11.png]] 801 + 802 + 803 + 804 + 805 + 806 + 807 + 808 +1. **Test with MQTT.fx tool** 809 + 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]] 813 +| 814 +| |[[image:image-20220709165402-12.png]] 794 794 795 -Create one connection in MQTT.fx tool, set broker port as 8883. 816 +| 817 +| |[[image:image-20220709165402-13.png]] 796 796 797 -[[image:image-20220709165402-14.png]] 798 798 820 + 821 + 822 + 823 + 824 + 825 + 826 + 827 +| 828 +| |[[image:image-20220709165402-14.png]] 829 + 830 +Create one connection in MQTT.fx tool, set broker port as 8883. 831 + 799 799 Upload the CA File, Client Certificate File, Client Key File 800 800 801 -[[image:image-20220709165402-15.png]] 802 802 835 +| 836 +| |[[image:image-20220709165402-15.png]] 837 + 838 + 839 + 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. 843 +| 844 +| |[[image:image-20220709165402-16.png]] 808 808 809 -[[image:image-20220709173500-1.png]] 846 +| 847 +| |[[image:image-20220709165402-17.png]] 810 810 849 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 850 + 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** === 854 +| 855 +| |[[image:image-20220709165402-18.png]] 816 816 857 + 858 + 859 +1. **Configurate in CloudTool** 860 + 817 817 Copy the same setting in MQTT.fx to MQTT configuration 818 818 819 -[[image:image-20220709165402-19.png]] 820 820 864 +| 865 +| |[[image:image-20220709165402-19.png]] 866 + 821 821 Add a lua script and copy the lua demo into it. 822 822 823 -[[image:image-20220709165402-20.png]] 824 824 870 +| 871 +| |[[image:image-20220709165402-20.png]] 872 + 873 + 874 + 875 + 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,12 @@ 1002 1002 1003 1003 end 1004 1004 1056 + 1057 + 1005 1005 Get message in AWS 1006 1006 1007 -[[image:image-20220709165402-21.png]] 1060 + 1061 +| 1062 +| |[[image:image-20220709165402-21.png]] 1063 + 1064 +
- image-20220709173500-1.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.Jim - Size
-
... ... @@ -1,1 +1,0 @@ 1 -1.5 MB - Content