Changes for page 2 Script

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

From version 3.1
edited by Leo
on 2022/06/16 17:19
Change comment: Renamed back-links.
To version 19.1
edited by Hunter
on 2022/07/29 15:56
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Leo
1 +XWiki.Hunter
Content
... ... @@ -7,25 +7,25 @@
7 7  )))
8 8  
9 9  (% style="text-align:center" %)
10 -[[image:1624245865976-320.png||class="img-thumbnail" height="182" width="1000"]]
10 +[[image:1624245865976-320.png||height="182" width="1000" class="img-thumbnail"]]
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 script function.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  
20 20  (% style="text-align:center" %)
21 -[[image:1624249623612-177.png||class="img-thumbnail" height="337" width="400"]]
21 +[[image:1624249623612-177.png||height="337" width="400" class="img-thumbnail"]]
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||class="img-thumbnail" height="135" width="400"]]
26 +[[image:1624249693457-742.png||height="135" width="400" class="img-thumbnail"]]
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||class="img-thumbnail" height="385" width="400"]]
35 +[[image:1645535936750-316.png||height="385" width="400" class="img-thumbnail"]]
36 36  
37 37  Script is as below:
38 38  
... ... @@ -66,6 +66,76 @@
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 +
69 69  = **2 V-Box connect with third part server** =
70 70  
71 71  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.
... ... @@ -90,144 +90,148 @@
90 90  
91 91  Demo1:
92 92  
93 -(% class="box infomessage" %)
94 -(((
95 -~-~- Meta class
96 -~-~-main
163 +{{code language="lua"}}
164 +-- Meta class
165 +--main
97 97  function mq.main()
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) 
167 + if not mq.m then
168 +  local err = ""
166 166  
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)  
167 167  
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
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
229 229  end
230 -)))
304 +{{/code}}
231 231  
232 232  == **2.2 V-Box connect with Azure platform** ==
233 233  
... ... @@ -371,7 +371,7 @@
371 371  3.Create product
372 372  
373 373  (% style="text-align:center" %)
374 -[[image:1624433478954-859.png||class="img-thumbnail" height="497" width="1100"]]
448 +[[image:1624433478954-859.png||height="497" width="1100" class="img-thumbnail"]]
375 375  
376 376  4.Product name,manufacturer,device type and industry,set according to your own needs.
377 377  
... ... @@ -382,7 +382,7 @@
382 382  After finishing configuration,please click "OK"
383 383  
384 384  (% style="text-align:center" %)
385 -[[image:1624433531968-337.png||class="img-thumbnail" height="568" width="700"]]
459 +[[image:1624433531968-337.png||height="568" width="700" class="img-thumbnail"]]
386 386  
387 387  5.Device
388 388  
... ... @@ -402,10 +402,10 @@
402 402  After configuration, click OK to generate a device ID and password, which will be used for device access later.
403 403  
404 404  (% style="text-align:center" %)
405 -[[image:1624436421499-613.png||class="img-thumbnail" height="499" width="700"]]
479 +[[image:1624436421499-613.png||height="499" width="700" class="img-thumbnail"]]
406 406  
407 407  (% style="text-align:center" %)
408 -[[image:1624437798012-126.png||class="img-thumbnail" height="366" width="500"]]
482 +[[image:1624437798012-126.png||height="366" width="500" class="img-thumbnail"]]
409 409  
410 410  6. Connection authentication (use MQTT.fx tool to access the IoT platform)
411 411  
... ... @@ -414,7 +414,7 @@
414 414  **[[Download>>https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Huawei/mqttClientIdGenerator-19.2.0.zip]]**
415 415  
416 416  (% style="text-align:center" %)
417 -[[image:1624437573798-815.png||class="img-thumbnail" height="351" width="700"]]
491 +[[image:1624437573798-815.png||height="351" width="700" class="img-thumbnail"]]
418 418  
419 419  (2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message
420 420  
... ... @@ -421,7 +421,7 @@
421 421  Client ID, user name, password
422 422  
423 423  (% style="text-align:center" %)
424 -[[image:1624437756866-251.png||class="img-thumbnail" height="405" width="700"]]
498 +[[image:1624437756866-251.png||height="405" width="700" class="img-thumbnail"]]
425 425  
426 426  (3) Download certificate file"North-Beijing4"
427 427  
... ... @@ -428,10 +428,10 @@
428 428  [[https:~~/~~/support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html>>https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html]]
429 429  
430 430  (% style="text-align:center" %)
431 -[[image:1624438225398-363.png||class="img-thumbnail" height="403" width="800"]]
505 +[[image:1624438225398-363.png||height="403" width="800" class="img-thumbnail"]]
432 432  
433 433  (% style="text-align:center" %)
434 -[[image:1624438260025-610.png||class="img-thumbnail" height="408" width="700"]]
508 +[[image:1624438260025-610.png||height="408" width="700" class="img-thumbnail"]]
435 435  
436 436  7.Run MQTTfx tool to connect with Huawei
437 437  
... ... @@ -440,7 +440,7 @@
440 440  (1)Click on the setting ICON
441 441  
442 442  (% style="text-align:center" %)
443 -[[image:1624438821280-974.png||class="img-thumbnail" height="198" width="500"]]
517 +[[image:1624438821280-974.png||height="198" width="500" class="img-thumbnail"]]
444 444  
445 445  (2)Fill in IIOT MQTT device access address, and configure authentication parameters.
446 446  First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface.
... ... @@ -455,7 +455,7 @@
455 455  Client ID: check step 6
456 456  
457 457  (% style="text-align:center" %)
458 -[[image:1624439672168-492.png||class="img-thumbnail" height="458" width="600"]]
532 +[[image:1624439672168-492.png||height="458" width="600" class="img-thumbnail"]]
459 459  
460 460  (3)Upload SSL certificate file,check step 6
461 461  
... ... @@ -462,15 +462,15 @@
462 462  Select folder java~-~->DigiCertGlobalRootCA.crt.pem and click OK or apply button
463 463  
464 464  (% style="text-align:center" %)
465 -[[image:1624439912938-659.png||class="img-thumbnail" height="458" width="600"]]
539 +[[image:1624439912938-659.png||height="458" width="600" class="img-thumbnail"]]
466 466  
467 467  (4)Connect and test publish and subscribe
468 468  
469 469  (% style="text-align:center" %)
470 -[[image:1624440014872-688.png||class="img-thumbnail" height="232" width="700"]]
544 +[[image:1624440014872-688.png||height="232" width="700" class="img-thumbnail"]]
471 471  
472 472  (% style="text-align:center" %)
473 -[[image:1624440026937-386.png||class="img-thumbnail" height="215" width="700"]]
547 +[[image:1624440026937-386.png||height="215" width="700" class="img-thumbnail"]]
474 474  
475 475  Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report
476 476  
... ... @@ -494,20 +494,20 @@
494 494  ②Custom model: used to display the service ID name of the configuration report.
495 495  
496 496  (% style="text-align:center" %)
497 -[[image:1624440793982-974.png||class="img-thumbnail" height="410" width="700"]]
571 +[[image:1624440793982-974.png||height="410" width="700" class="img-thumbnail"]]
498 498  
499 499  (% style="text-align:center" %)
500 -[[image:1624440883015-105.png||class="img-thumbnail" height="370" width="600"]]
574 +[[image:1624440883015-105.png||height="370" width="600" class="img-thumbnail"]]
501 501  
502 502  ③Add property, ID of monitoring point, and data format:
503 503  
504 504  (% style="text-align:center" %)
505 -[[image:1624441052296-108.png||class="img-thumbnail" height="477" width="600"]]
579 +[[image:1624441052296-108.png||height="477" width="600" class="img-thumbnail"]]
506 506  
507 507  ④After the configuration is complete, check the received data on the device
508 508  
509 509  (% style="text-align:center" %)
510 -[[image:1624441186851-536.png||class="img-thumbnail" height="434" width="700"]]
584 +[[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]]
511 511  
512 512  == **2.4 V-Box connect with Huawei platform** ==
513 513  
... ... @@ -518,7 +518,7 @@
518 518  2.configure MQTT configuration
519 519  
520 520  (% style="text-align:center" %)
521 -[[image:1624506363847-661.png||class="img-thumbnail" height="507" width="1000"]]
595 +[[image:1624506363847-661.png||height="507" width="1000" class="img-thumbnail"]]
522 522  
523 523  3.Create a script with the demo as below.
524 524  
... ... @@ -625,11 +625,309 @@
625 625  4.Download project access into V-Box to test in debug page
626 626  
627 627  (% style="text-align:center" %)
628 -[[image:1624506710354-406.png||class="img-thumbnail" height="658" width="1000"]]
702 +[[image:1624506710354-406.png||height="658" width="1000" class="img-thumbnail"]]
629 629  
630 630  (% style="text-align:center" %)
631 -[[image:1624506666650-161.png||class="img-thumbnail" height="547" width="1000"]]
705 +[[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]]
632 632  
633 633  == **2.5 V-Box connect with AWS platform** ==
634 634  
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]]
709 +=== **Log in AWS** ===
710 +
711 +Login aws account and click“Connect an IoT device”
712 +
713 +[[image:image-20220709165402-1.png]]
714 +
715 +[[image:image-20220709165402-2.png]]
716 +
717 +
718 +=== **Create policy** ===
719 +
720 +Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
721 +
722 +[[image:image-20220709165402-3.png]]
723 +
724 +Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
725 +
726 +[[image:image-20220709165402-5.png]]
727 +
728 +[[image:image-20220709165402-4.png]]
729 +
730 +{{code language="java"}}
731 +{
732 +
733 +  "Version": "2012-10-17",
734 +
735 +  "Statement": [
736 +
737 +    {
738 +
739 +      "Effect": "Allow",
740 +
741 +      "Action": [
742 +
743 +        "iot:Connect",
744 +
745 +        "iot:Publish",
746 +
747 +        "iot:Subscribe",
748 +
749 +        "iot:Receive",
750 +
751 +        "greengrass:Discover"
752 +
753 +      ],
754 +
755 +      "Resource": "*"
756 +
757 +    }
758 +
759 +  ]
760 +
761 +}
762 +{{/code}}
763 +
764 +=== **Create things** ===
765 +
766 +Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
767 +
768 +[[image:image-20220709165402-6.png]]
769 +
770 +[[image:image-20220709165402-7.png]]
771 +
772 +Name the thing~-~-->Click “Next”
773 +
774 +[[image:image-20220709165402-8.png]]
775 +
776 +Select the way to create certificate
777 +
778 +[[image:image-20220709165402-9.png]]
779 +
780 +Select policy
781 +
782 +[[image:image-20220709165402-10.png]]
783 +
784 +[[image:image-20220709165402-11.png]]
785 +
786 +
787 +=== **Test with MQTT.fx tool** ===
788 +
789 +Click “View Setting” to get the “Broker Adress”
790 +
791 +[[image:image-20220709165402-13.png]]
792 +
793 +[[image:image-20220709165402-12.png]]
794 +
795 +Create one connection in MQTT.fx tool, set broker port as 8883.
796 +
797 +[[image:image-20220709165402-14.png]]
798 +
799 +Upload the CA File, Client Certificate File, Client Key File
800 +
801 +[[image:image-20220709165402-15.png]]
802 +
803 +Publish message to topic “TEST”
804 +
805 +[[image:image-20220709165402-17.png]]
806 +
807 +Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
808 +
809 +[[image:image-20220709173500-1.png]]
810 +
811 +And we can also send message form AWS platform to MQTT.fx tool.
812 +
813 +[[image:image-20220709165402-18.png]]
814 +
815 +=== **Configurate in CloudTool** ===
816 +
817 +Copy the same setting in MQTT.fx to MQTT configuration
818 +
819 +[[image:image-20220709165402-19.png]]
820 +
821 + Add a lua script and copy the lua demo into it.
822 +
823 +[[image:image-20220709165402-20.png]]
824 +
825 +sprint = print
826 +
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)
828 +
829 +local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
830 +
831 +~-~-publish to topics
832 +
833 +local pub_RE_TOPIC = string.format('TEST')
834 +
835 +~-~-Subscribe topics
836 +
837 +local Subscribe_RE_TOPIC1 = string.format('TEST')
838 +
839 +~-~-variable
840 +
841 +local last_time = 0
842 +
843 +~-~-Timing main function
844 +
845 +function aws.main()
846 +
847 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
848 +
849 + if g_mq then
850 +
851 + if g_mq:isconnected() then
852 +
853 + send_Data()
854 +
855 + else
856 +
857 + if os.time() - last_time > 5 then
858 +
859 + last_time = os.time()
860 +
861 + mymqtt_connect()
862 +
863 + end
864 +
865 + end
866 +
867 + else
868 +
869 + mymqtt_init()
870 +
871 + end
872 +
873 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
874 +
875 +end
876 +
877 +
878 +~-~- Initialize MQTT
879 +
880 +function mymqtt_init()
881 +
882 + sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
883 +
884 + g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
885 +
886 + if g_mq then
887 +
888 + g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
889 +
890 + sprint("mqtt init success")
891 +
892 + else
893 +
894 + sprint("mqtt init failed:", err)
895 +
896 + end
897 +
898 +end
899 +
900 +~-~- Connect to MQTT server
901 +
902 +function mymqtt_connect()
903 +
904 + sprint("mqtt connecting...")
905 +
906 + local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
907 +
908 + if stat == nil then
909 +
910 + sprint("mqtt connect failed:", err)
911 +
912 + return
913 +
914 + else
915 +
916 + sprint("mqtt connected")
917 +
918 + end
919 +
920 + g_mq:subscribe(TEST, 0)
921 +
922 +end
923 +
924 +~-~- Receive MQTT message callback function
925 +
926 +function mymqtt_msg_callback(topic, msg)
927 +
928 + print("topic:",topic)
929 +
930 + print("revdata:",msg)
931 +
932 + local revData = json.decode(msg)
933 +
934 + print (revData)
935 +
936 + if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
937 +
938 +if string.match(topic,Subscribe_RE_TOPIC1) then
939 +
940 + ~-~-if revData ~~= nil then
941 +
942 + for k,v in pairs (revData) do
943 +
944 + print("printing revdata after kv here")
945 +
946 + print (k,v)
947 +
948 + end
949 +
950 + print ("current state is",fanstate)
951 +
952 + ~-~-end
953 +
954 +end
955 +
956 +end
957 +
958 +end
959 +
960 +
961 +~-~-Get real-time data
962 +
963 +function getData()
964 +
965 + local jdata = {}
966 +
967 + local addr = bns_get_alldata()
968 +
969 + print(json.encode(addr))
970 +
971 + for i,v in pairs(addr) do
972 +
973 + if v[2] == 1 then
974 +
975 + jdata[v[3]] = v[4]
976 +
977 + end
978 +
979 + end
980 +
981 + return jdata
982 +
983 +end
984 +
985 +~-~-send data
986 +
987 +function send_Data()
988 +
989 + local pub_data =
990 +
991 + {
992 +
993 +123
994 +
995 +}
996 +
997 +sprint(json.encode(pub_data))
998 +
999 +print("..........",pub_RE_TOPIC)
1000 +
1001 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
1002 +
1003 +end
1004 +
1005 +Get message in AWS
1006 +
1007 +[[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