Changes for page 2 Script

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

From version 22.1
edited by Hunter
on 2022/09/08 18:57
Change comment: There is no comment for this version
To version 4.1
edited by Leo
on 2022/06/16 17:20
Change comment: Renamed back-links.

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Hunter
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.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 Functions.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,154 +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 -== **1.6 LINE Notify** ==
139 -
140 -This example shows how to use the LINE Notify to send message into LINE group. When monitoring bit "@test" changes, it will trigger and send the message. Please replace with your own Token.
141 -
142 -{{code}}
143 -local tempBit = 0
144 -local tempWord = 0
145 -
146 -local LineToken = "08XCpubkOdwGdGgRTXF0x8umiyrALtoM0v6lBFUV6PC"
147 -
148 -local https = require("https")
149 -local json = require("json")
150 -local ltn12 = require("ltn12")
151 -
152 --- Send http.get request and return response result
153 -function getHttpsUrl(url,header,reqbody)
154 - local body = {}
155 - local bodyJson = json.encode(body)
156 - local result_table, code, headers, status = https.request{
157 - method = "POST",
158 - url = url,
159 - source = ltn12.source.string(reqbody),
160 - headers = header,
161 - sink = ltn12.sink.table(body)
162 - }
163 - print("code:"..code)
164 - if code~= 200 then
165 - return
166 - else
167 - return body
168 - end
169 -end
170 -
171 -function getMessageUrl(lineMessage)
172 - local url = "https://notify-api.line.me/api/notify"
173 - local reqMess = "message="..lineMessage
174 - local headers =
175 - {
176 - ["Authorization"] = "Bearer "..LineToken,
177 - ["Content-Type"] = "application/x-www-form-urlencoded",
178 - ["Content-Length"] = #reqMess
179 - }
180 -
181 - print("Get the link:"..url)
182 - getHttpsUrl(url, headers, reqMess)
183 -end
184 -
185 -
186 -function linenotify.main()
187 - local bitValue = addr_getbit("@test");
188 - local message = ''
189 - print("b=="..bitValue)
190 - if bitValue == 1 and bitValue ~= tempBit then
191 - message = 'Alarm V-Box triggered, the output is '.. bitValue
192 - getMessageUrl(message)
193 - print("Notification pushed of triggering alarm,"..bitValue)
194 - elseif bitValue == 0 and bitValue ~= tempBit then
195 - message = 'Alarm V-Box dismissed, the output is '.. bitValue
196 - getMessageUrl(message)
197 - print("Notification pushed of dismissing alarm,"..bitValue)
198 - end
199 - tempBit = bitValue----Prevent monitoring values from continuous being sent to the platform
200 -
201 - local wordValue = addr_getword("@t2")
202 - print("w=="..wordValue)
203 - --dosomething
204 - if wordValue >= 100 and wordValue ~= tempWord and tempWord <= 100 then
205 - message = 'Alarm V-Box triggered, the temperature is '.. wordValue
206 - getMessageUrl(message)
207 - print("Notification pushed of triggering alarm,"..wordValue)
208 - elseif wordValue < 100 and wordValue ~= tempWord and tempWord >= 100 then
209 - message = 'Alarm V-Box dismissed, the temperature is '.. wordValue
210 - getMessageUrl(message)
211 - print("Notification pushed of dismissing alarm,"..wordValue)
212 - end
213 - tempWord = wordValue----Prevent monitoring values from continuous being sent to the platform
214 -end
215 -{{/code}}
216 -
217 217  = **2 V-Box connect with third part server** =
218 218  
219 219  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.
... ... @@ -232,280 +232,152 @@
232 232  
233 233  (% class="mark" %)2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate
234 234  
235 -(% class="wikigeneratedid" %)
236 -**✎Note: **Before program the script of MQTT, please make sure the server(MQTT broker) can be connected through MQTT Client tool.
87 +== **2.1 V-Box connect with customer server:grouprobotinfo.com** ==
237 237  
238 -(% class="wikigeneratedid" %)
239 -Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]**
240 -
241 -== **2.1 V-Box connect with test server(General Example)** ==
242 -
243 -{{code language="lua"}}
244 ---MQTT configuration table
245 -local MQTT_CFG={}
246 -MQTT_CFG.username = "weconsupport"
247 -MQTT_CFG.password = "123456"
248 -MQTT_CFG.netway = 0
249 -MQTT_CFG.keepalive = 60
250 -MQTT_CFG.cleansession = 1
251 ---TCP URL
252 -MQTT_URL = "tcp://mq.tongxinmao.com:1883"
253 ---Client ID
254 -MQTT_CLIENT_ID = "V-BOXH-AG"
255 -
256 ---Generate UUID
257 -function uuid()
258 - local seed = {'e','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}
259 - local tb = {}
260 - for i=1, 32 do
261 - table.insert(tb, seed[math.random(1,16)])
262 - end
263 - local sid=table.concat(tb)
264 - return string.format('%s',
265 - string.sub(sid,1,32)
266 - )
267 -end
268 -
269 -
270 ---Topic name to subscribed
271 -local SUBSCRIBE_TOPIC = 'testtopic/test/no1/123456'
272 -
273 ---Topic name to be published
274 -local PUBLISH_TOPIC = 'testtopic/test/no1/7890'
275 -
276 -
277 ---real time
278 -local LAST_TIME = 0
279 -
280 -
281 ---initialize mqtt
282 -function mqtt_init()
283 - print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID))
284 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable
285 - if g_mq then
286 - g_mq:on("message", mqtt_msg_callback) -- Register a callback for receiving messages
287 - print("mqtt init success")
288 - else
289 - print("mqtt init failed:", err)
290 - end
291 -end
292 -
293 --- connect to mqtt
294 -function mqtt_connect()
295 - print("mqtt connecting...")
296 - local stat, err = g_mq:connect(MQTT_CFG)
297 - if stat == nil then
298 - print("mqtt connect failed:", err)
299 - return
300 - else
301 - print("mqtt connected")
302 - end
303 - g_mq:subscribe(SUBSCRIBE_TOPIC, 0)
304 -end
305 -
306 --- Received message callback function
307 -function mqtt_msg_callback(topic, msg)
308 - print("topic:", topic)
309 - print("msg:", msg)
310 - local objMsg = json.decode(msg)
311 - local water = objMsg.data.waterlevel
312 - local temp = objMsg.data.temperature
313 - addr_setword("@HDW20",water)
314 - addr_setword("@HDW10",temp)
315 -end
316 -
317 ---Send data (data upload to platform and encapsulate it with custom functions)
318 -function send_data()
319 - local pub_data = {
320 - timestamp = os.time(),
321 - messageId = 1,
322 - event = 'test_data',
323 - mfrs = 'V-Box',
324 - data = {
325 - id = uuid(),
326 - waterlevel = addr_getword("@HDW10"),
327 - temperature = addr_getword("@HDW20")
328 - }
329 - }
330 - return g_mq:publish(PUBLISH_TOPIC, json.encode(pub_data), 0, 0)
331 -end
332 -
333 -
334 ---main function fixed timed execution
335 -function MQTT.main()
336 - --dosomething
337 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main start")
338 - --determine the mqtt object whether exist
339 - if g_mq then
340 - --determine the mqtt object whether has been connected or not
341 - if g_mq:isconnected() then
342 - send_data()
343 - else
344 - --if exceed 20 sec not connect, reconnect once
345 - if os.time() - LAST_TIME > 20 then
346 - LAST_TIME = os.time()
347 - --connect to mqtt or reconnect
348 - mqtt_connect()
349 - end
350 - end
351 - else
352 - --mqtt object does not exist so create new one
353 - mqtt_init()
354 - end
355 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main end")
356 -end
357 -{{/code}}
358 -
359 -== **2.2 V-Box connect with customer server:grouprobotinfo.com** ==
360 -
361 361  This demo does not use SSL certification. Script is as below
362 362  
363 363  Demo1:
364 364  
365 -{{code language="lua"}}
366 --- Meta class
367 ---main
93 +(% class="box infomessage" %)
94 +(((
95 +~-~- Meta class
96 +~-~-main
368 368  function mq.main()
369 - if not mq.m then
370 -  local err = ""
98 + if not mq.m then
99 + local err = ""
100 +\\ mq.m, err = mqtt.create("tcp:~/~/grouprobotinfo.com:1883", "ClienID") ~-~- create connection
101 + if mq.m then
102 + mq.config = {
103 + username = "",~-~- ID
104 + password = "",~-~- password
105 + netway = 1, ~-~- Ethernet connection, WIFI=1
106 + ~-~- keepalive = 100, ~-~- Optional, set the connection heartbeat interval for 100 seconds.
107 + ~-~- cleansession = 0, ~-~- Optional, keep session
108 + }
109 + mq.m:on("message", function(topic, msg) ~-~- Register for receiving message callbacks
110 + local str = string.format("%s:%s", topic, msg)
111 + ~-~- print("mqtt msg:", str) ~-~- Print out the received topics and content
112 + end
113 + )
114 + mq.m:on("offline", function (cause) ~-~- Register for lost connection callbacks
115 + ~-~- addr_setstring("@xxx", "cause"..(cause or " got nil"))
116 + end)
117 + mq.m:on("arrived", function() ~-~- Registration for sending messages to callbacks 
118 + print("msg arrived")
119 + end)
120 + else
121 + print("mqtt create failed:", err) ~-~- Create object failed
122 + end
123 + else
124 + if mq.m:isconnected() then ~-~- If online, post a message
125 + local phaseStatus ="unknow"
126 + if addr_getbit("@Standby")== 1 then
127 + phaseStatus = "Standby"
128 + elseif addr_getbit("@Pre-Freeze")==1 then
129 + phaseStatus= "Pre-Freeze"
130 + elseif addr_getbit("@Prepare")==1 then
131 + phaseStatus ="Prepare"
132 + elseif addr_getbit("@Primary Dry")==1 then
133 + phaseStatus = "Primary dry"
134 + elseif addr_getbit("@Secondary Dry")==1 then
135 + phaseStatus = "Secondary Dry"
136 + end
137 +~-~- print(addr_getbit("@Primary Dry"))
138 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--
139 + local activating ="unknow"
140 + if addr_getbit("@Compressor")==1 then
141 + activating = ",".."Compressor"
142 + end
143 + if addr_getbit("@Silicone Pump")==1 then
144 + activating = activating..",".."Silicone Pump"
145 + end
146 + if addr_getbit("@Vacuum Pump")==1 then
147 + activating = activating..",".."Vacuum Pump"
148 + end
149 + if addr_getbit("@Root Pump")==1 then
150 + activating = activating..",".."Root Pump"
151 + end
152 + if addr_getbit("@Heater")==1 then
153 + activating = activating..",".."Heater"
154 + end
155 + if addr_getbit("@Valve Silicone")==1 then
156 + activating = activating..",".."Valve Silicone"
157 + end
158 + if addr_getbit("@Valve Ice Condenser")==1 then
159 + activating = activating..",".."Valve Ice Condenser"
160 + end
161 + if addr_getbit("@Valve Vacuum Pump")==1 then
162 + activating = activating..",".."Valve Vacuum Pump"
163 + end
164 + local pr_activating =string.sub(activating,2)
165 + ~-~- print(pr_activating) 
371 371  
372 -  mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID")  -- create connection
373 -  if mq.m then
374 -   mq.config = {
375 -    username = "",-- ID
376 -    password = "",-- password
377 -    netway = 1, -- Ethernet connection, WIFI=1
378 -    -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds.
379 -    -- cleansession = 0, -- Optional, keep session
380 -   }
381 -   mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks
382 -    local str = string.format("%s:%s", topic, msg)
383 -    -- print("mqtt msg:", str) -- Print out the received topics and content
384 -   end
385 -   )
386 -   mq.m:on("offline", function (cause) -- Register for lost connection callbacks
387 -    -- addr_setstring("@xxx", "cause"..(cause or " got nil"))
388 -   end)
389 -   mq.m:on("arrived", function() -- Registration for sending messages to callbacks 
390 -    print("msg arrived")
391 -   end)
392 -  else
393 -   print("mqtt create failed:", err) -- Create object failed
394 -  end
395 - else
396 -  if mq.m:isconnected() then -- If online, post a message
397 -     local phaseStatus ="unknow"
398 -     if addr_getbit("@Standby")== 1 then
399 -         phaseStatus = "Standby"
400 -     elseif addr_getbit("@Pre-Freeze")==1 then
401 -         phaseStatus= "Pre-Freeze"
402 -     elseif addr_getbit("@Prepare")==1 then
403 -         phaseStatus ="Prepare"
404 -     elseif addr_getbit("@Primary Dry")==1 then
405 -         phaseStatus = "Primary dry"
406 -     elseif addr_getbit("@Secondary Dry")==1 then
407 -         phaseStatus = "Secondary Dry"
408 -     end
409 ---   print(addr_getbit("@Primary Dry"))
410 --------------------------------------------------------------------------------------------------------------------------
411 -     local activating ="unknow"
412 -     if addr_getbit("@Compressor")==1 then
413 -         activating = ",".."Compressor"
414 -     end
415 -     if addr_getbit("@Silicone Pump")==1 then
416 -         activating = activating..",".."Silicone Pump"
417 -     end
418 -     if addr_getbit("@Vacuum Pump")==1 then
419 -         activating = activating..",".."Vacuum Pump"
420 -     end
421 -     if addr_getbit("@Root Pump")==1 then
422 -         activating = activating..",".."Root Pump"
423 -     end
424 -     if addr_getbit("@Heater")==1 then
425 -         activating = activating..",".."Heater"
426 -     end
427 -     if addr_getbit("@Valve Silicone")==1 then
428 -         activating = activating..",".."Valve Silicone"
429 -     end
430 -     if addr_getbit("@Valve Ice Condenser")==1 then
431 -         activating = activating..",".."Valve Ice Condenser"
432 -     end
433 -     if addr_getbit("@Valve Vacuum Pump")==1 then
434 -         activating = activating..",".."Valve Vacuum Pump"
435 -     end
436 -     local pr_activating =string.sub(activating,2)
437 -    --  print(pr_activating)  
438 438  
439 -
440 -
441 -     local status_text ="unknow"
442 -     if addr_getbit("@Status Run")==1 then
443 -         status_text = "RUNNING"
444 -     else
445 -         status_text = "STOP"
446 -     end
447 --------------------------------------------------------------------------------------------------------------------------      
448 -
449 -     local js =  {type="status",
450 -                  mc_name ="FD300",
451 -                  status=status_text,
452 -                  elapsed_time={
453 -                                hour=addr_getword("@Elapsed Time (Hour)"),
454 -                                min=addr_getword("@Elapsed Time (Minute)"),
455 -                                sec=addr_getword("@Elapsed Time (Second)")
456 -                                },
457 -                   phase = phaseStatus,
458 -                   step = addr_getword("@Step"),
459 -                   activating_output = pr_activating,
460 -                   sv=addr_getshort("@SV Silicone")/10,
461 -                   pv=addr_getshort("@PV Silicone")/10,
462 -                   product1=addr_getshort("@Product 1")/10,
463 -
464 -                   product2=addr_getshort("@Product 2")/10,
465 -                   product3=addr_getshort("@Product 3")/10,
466 -                   product4=addr_getshort("@Product 4")/10,
467 -                   ice1=addr_getshort("@Ice condenser 1")/10,
468 -                   ice2=addr_getshort("@Ice condenser 2")/10,
469 -                   vacuum=addr_getfloat("@Vacuum")
470 -
471 -                }
472 -     local jsAlarm = {  HPC = addr_getbit("@B_25395#W0.00"),
473 -                        ODPC = addr_getbit("@B_25395#W0.01"),
474 -                        MTPC=addr_getbit("@B_25395#W0.02"),
475 -                        HTT = addr_getbit("@B_25395#W1.03"),
476 -                        CPC = addr_getbit("@B_25395#W0.08"),
477 -                        CPSP =addr_getbit("@B_25395#W1.00"),
478 -                        CPVP =addr_getbit("@B_25395#W0.10"),
479 -                        CPRP =addr_getbit("@B_25395#W0.11"),
480 -                        HP =addr_getbit("@B_25395#W1.01"),
481 -                        PP= addr_getbit("@B_25395#W1.02"),
482 -                        PO=addr_getbit("@B_25395#W0.07"),
483 -                        FSE=addr_getbit("@B_25395#W2.04"),
484 -                        AVVSVV=addr_getbit("@B_25395#W1.12"),
485 -                        ICHT=addr_getbit("@B_25395#W3.06")
486 -
487 -                }
488 -
489 -    -- ("@B_25395#CIO1.02")
490 -     mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
491 -     mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
492 -  else
493 -   local stat, err = mq.m:connect(mq.config) -- connection
494 -   if stat == nil then --Determine whether to connect
495 -    print("mqtt connect failed:", err)
496 -    return -- Connection failed, return directly
497 -   end
498 -   mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics
499 -
500 -  end
501 -  -- mq.m:unsubscribe("stc/test")
502 -  -- mq.m:disconnect() -- close matt
503 -  -- mq.m:close() -- close clase
504 - end
168 + local status_text ="unknow"
169 + if addr_getbit("@Status Run")==1 then
170 + status_text = "RUNNING"
171 + else
172 + status_text = "STOP"
173 + end
174 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--
175 +\\ local js = {type="status",
176 + mc_name ="FD300",
177 + status=status_text,
178 + elapsed_time={
179 + hour=addr_getword("@Elapsed Time (Hour)"),
180 + min=addr_getword("@Elapsed Time (Minute)"),
181 + sec=addr_getword("@Elapsed Time (Second)")
182 + },
183 + phase = phaseStatus,
184 + step = addr_getword("@Step"),
185 + activating_output = pr_activating,
186 + sv=addr_getshort("@SV Silicone")/10,
187 + pv=addr_getshort("@PV Silicone")/10,
188 + product1=addr_getshort("@Product 1")/10,
189 +
190 + product2=addr_getshort("@Product 2")/10,
191 + product3=addr_getshort("@Product 3")/10,
192 + product4=addr_getshort("@Product 4")/10,
193 + ice1=addr_getshort("@Ice condenser 1")/10,
194 + ice2=addr_getshort("@Ice condenser 2")/10,
195 + vacuum=addr_getfloat("@Vacuum")
196 +
197 + }
198 + local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"),
199 + ODPC = addr_getbit("@B_25395#W0.01"),
200 + MTPC=addr_getbit("@B_25395#W0.02"),
201 + HTT = addr_getbit("@B_25395#W1.03"),
202 + CPC = addr_getbit("@B_25395#W0.08"),
203 + CPSP =addr_getbit("@B_25395#W1.00"),
204 + CPVP =addr_getbit("@B_25395#W0.10"),
205 + CPRP =addr_getbit("@B_25395#W0.11"),
206 + HP =addr_getbit("@B_25395#W1.01"),
207 + PP= addr_getbit("@B_25395#W1.02"),
208 + PO=addr_getbit("@B_25395#W0.07"),
209 + FSE=addr_getbit("@B_25395#W2.04"),
210 + AVVSVV=addr_getbit("@B_25395#W1.12"),
211 + ICHT=addr_getbit("@B_25395#W3.06")
212 +
213 + }
214 +\\ ~-~- ("@B_25395#CIO1.02")
215 + mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
216 + mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
217 + else
218 + local stat, err = mq.m:connect(mq.config) ~-~- connection
219 + if stat == nil then ~-~-Determine whether to connect
220 + print("mqtt connect failed:", err)
221 + return ~-~- Connection failed, return directly
222 + end
223 + mq.m:subscribe("mqtt-v-box-epsilon", 0)~-~- Subscribe to topics
224 +\\ end
225 + ~-~- mq.m:unsubscribe("stc/test")
226 + ~-~- mq.m:disconnect() ~-~- close matt
227 + ~-~- mq.m:close() ~-~- close clase
228 + end
505 505  end
506 -{{/code}}
230 +)))
507 507  
508 -== **2.3 V-Box connect with Azure platform** ==
232 +== **2.2 V-Box connect with Azure platform** ==
509 509  
510 510  In this demo,V-Box connects with Azure by SSL certification.
511 511  
... ... @@ -636,7 +636,7 @@
636 636  end
637 637  )))
638 638  
639 -== **2.4 How to configure the Huawei platform?(✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register)** ==
363 +== **2.3 How to configure the Huawei platform?(✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register)** ==
640 640  
641 641  1.Register a account: [[https:~~/~~/www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ>>https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ]]
642 642  
... ... @@ -647,7 +647,7 @@
647 647  3.Create product
648 648  
649 649  (% style="text-align:center" %)
650 -[[image:1624433478954-859.png||height="497" width="1100" class="img-thumbnail"]]
374 +[[image:1624433478954-859.png||class="img-thumbnail" height="497" width="1100"]]
651 651  
652 652  4.Product name,manufacturer,device type and industry,set according to your own needs.
653 653  
... ... @@ -658,7 +658,7 @@
658 658  After finishing configuration,please click "OK"
659 659  
660 660  (% style="text-align:center" %)
661 -[[image:1624433531968-337.png||height="568" width="700" class="img-thumbnail"]]
385 +[[image:1624433531968-337.png||class="img-thumbnail" height="568" width="700"]]
662 662  
663 663  5.Device
664 664  
... ... @@ -678,10 +678,10 @@
678 678  After configuration, click OK to generate a device ID and password, which will be used for device access later.
679 679  
680 680  (% style="text-align:center" %)
681 -[[image:1624436421499-613.png||height="499" width="700" class="img-thumbnail"]]
405 +[[image:1624436421499-613.png||class="img-thumbnail" height="499" width="700"]]
682 682  
683 683  (% style="text-align:center" %)
684 -[[image:1624437798012-126.png||height="366" width="500" class="img-thumbnail"]]
408 +[[image:1624437798012-126.png||class="img-thumbnail" height="366" width="500"]]
685 685  
686 686  6. Connection authentication (use MQTT.fx tool to access the IoT platform)
687 687  
... ... @@ -690,7 +690,7 @@
690 690  **[[Download>>https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Huawei/mqttClientIdGenerator-19.2.0.zip]]**
691 691  
692 692  (% style="text-align:center" %)
693 -[[image:1624437573798-815.png||height="351" width="700" class="img-thumbnail"]]
417 +[[image:1624437573798-815.png||class="img-thumbnail" height="351" width="700"]]
694 694  
695 695  (2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message
696 696  
... ... @@ -697,7 +697,7 @@
697 697  Client ID, user name, password
698 698  
699 699  (% style="text-align:center" %)
700 -[[image:1624437756866-251.png||height="405" width="700" class="img-thumbnail"]]
424 +[[image:1624437756866-251.png||class="img-thumbnail" height="405" width="700"]]
701 701  
702 702  (3) Download certificate file"North-Beijing4"
703 703  
... ... @@ -704,10 +704,10 @@
704 704  [[https:~~/~~/support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html>>https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html]]
705 705  
706 706  (% style="text-align:center" %)
707 -[[image:1624438225398-363.png||height="403" width="800" class="img-thumbnail"]]
431 +[[image:1624438225398-363.png||class="img-thumbnail" height="403" width="800"]]
708 708  
709 709  (% style="text-align:center" %)
710 -[[image:1624438260025-610.png||height="408" width="700" class="img-thumbnail"]]
434 +[[image:1624438260025-610.png||class="img-thumbnail" height="408" width="700"]]
711 711  
712 712  7.Run MQTTfx tool to connect with Huawei
713 713  
... ... @@ -716,7 +716,7 @@
716 716  (1)Click on the setting ICON
717 717  
718 718  (% style="text-align:center" %)
719 -[[image:1624438821280-974.png||height="198" width="500" class="img-thumbnail"]]
443 +[[image:1624438821280-974.png||class="img-thumbnail" height="198" width="500"]]
720 720  
721 721  (2)Fill in IIOT MQTT device access address, and configure authentication parameters.
722 722  First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface.
... ... @@ -731,7 +731,7 @@
731 731  Client ID: check step 6
732 732  
733 733  (% style="text-align:center" %)
734 -[[image:1624439672168-492.png||height="458" width="600" class="img-thumbnail"]]
458 +[[image:1624439672168-492.png||class="img-thumbnail" height="458" width="600"]]
735 735  
736 736  (3)Upload SSL certificate file,check step 6
737 737  
... ... @@ -738,15 +738,15 @@
738 738  Select folder java~-~->DigiCertGlobalRootCA.crt.pem and click OK or apply button
739 739  
740 740  (% style="text-align:center" %)
741 -[[image:1624439912938-659.png||height="458" width="600" class="img-thumbnail"]]
465 +[[image:1624439912938-659.png||class="img-thumbnail" height="458" width="600"]]
742 742  
743 743  (4)Connect and test publish and subscribe
744 744  
745 745  (% style="text-align:center" %)
746 -[[image:1624440014872-688.png||height="232" width="700" class="img-thumbnail"]]
470 +[[image:1624440014872-688.png||class="img-thumbnail" height="232" width="700"]]
747 747  
748 748  (% style="text-align:center" %)
749 -[[image:1624440026937-386.png||height="215" width="700" class="img-thumbnail"]]
473 +[[image:1624440026937-386.png||class="img-thumbnail" height="215" width="700"]]
750 750  
751 751  Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report
752 752  
... ... @@ -770,22 +770,22 @@
770 770  ②Custom model: used to display the service ID name of the configuration report.
771 771  
772 772  (% style="text-align:center" %)
773 -[[image:1624440793982-974.png||height="410" width="700" class="img-thumbnail"]]
497 +[[image:1624440793982-974.png||class="img-thumbnail" height="410" width="700"]]
774 774  
775 775  (% style="text-align:center" %)
776 -[[image:1624440883015-105.png||height="370" width="600" class="img-thumbnail"]]
500 +[[image:1624440883015-105.png||class="img-thumbnail" height="370" width="600"]]
777 777  
778 778  ③Add property, ID of monitoring point, and data format:
779 779  
780 780  (% style="text-align:center" %)
781 -[[image:1624441052296-108.png||height="477" width="600" class="img-thumbnail"]]
505 +[[image:1624441052296-108.png||class="img-thumbnail" height="477" width="600"]]
782 782  
783 783  ④After the configuration is complete, check the received data on the device
784 784  
785 785  (% style="text-align:center" %)
786 -[[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]]
510 +[[image:1624441186851-536.png||class="img-thumbnail" height="434" width="700"]]
787 787  
788 -== **2.5 V-Box connect with Huawei platform** ==
512 +== **2.4 V-Box connect with Huawei platform** ==
789 789  
790 790  In this demo,V-Box connects with Huawei by SSL certification.
791 791  
... ... @@ -794,7 +794,7 @@
794 794  2.configure MQTT configuration
795 795  
796 796  (% style="text-align:center" %)
797 -[[image:1624506363847-661.png||height="507" width="1000" class="img-thumbnail"]]
521 +[[image:1624506363847-661.png||class="img-thumbnail" height="507" width="1000"]]
798 798  
799 799  3.Create a script with the demo as below.
800 800  
... ... @@ -901,309 +901,11 @@
901 901  4.Download project access into V-Box to test in debug page
902 902  
903 903  (% style="text-align:center" %)
904 -[[image:1624506710354-406.png||height="658" width="1000" class="img-thumbnail"]]
628 +[[image:1624506710354-406.png||class="img-thumbnail" height="658" width="1000"]]
905 905  
906 906  (% style="text-align:center" %)
907 -[[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]]
631 +[[image:1624506666650-161.png||class="img-thumbnail" height="547" width="1000"]]
908 908  
909 -== **2.6 V-Box connect with AWS platform** ==
633 +== **2.5 V-Box connect with AWS platform** ==
910 910  
911 -=== **Log in AWS** ===
912 -
913 -Login aws account and click“Connect an IoT device”
914 -
915 -[[image:image-20220709165402-1.png]]
916 -
917 -[[image:image-20220709165402-2.png]]
918 -
919 -
920 -=== **Create policy** ===
921 -
922 -Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
923 -
924 -[[image:image-20220709165402-3.png]]
925 -
926 -Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
927 -
928 -[[image:image-20220709165402-5.png]]
929 -
930 -[[image:image-20220709165402-4.png]]
931 -
932 -{{code language="java"}}
933 -{
934 -
935 -  "Version": "2012-10-17",
936 -
937 -  "Statement": [
938 -
939 -    {
940 -
941 -      "Effect": "Allow",
942 -
943 -      "Action": [
944 -
945 -        "iot:Connect",
946 -
947 -        "iot:Publish",
948 -
949 -        "iot:Subscribe",
950 -
951 -        "iot:Receive",
952 -
953 -        "greengrass:Discover"
954 -
955 -      ],
956 -
957 -      "Resource": "*"
958 -
959 -    }
960 -
961 -  ]
962 -
963 -}
964 -{{/code}}
965 -
966 -=== **Create things** ===
967 -
968 -Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
969 -
970 -[[image:image-20220709165402-6.png]]
971 -
972 -[[image:image-20220709165402-7.png]]
973 -
974 -Name the thing~-~-->Click “Next”
975 -
976 -[[image:image-20220709165402-8.png]]
977 -
978 -Select the way to create certificate
979 -
980 -[[image:image-20220709165402-9.png]]
981 -
982 -Select policy
983 -
984 -[[image:image-20220709165402-10.png]]
985 -
986 -[[image:image-20220709165402-11.png]]
987 -
988 -
989 -=== **Test with MQTT.fx tool** ===
990 -
991 -Click “View Setting” to get the “Broker Adress”
992 -
993 -[[image:image-20220709165402-13.png]]
994 -
995 -[[image:image-20220709165402-12.png]]
996 -
997 -Create one connection in MQTT.fx tool, set broker port as 8883.
998 -
999 -[[image:image-20220709165402-14.png]]
1000 -
1001 -Upload the CA File, Client Certificate File, Client Key File
1002 -
1003 -[[image:image-20220709165402-15.png]]
1004 -
1005 -Publish message to topic “TEST”
1006 -
1007 -[[image:image-20220709165402-17.png]]
1008 -
1009 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
1010 -
1011 -[[image:image-20220709173500-1.png]]
1012 -
1013 -And we can also send message form AWS platform to MQTT.fx tool.
1014 -
1015 -[[image:image-20220709165402-18.png]]
1016 -
1017 -=== **Configurate in CloudTool** ===
1018 -
1019 -Copy the same setting in MQTT.fx to MQTT configuration
1020 -
1021 -[[image:image-20220709165402-19.png]]
1022 -
1023 - Add a lua script and copy the lua demo into it.
1024 -
1025 -[[image:image-20220709165402-20.png]]
1026 -
1027 -sprint = print
1028 -
1029 -~-~-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)
1030 -
1031 -local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
1032 -
1033 -~-~-publish to topics
1034 -
1035 -local pub_RE_TOPIC = string.format('TEST')
1036 -
1037 -~-~-Subscribe topics
1038 -
1039 -local Subscribe_RE_TOPIC1 = string.format('TEST')
1040 -
1041 -~-~-variable
1042 -
1043 -local last_time = 0
1044 -
1045 -~-~-Timing main function
1046 -
1047 -function aws.main()
1048 -
1049 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
1050 -
1051 - if g_mq then
1052 -
1053 - if g_mq:isconnected() then
1054 -
1055 - send_Data()
1056 -
1057 - else
1058 -
1059 - if os.time() - last_time > 5 then
1060 -
1061 - last_time = os.time()
1062 -
1063 - mymqtt_connect()
1064 -
1065 - end
1066 -
1067 - end
1068 -
1069 - else
1070 -
1071 - mymqtt_init()
1072 -
1073 - end
1074 -
1075 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
1076 -
1077 -end
1078 -
1079 -
1080 -~-~- Initialize MQTT
1081 -
1082 -function mymqtt_init()
1083 -
1084 - sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
1085 -
1086 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
1087 -
1088 - if g_mq then
1089 -
1090 - g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
1091 -
1092 - sprint("mqtt init success")
1093 -
1094 - else
1095 -
1096 - sprint("mqtt init failed:", err)
1097 -
1098 - end
1099 -
1100 -end
1101 -
1102 -~-~- Connect to MQTT server
1103 -
1104 -function mymqtt_connect()
1105 -
1106 - sprint("mqtt connecting...")
1107 -
1108 - local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
1109 -
1110 - if stat == nil then
1111 -
1112 - sprint("mqtt connect failed:", err)
1113 -
1114 - return
1115 -
1116 - else
1117 -
1118 - sprint("mqtt connected")
1119 -
1120 - end
1121 -
1122 - g_mq:subscribe(TEST, 0)
1123 -
1124 -end
1125 -
1126 -~-~- Receive MQTT message callback function
1127 -
1128 -function mymqtt_msg_callback(topic, msg)
1129 -
1130 - print("topic:",topic)
1131 -
1132 - print("revdata:",msg)
1133 -
1134 - local revData = json.decode(msg)
1135 -
1136 - print (revData)
1137 -
1138 - if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
1139 -
1140 -if string.match(topic,Subscribe_RE_TOPIC1) then
1141 -
1142 - ~-~-if revData ~~= nil then
1143 -
1144 - for k,v in pairs (revData) do
1145 -
1146 - print("printing revdata after kv here")
1147 -
1148 - print (k,v)
1149 -
1150 - end
1151 -
1152 - print ("current state is",fanstate)
1153 -
1154 - ~-~-end
1155 -
1156 -end
1157 -
1158 -end
1159 -
1160 -end
1161 -
1162 -
1163 -~-~-Get real-time data
1164 -
1165 -function getData()
1166 -
1167 - local jdata = {}
1168 -
1169 - local addr = bns_get_alldata()
1170 -
1171 - print(json.encode(addr))
1172 -
1173 - for i,v in pairs(addr) do
1174 -
1175 - if v[2] == 1 then
1176 -
1177 - jdata[v[3]] = v[4]
1178 -
1179 - end
1180 -
1181 - end
1182 -
1183 - return jdata
1184 -
1185 -end
1186 -
1187 -~-~-send data
1188 -
1189 -function send_Data()
1190 -
1191 - local pub_data =
1192 -
1193 - {
1194 -
1195 -123
1196 -
1197 -}
1198 -
1199 -sprint(json.encode(pub_data))
1200 -
1201 -print("..........",pub_RE_TOPIC)
1202 -
1203 - return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
1204 -
1205 -end
1206 -
1207 -Get message in AWS
1208 -
1209 -[[image:image-20220709165402-21.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]]
image-20220709165226-1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -1.2 MB
Content
image-20220709165402-1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -200.2 KB
Content
image-20220709165402-10.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -19.0 KB
Content
image-20220709165402-11.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -105.9 KB
Content
image-20220709165402-12.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -29.0 KB
Content
image-20220709165402-13.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -158.8 KB
Content
image-20220709165402-14.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -48.1 KB
Content
image-20220709165402-15.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -46.9 KB
Content
image-20220709165402-16.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -140.7 KB
Content
image-20220709165402-17.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -12.5 KB
Content
image-20220709165402-18.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -32.2 KB
Content
image-20220709165402-19.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -66.6 KB
Content
image-20220709165402-2.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -188.5 KB
Content
image-20220709165402-20.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -33.3 KB
Content
image-20220709165402-21.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -124.8 KB
Content
image-20220709165402-3.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -103.9 KB
Content
image-20220709165402-4.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -4.0 KB
Content
image-20220709165402-5.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -66.5 KB
Content
image-20220709165402-6.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -110.0 KB
Content
image-20220709165402-7.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -25.4 KB
Content
image-20220709165402-8.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -64.2 KB
Content
image-20220709165402-9.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -37.5 KB
Content
image-20220709173500-1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Jim
Size
... ... @@ -1,1 +1,0 @@
1 -1.5 MB
Content