Changes for page 2 Script

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

From version 20.1
edited by Hunter
on 2022/07/29 16:47
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.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,76 +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 -
139 139  = **2 V-Box connect with third part server** =
140 140  
141 141  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.
... ... @@ -154,280 +154,152 @@
154 154  
155 155  (% class="mark" %)2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate
156 156  
157 -(% class="wikigeneratedid" %)
158 -**✎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** ==
159 159  
160 -(% class="wikigeneratedid" %)
161 -Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]**
162 -
163 -== **2.1 V-Box connect with test server(General Example)** ==
164 -
165 -{{code language="lua"}}
166 ---MQTT configuration table
167 -local MQTT_CFG={}
168 -MQTT_CFG.username = "weconsupport"
169 -MQTT_CFG.password = "123456"
170 -MQTT_CFG.netway = 0
171 -MQTT_CFG.keepalive = 60
172 -MQTT_CFG.cleansession = 1
173 ---TCP URL
174 -MQTT_URL = "tcp://mq.tongxinmao.com:1883"
175 ---Client ID
176 -MQTT_CLIENT_ID = "V-BOXH-AG"
177 -
178 ---Generate UUID
179 -function uuid()
180 - local seed = {'e','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}
181 - local tb = {}
182 - for i=1, 32 do
183 - table.insert(tb, seed[math.random(1,16)])
184 - end
185 - local sid=table.concat(tb)
186 - return string.format('%s',
187 - string.sub(sid,1,32)
188 - )
189 -end
190 -
191 -
192 ---Topic name to subscribed
193 -local SUBSCRIBE_TOPIC = 'testtopic/test/no1/123456'
194 -
195 ---Topic name to be published
196 -local PUBLISH_TOPIC = 'testtopic/test/no1/7890'
197 -
198 -
199 ---real time
200 -local LAST_TIME = 0
201 -
202 -
203 ---initialize mqtt
204 -function mqtt_init()
205 - print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID))
206 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable
207 - if g_mq then
208 - g_mq:on("message", mqtt_msg_callback) -- Register a callback for receiving messages
209 - print("mqtt init success")
210 - else
211 - print("mqtt init failed:", err)
212 - end
213 -end
214 -
215 --- connect to mqtt
216 -function mqtt_connect()
217 - print("mqtt connecting...")
218 - local stat, err = g_mq:connect(MQTT_CFG)
219 - if stat == nil then
220 - print("mqtt connect failed:", err)
221 - return
222 - else
223 - print("mqtt connected")
224 - end
225 - g_mq:subscribe(SUBSCRIBE_TOPIC, 0)
226 -end
227 -
228 --- Received message callback function
229 -function mqtt_msg_callback(topic, msg)
230 - print("topic:", topic)
231 - print("msg:", msg)
232 - local objMsg = json.decode(msg)
233 - local water = objMsg.data.waterlevel
234 - local temp = objMsg.data.temperature
235 - addr_setword("@HDW20",water)
236 - addr_setword("@HDW10",temp)
237 -end
238 -
239 ---Send data (data upload to platform and encapsulate it with custom functions)
240 -function send_data()
241 - local pub_data = {
242 - timestamp = os.time(),
243 - messageId = 1,
244 - event = 'test_data',
245 - mfrs = 'V-Box',
246 - data = {
247 - id = uuid(),
248 - waterlevel = addr_getword("@HDW10"),
249 - temperature = addr_getword("@HDW20")
250 - }
251 - }
252 - return g_mq:publish(PUBLISH_TOPIC, json.encode(pub_data), 0, 0)
253 -end
254 -
255 -
256 ---main function fixed timed execution
257 -function MQTT.main()
258 - --dosomething
259 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main start")
260 - --determine the mqtt object whether exist
261 - if g_mq then
262 - --determine the mqtt object whether has been connected or not
263 - if g_mq:isconnected() then
264 - send_data()
265 - else
266 - --if exceed 20 sec not connect, reconnect once
267 - if os.time() - LAST_TIME > 20 then
268 - LAST_TIME = os.time()
269 - --connect to mqtt or reconnect
270 - mqtt_connect()
271 - end
272 - end
273 - else
274 - --mqtt object does not exist so create new one
275 - mqtt_init()
276 - end
277 - print(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " main end")
278 -end
279 -{{/code}}
280 -
281 -== **2.2 V-Box connect with customer server:grouprobotinfo.com** ==
282 -
283 283  This demo does not use SSL certification. Script is as below
284 284  
285 285  Demo1:
286 286  
287 -{{code language="lua"}}
288 --- Meta class
289 ---main
93 +(% class="box infomessage" %)
94 +(((
95 +~-~- Meta class
96 +~-~-main
290 290  function mq.main()
291 - if not mq.m then
292 -  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) 
293 293  
294 -  mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID")  -- create connection
295 -  if mq.m then
296 -   mq.config = {
297 -    username = "",-- ID
298 -    password = "",-- password
299 -    netway = 1, -- Ethernet connection, WIFI=1
300 -    -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds.
301 -    -- cleansession = 0, -- Optional, keep session
302 -   }
303 -   mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks
304 -    local str = string.format("%s:%s", topic, msg)
305 -    -- print("mqtt msg:", str) -- Print out the received topics and content
306 -   end
307 -   )
308 -   mq.m:on("offline", function (cause) -- Register for lost connection callbacks
309 -    -- addr_setstring("@xxx", "cause"..(cause or " got nil"))
310 -   end)
311 -   mq.m:on("arrived", function() -- Registration for sending messages to callbacks 
312 -    print("msg arrived")
313 -   end)
314 -  else
315 -   print("mqtt create failed:", err) -- Create object failed
316 -  end
317 - else
318 -  if mq.m:isconnected() then -- If online, post a message
319 -     local phaseStatus ="unknow"
320 -     if addr_getbit("@Standby")== 1 then
321 -         phaseStatus = "Standby"
322 -     elseif addr_getbit("@Pre-Freeze")==1 then
323 -         phaseStatus= "Pre-Freeze"
324 -     elseif addr_getbit("@Prepare")==1 then
325 -         phaseStatus ="Prepare"
326 -     elseif addr_getbit("@Primary Dry")==1 then
327 -         phaseStatus = "Primary dry"
328 -     elseif addr_getbit("@Secondary Dry")==1 then
329 -         phaseStatus = "Secondary Dry"
330 -     end
331 ---   print(addr_getbit("@Primary Dry"))
332 --------------------------------------------------------------------------------------------------------------------------
333 -     local activating ="unknow"
334 -     if addr_getbit("@Compressor")==1 then
335 -         activating = ",".."Compressor"
336 -     end
337 -     if addr_getbit("@Silicone Pump")==1 then
338 -         activating = activating..",".."Silicone Pump"
339 -     end
340 -     if addr_getbit("@Vacuum Pump")==1 then
341 -         activating = activating..",".."Vacuum Pump"
342 -     end
343 -     if addr_getbit("@Root Pump")==1 then
344 -         activating = activating..",".."Root Pump"
345 -     end
346 -     if addr_getbit("@Heater")==1 then
347 -         activating = activating..",".."Heater"
348 -     end
349 -     if addr_getbit("@Valve Silicone")==1 then
350 -         activating = activating..",".."Valve Silicone"
351 -     end
352 -     if addr_getbit("@Valve Ice Condenser")==1 then
353 -         activating = activating..",".."Valve Ice Condenser"
354 -     end
355 -     if addr_getbit("@Valve Vacuum Pump")==1 then
356 -         activating = activating..",".."Valve Vacuum Pump"
357 -     end
358 -     local pr_activating =string.sub(activating,2)
359 -    --  print(pr_activating)  
360 360  
361 -
362 -
363 -     local status_text ="unknow"
364 -     if addr_getbit("@Status Run")==1 then
365 -         status_text = "RUNNING"
366 -     else
367 -         status_text = "STOP"
368 -     end
369 --------------------------------------------------------------------------------------------------------------------------      
370 -
371 -     local js =  {type="status",
372 -                  mc_name ="FD300",
373 -                  status=status_text,
374 -                  elapsed_time={
375 -                                hour=addr_getword("@Elapsed Time (Hour)"),
376 -                                min=addr_getword("@Elapsed Time (Minute)"),
377 -                                sec=addr_getword("@Elapsed Time (Second)")
378 -                                },
379 -                   phase = phaseStatus,
380 -                   step = addr_getword("@Step"),
381 -                   activating_output = pr_activating,
382 -                   sv=addr_getshort("@SV Silicone")/10,
383 -                   pv=addr_getshort("@PV Silicone")/10,
384 -                   product1=addr_getshort("@Product 1")/10,
385 -
386 -                   product2=addr_getshort("@Product 2")/10,
387 -                   product3=addr_getshort("@Product 3")/10,
388 -                   product4=addr_getshort("@Product 4")/10,
389 -                   ice1=addr_getshort("@Ice condenser 1")/10,
390 -                   ice2=addr_getshort("@Ice condenser 2")/10,
391 -                   vacuum=addr_getfloat("@Vacuum")
392 -
393 -                }
394 -     local jsAlarm = {  HPC = addr_getbit("@B_25395#W0.00"),
395 -                        ODPC = addr_getbit("@B_25395#W0.01"),
396 -                        MTPC=addr_getbit("@B_25395#W0.02"),
397 -                        HTT = addr_getbit("@B_25395#W1.03"),
398 -                        CPC = addr_getbit("@B_25395#W0.08"),
399 -                        CPSP =addr_getbit("@B_25395#W1.00"),
400 -                        CPVP =addr_getbit("@B_25395#W0.10"),
401 -                        CPRP =addr_getbit("@B_25395#W0.11"),
402 -                        HP =addr_getbit("@B_25395#W1.01"),
403 -                        PP= addr_getbit("@B_25395#W1.02"),
404 -                        PO=addr_getbit("@B_25395#W0.07"),
405 -                        FSE=addr_getbit("@B_25395#W2.04"),
406 -                        AVVSVV=addr_getbit("@B_25395#W1.12"),
407 -                        ICHT=addr_getbit("@B_25395#W3.06")
408 -
409 -                }
410 -
411 -    -- ("@B_25395#CIO1.02")
412 -     mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
413 -     mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
414 -  else
415 -   local stat, err = mq.m:connect(mq.config) -- connection
416 -   if stat == nil then --Determine whether to connect
417 -    print("mqtt connect failed:", err)
418 -    return -- Connection failed, return directly
419 -   end
420 -   mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics
421 -
422 -  end
423 -  -- mq.m:unsubscribe("stc/test")
424 -  -- mq.m:disconnect() -- close matt
425 -  -- mq.m:close() -- close clase
426 - 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
427 427  end
428 -{{/code}}
230 +)))
429 429  
430 -== **2.3 V-Box connect with Azure platform** ==
232 +== **2.2 V-Box connect with Azure platform** ==
431 431  
432 432  In this demo,V-Box connects with Azure by SSL certification.
433 433  
... ... @@ -558,7 +558,7 @@
558 558  end
559 559  )))
560 560  
561 -== **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)** ==
562 562  
563 563  1.Register a account: [[https:~~/~~/www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ>>https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ]]
564 564  
... ... @@ -569,7 +569,7 @@
569 569  3.Create product
570 570  
571 571  (% style="text-align:center" %)
572 -[[image:1624433478954-859.png||height="497" width="1100" class="img-thumbnail"]]
374 +[[image:1624433478954-859.png||class="img-thumbnail" height="497" width="1100"]]
573 573  
574 574  4.Product name,manufacturer,device type and industry,set according to your own needs.
575 575  
... ... @@ -580,7 +580,7 @@
580 580  After finishing configuration,please click "OK"
581 581  
582 582  (% style="text-align:center" %)
583 -[[image:1624433531968-337.png||height="568" width="700" class="img-thumbnail"]]
385 +[[image:1624433531968-337.png||class="img-thumbnail" height="568" width="700"]]
584 584  
585 585  5.Device
586 586  
... ... @@ -600,10 +600,10 @@
600 600  After configuration, click OK to generate a device ID and password, which will be used for device access later.
601 601  
602 602  (% style="text-align:center" %)
603 -[[image:1624436421499-613.png||height="499" width="700" class="img-thumbnail"]]
405 +[[image:1624436421499-613.png||class="img-thumbnail" height="499" width="700"]]
604 604  
605 605  (% style="text-align:center" %)
606 -[[image:1624437798012-126.png||height="366" width="500" class="img-thumbnail"]]
408 +[[image:1624437798012-126.png||class="img-thumbnail" height="366" width="500"]]
607 607  
608 608  6. Connection authentication (use MQTT.fx tool to access the IoT platform)
609 609  
... ... @@ -612,7 +612,7 @@
612 612  **[[Download>>https://wecon-disk.oss-ap-southeast-1.aliyuncs.com/Download/WIKI/V-BOX/Demo/Huawei/mqttClientIdGenerator-19.2.0.zip]]**
613 613  
614 614  (% style="text-align:center" %)
615 -[[image:1624437573798-815.png||height="351" width="700" class="img-thumbnail"]]
417 +[[image:1624437573798-815.png||class="img-thumbnail" height="351" width="700"]]
616 616  
617 617  (2)Fill in the device ID and secret (deviceid and secret generated when registering the device) to generate connection message
618 618  
... ... @@ -619,7 +619,7 @@
619 619  Client ID, user name, password
620 620  
621 621  (% style="text-align:center" %)
622 -[[image:1624437756866-251.png||height="405" width="700" class="img-thumbnail"]]
424 +[[image:1624437756866-251.png||class="img-thumbnail" height="405" width="700"]]
623 623  
624 624  (3) Download certificate file"North-Beijing4"
625 625  
... ... @@ -626,10 +626,10 @@
626 626  [[https:~~/~~/support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html>>https://support.huaweicloud.com/en-us/devg-iothub/iot_02_1004.html]]
627 627  
628 628  (% style="text-align:center" %)
629 -[[image:1624438225398-363.png||height="403" width="800" class="img-thumbnail"]]
431 +[[image:1624438225398-363.png||class="img-thumbnail" height="403" width="800"]]
630 630  
631 631  (% style="text-align:center" %)
632 -[[image:1624438260025-610.png||height="408" width="700" class="img-thumbnail"]]
434 +[[image:1624438260025-610.png||class="img-thumbnail" height="408" width="700"]]
633 633  
634 634  7.Run MQTTfx tool to connect with Huawei
635 635  
... ... @@ -638,7 +638,7 @@
638 638  (1)Click on the setting ICON
639 639  
640 640  (% style="text-align:center" %)
641 -[[image:1624438821280-974.png||height="198" width="500" class="img-thumbnail"]]
443 +[[image:1624438821280-974.png||class="img-thumbnail" height="198" width="500"]]
642 642  
643 643  (2)Fill in IIOT MQTT device access address, and configure authentication parameters.
644 644  First: It is the server and port connected to Huawei IOT, which can be viewed through the overview of the interface.
... ... @@ -653,7 +653,7 @@
653 653  Client ID: check step 6
654 654  
655 655  (% style="text-align:center" %)
656 -[[image:1624439672168-492.png||height="458" width="600" class="img-thumbnail"]]
458 +[[image:1624439672168-492.png||class="img-thumbnail" height="458" width="600"]]
657 657  
658 658  (3)Upload SSL certificate file,check step 6
659 659  
... ... @@ -660,15 +660,15 @@
660 660  Select folder java~-~->DigiCertGlobalRootCA.crt.pem and click OK or apply button
661 661  
662 662  (% style="text-align:center" %)
663 -[[image:1624439912938-659.png||height="458" width="600" class="img-thumbnail"]]
465 +[[image:1624439912938-659.png||class="img-thumbnail" height="458" width="600"]]
664 664  
665 665  (4)Connect and test publish and subscribe
666 666  
667 667  (% style="text-align:center" %)
668 -[[image:1624440014872-688.png||height="232" width="700" class="img-thumbnail"]]
470 +[[image:1624440014872-688.png||class="img-thumbnail" height="232" width="700"]]
669 669  
670 670  (% style="text-align:center" %)
671 -[[image:1624440026937-386.png||height="215" width="700" class="img-thumbnail"]]
473 +[[image:1624440026937-386.png||class="img-thumbnail" height="215" width="700"]]
672 672  
673 673  Huawei publish topic format: $oc/devices/{device_id}/sys/properties/report
674 674  
... ... @@ -692,22 +692,22 @@
692 692  ②Custom model: used to display the service ID name of the configuration report.
693 693  
694 694  (% style="text-align:center" %)
695 -[[image:1624440793982-974.png||height="410" width="700" class="img-thumbnail"]]
497 +[[image:1624440793982-974.png||class="img-thumbnail" height="410" width="700"]]
696 696  
697 697  (% style="text-align:center" %)
698 -[[image:1624440883015-105.png||height="370" width="600" class="img-thumbnail"]]
500 +[[image:1624440883015-105.png||class="img-thumbnail" height="370" width="600"]]
699 699  
700 700  ③Add property, ID of monitoring point, and data format:
701 701  
702 702  (% style="text-align:center" %)
703 -[[image:1624441052296-108.png||height="477" width="600" class="img-thumbnail"]]
505 +[[image:1624441052296-108.png||class="img-thumbnail" height="477" width="600"]]
704 704  
705 705  ④After the configuration is complete, check the received data on the device
706 706  
707 707  (% style="text-align:center" %)
708 -[[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]]
510 +[[image:1624441186851-536.png||class="img-thumbnail" height="434" width="700"]]
709 709  
710 -== **2.5 V-Box connect with Huawei platform** ==
512 +== **2.4 V-Box connect with Huawei platform** ==
711 711  
712 712  In this demo,V-Box connects with Huawei by SSL certification.
713 713  
... ... @@ -716,7 +716,7 @@
716 716  2.configure MQTT configuration
717 717  
718 718  (% style="text-align:center" %)
719 -[[image:1624506363847-661.png||height="507" width="1000" class="img-thumbnail"]]
521 +[[image:1624506363847-661.png||class="img-thumbnail" height="507" width="1000"]]
720 720  
721 721  3.Create a script with the demo as below.
722 722  
... ... @@ -823,309 +823,11 @@
823 823  4.Download project access into V-Box to test in debug page
824 824  
825 825  (% style="text-align:center" %)
826 -[[image:1624506710354-406.png||height="658" width="1000" class="img-thumbnail"]]
628 +[[image:1624506710354-406.png||class="img-thumbnail" height="658" width="1000"]]
827 827  
828 828  (% style="text-align:center" %)
829 -[[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]]
631 +[[image:1624506666650-161.png||class="img-thumbnail" height="547" width="1000"]]
830 830  
831 -== **2.6 V-Box connect with AWS platform** ==
633 +== **2.5 V-Box connect with AWS platform** ==
832 832  
833 -=== **Log in AWS** ===
834 -
835 -Login aws account and click“Connect an IoT device”
836 -
837 -[[image:image-20220709165402-1.png]]
838 -
839 -[[image:image-20220709165402-2.png]]
840 -
841 -
842 -=== **Create policy** ===
843 -
844 -Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create”
845 -
846 -[[image:image-20220709165402-3.png]]
847 -
848 -Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create”
849 -
850 -[[image:image-20220709165402-5.png]]
851 -
852 -[[image:image-20220709165402-4.png]]
853 -
854 -{{code language="java"}}
855 -{
856 -
857 -  "Version": "2012-10-17",
858 -
859 -  "Statement": [
860 -
861 -    {
862 -
863 -      "Effect": "Allow",
864 -
865 -      "Action": [
866 -
867 -        "iot:Connect",
868 -
869 -        "iot:Publish",
870 -
871 -        "iot:Subscribe",
872 -
873 -        "iot:Receive",
874 -
875 -        "greengrass:Discover"
876 -
877 -      ],
878 -
879 -      "Resource": "*"
880 -
881 -    }
882 -
883 -  ]
884 -
885 -}
886 -{{/code}}
887 -
888 -=== **Create things** ===
889 -
890 -Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing”
891 -
892 -[[image:image-20220709165402-6.png]]
893 -
894 -[[image:image-20220709165402-7.png]]
895 -
896 -Name the thing~-~-->Click “Next”
897 -
898 -[[image:image-20220709165402-8.png]]
899 -
900 -Select the way to create certificate
901 -
902 -[[image:image-20220709165402-9.png]]
903 -
904 -Select policy
905 -
906 -[[image:image-20220709165402-10.png]]
907 -
908 -[[image:image-20220709165402-11.png]]
909 -
910 -
911 -=== **Test with MQTT.fx tool** ===
912 -
913 -Click “View Setting” to get the “Broker Adress”
914 -
915 -[[image:image-20220709165402-13.png]]
916 -
917 -[[image:image-20220709165402-12.png]]
918 -
919 -Create one connection in MQTT.fx tool, set broker port as 8883.
920 -
921 -[[image:image-20220709165402-14.png]]
922 -
923 -Upload the CA File, Client Certificate File, Client Key File
924 -
925 -[[image:image-20220709165402-15.png]]
926 -
927 -Publish message to topic “TEST”
928 -
929 -[[image:image-20220709165402-17.png]]
930 -
931 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool.
932 -
933 -[[image:image-20220709173500-1.png]]
934 -
935 -And we can also send message form AWS platform to MQTT.fx tool.
936 -
937 -[[image:image-20220709165402-18.png]]
938 -
939 -=== **Configurate in CloudTool** ===
940 -
941 -Copy the same setting in MQTT.fx to MQTT configuration
942 -
943 -[[image:image-20220709165402-19.png]]
944 -
945 - Add a lua script and copy the lua demo into it.
946 -
947 -[[image:image-20220709165402-20.png]]
948 -
949 -sprint = print
950 -
951 -~-~-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)
952 -
953 -local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg()
954 -
955 -~-~-publish to topics
956 -
957 -local pub_RE_TOPIC = string.format('TEST')
958 -
959 -~-~-Subscribe topics
960 -
961 -local Subscribe_RE_TOPIC1 = string.format('TEST')
962 -
963 -~-~-variable
964 -
965 -local last_time = 0
966 -
967 -~-~-Timing main function
968 -
969 -function aws.main()
970 -
971 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start")
972 -
973 - if g_mq then
974 -
975 - if g_mq:isconnected() then
976 -
977 - send_Data()
978 -
979 - else
980 -
981 - if os.time() - last_time > 5 then
982 -
983 - last_time = os.time()
984 -
985 - mymqtt_connect()
986 -
987 - end
988 -
989 - end
990 -
991 - else
992 -
993 - mymqtt_init()
994 -
995 - end
996 -
997 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end")
998 -
999 -end
1000 -
1001 -
1002 -~-~- Initialize MQTT
1003 -
1004 -function mymqtt_init()
1005 -
1006 - sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID))
1007 -
1008 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable
1009 -
1010 - if g_mq then
1011 -
1012 - g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks
1013 -
1014 - sprint("mqtt init success")
1015 -
1016 - else
1017 -
1018 - sprint("mqtt init failed:", err)
1019 -
1020 - end
1021 -
1022 -end
1023 -
1024 -~-~- Connect to MQTT server
1025 -
1026 -function mymqtt_connect()
1027 -
1028 - sprint("mqtt connecting...")
1029 -
1030 - local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART)
1031 -
1032 - if stat == nil then
1033 -
1034 - sprint("mqtt connect failed:", err)
1035 -
1036 - return
1037 -
1038 - else
1039 -
1040 - sprint("mqtt connected")
1041 -
1042 - end
1043 -
1044 - g_mq:subscribe(TEST, 0)
1045 -
1046 -end
1047 -
1048 -~-~- Receive MQTT message callback function
1049 -
1050 -function mymqtt_msg_callback(topic, msg)
1051 -
1052 - print("topic:",topic)
1053 -
1054 - print("revdata:",msg)
1055 -
1056 - local revData = json.decode(msg)
1057 -
1058 - print (revData)
1059 -
1060 - if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud
1061 -
1062 -if string.match(topic,Subscribe_RE_TOPIC1) then
1063 -
1064 - ~-~-if revData ~~= nil then
1065 -
1066 - for k,v in pairs (revData) do
1067 -
1068 - print("printing revdata after kv here")
1069 -
1070 - print (k,v)
1071 -
1072 - end
1073 -
1074 - print ("current state is",fanstate)
1075 -
1076 - ~-~-end
1077 -
1078 -end
1079 -
1080 -end
1081 -
1082 -end
1083 -
1084 -
1085 -~-~-Get real-time data
1086 -
1087 -function getData()
1088 -
1089 - local jdata = {}
1090 -
1091 - local addr = bns_get_alldata()
1092 -
1093 - print(json.encode(addr))
1094 -
1095 - for i,v in pairs(addr) do
1096 -
1097 - if v[2] == 1 then
1098 -
1099 - jdata[v[3]] = v[4]
1100 -
1101 - end
1102 -
1103 - end
1104 -
1105 - return jdata
1106 -
1107 -end
1108 -
1109 -~-~-send data
1110 -
1111 -function send_Data()
1112 -
1113 - local pub_data =
1114 -
1115 - {
1116 -
1117 -123
1118 -
1119 -}
1120 -
1121 -sprint(json.encode(pub_data))
1122 -
1123 -print("..........",pub_RE_TOPIC)
1124 -
1125 - return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0)
1126 -
1127 -end
1128 -
1129 -Get message in AWS
1130 -
1131 -[[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