Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 0 added, 22 removed)
- image-20220709165226-1.png
- image-20220709165402-1.png
- image-20220709165402-10.png
- image-20220709165402-11.png
- image-20220709165402-12.png
- image-20220709165402-13.png
- image-20220709165402-14.png
- image-20220709165402-15.png
- image-20220709165402-16.png
- image-20220709165402-17.png
- image-20220709165402-18.png
- image-20220709165402-19.png
- image-20220709165402-2.png
- image-20220709165402-20.png
- image-20220709165402-21.png
- image-20220709165402-3.png
- image-20220709165402-4.png
- image-20220709165402-5.png
- image-20220709165402-6.png
- image-20220709165402-7.png
- image-20220709165402-8.png
- image-20220709165402-9.png
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. admin1 +XWiki.Hunter - Content
-
... ... @@ -36,34 +36,35 @@ 36 36 37 37 Script is as below: 38 38 39 -{{code language="Lua"}} 39 +(% class="box infomessage" %) 40 +((( 40 40 function sms.main() 41 -------send condition------ 42 +~-~-~-~-~-~-send condition~-~-~-~-~-~- 42 42 local temp1 = addr_getword("@Temperature1") 43 43 local temp2 = addr_getword("@Temperature2") 44 44 local temp3 = addr_getword("@Temperature3") 45 45 local timer = addr_getword("@Timer") 46 46 local tag = addr_getbit("@Tag") 47 -------lasting time------ 48 +~-~-~-~-~-~-lasting time~-~-~-~-~-~- 48 48 if temp1 > 5 and temp2 > 10 and temp3 < 20 then 49 - 50 - 50 + timer = timer + 1 51 + addr_setword("@Timer",timer) 51 51 else 52 - 53 - 53 + timer = 0 54 + addr_setword("@Timer",timer) 54 54 end 55 -------send sms & output Y0------ 56 +~-~-~-~-~-~-send sms & output Y0~-~-~-~-~-~- 56 56 if timer > 5 then 57 - 58 - 59 - 60 - 58 + if tag == 0 then 59 + send_sms_ira("19859254700","alarm trigger") 60 + addr_setbit("@Tag",1) 61 + end 61 61 elseif tag == 1 then 62 62 send_sms_ira("19859254700","alarm release") 63 63 addr_setbit("@Tag",0) 64 64 end 65 65 end 66 - {{/code}}67 +))) 67 67 68 68 == **1.5 Telegram notification** == 69 69 ... ... @@ -159,148 +159,144 @@ 159 159 160 160 Demo1: 161 161 162 -{{code language="Lua"}} 163 --- Meta class 164 ---main 163 +(% class="box infomessage" %) 164 +((( 165 +~-~- Meta class 166 +~-~-main 165 165 function mq.main() 166 - if not mq.m then 167 - local err = "" 168 + if not mq.m then 169 + local err = "" 170 +\\ mq.m, err = mqtt.create("tcp:~/~/grouprobotinfo.com:1883", "ClienID") ~-~- create connection 171 + if mq.m then 172 + mq.config = { 173 + username = "",~-~- ID 174 + password = "",~-~- password 175 + netway = 1, ~-~- Ethernet connection, WIFI=1 176 + ~-~- keepalive = 100, ~-~- Optional, set the connection heartbeat interval for 100 seconds. 177 + ~-~- cleansession = 0, ~-~- Optional, keep session 178 + } 179 + mq.m:on("message", function(topic, msg) ~-~- Register for receiving message callbacks 180 + local str = string.format("%s:%s", topic, msg) 181 + ~-~- print("mqtt msg:", str) ~-~- Print out the received topics and content 182 + end 183 + ) 184 + mq.m:on("offline", function (cause) ~-~- Register for lost connection callbacks 185 + ~-~- addr_setstring("@xxx", "cause"..(cause or " got nil")) 186 + end) 187 + mq.m:on("arrived", function() ~-~- Registration for sending messages to callbacks 188 + print("msg arrived") 189 + end) 190 + else 191 + print("mqtt create failed:", err) ~-~- Create object failed 192 + end 193 + else 194 + if mq.m:isconnected() then ~-~- If online, post a message 195 + local phaseStatus ="unknow" 196 + if addr_getbit("@Standby")== 1 then 197 + phaseStatus = "Standby" 198 + elseif addr_getbit("@Pre-Freeze")==1 then 199 + phaseStatus= "Pre-Freeze" 200 + elseif addr_getbit("@Prepare")==1 then 201 + phaseStatus ="Prepare" 202 + elseif addr_getbit("@Primary Dry")==1 then 203 + phaseStatus = "Primary dry" 204 + elseif addr_getbit("@Secondary Dry")==1 then 205 + phaseStatus = "Secondary Dry" 206 + end 207 +~-~- print(addr_getbit("@Primary Dry")) 208 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-- 209 + local activating ="unknow" 210 + if addr_getbit("@Compressor")==1 then 211 + activating = ",".."Compressor" 212 + end 213 + if addr_getbit("@Silicone Pump")==1 then 214 + activating = activating..",".."Silicone Pump" 215 + end 216 + if addr_getbit("@Vacuum Pump")==1 then 217 + activating = activating..",".."Vacuum Pump" 218 + end 219 + if addr_getbit("@Root Pump")==1 then 220 + activating = activating..",".."Root Pump" 221 + end 222 + if addr_getbit("@Heater")==1 then 223 + activating = activating..",".."Heater" 224 + end 225 + if addr_getbit("@Valve Silicone")==1 then 226 + activating = activating..",".."Valve Silicone" 227 + end 228 + if addr_getbit("@Valve Ice Condenser")==1 then 229 + activating = activating..",".."Valve Ice Condenser" 230 + end 231 + if addr_getbit("@Valve Vacuum Pump")==1 then 232 + activating = activating..",".."Valve Vacuum Pump" 233 + end 234 + local pr_activating =string.sub(activating,2) 235 + ~-~- print(pr_activating) 168 168 169 - mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID") -- create connection 170 - if mq.m then 171 - mq.config = { 172 - username = "",-- ID 173 - password = "",-- password 174 - netway = 1, -- Ethernet connection, WIFI=1 175 - -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds. 176 - -- cleansession = 0, -- Optional, keep session 177 - } 178 - mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks 179 - local str = string.format("%s:%s", topic, msg) 180 - -- print("mqtt msg:", str) -- Print out the received topics and content 181 - end 182 - ) 183 - mq.m:on("offline", function (cause) -- Register for lost connection callbacks 184 - -- addr_setstring("@xxx", "cause"..(cause or " got nil")) 185 - end) 186 - mq.m:on("arrived", function() -- Registration for sending messages to callbacks 187 - print("msg arrived") 188 - end) 189 - else 190 - print("mqtt create failed:", err) -- Create object failed 191 - end 192 - else 193 - if mq.m:isconnected() then -- If online, post a message 194 - local phaseStatus ="unknow" 195 - if addr_getbit("@Standby")== 1 then 196 - phaseStatus = "Standby" 197 - elseif addr_getbit("@Pre-Freeze")==1 then 198 - phaseStatus= "Pre-Freeze" 199 - elseif addr_getbit("@Prepare")==1 then 200 - phaseStatus ="Prepare" 201 - elseif addr_getbit("@Primary Dry")==1 then 202 - phaseStatus = "Primary dry" 203 - elseif addr_getbit("@Secondary Dry")==1 then 204 - phaseStatus = "Secondary Dry" 205 - end 206 --- print(addr_getbit("@Primary Dry")) 207 -------------------------------------------------------------------------------------------------------------------------- 208 - local activating ="unknow" 209 - if addr_getbit("@Compressor")==1 then 210 - activating = ",".."Compressor" 211 - end 212 - if addr_getbit("@Silicone Pump")==1 then 213 - activating = activating..",".."Silicone Pump" 214 - end 215 - if addr_getbit("@Vacuum Pump")==1 then 216 - activating = activating..",".."Vacuum Pump" 217 - end 218 - if addr_getbit("@Root Pump")==1 then 219 - activating = activating..",".."Root Pump" 220 - end 221 - if addr_getbit("@Heater")==1 then 222 - activating = activating..",".."Heater" 223 - end 224 - if addr_getbit("@Valve Silicone")==1 then 225 - activating = activating..",".."Valve Silicone" 226 - end 227 - if addr_getbit("@Valve Ice Condenser")==1 then 228 - activating = activating..",".."Valve Ice Condenser" 229 - end 230 - if addr_getbit("@Valve Vacuum Pump")==1 then 231 - activating = activating..",".."Valve Vacuum Pump" 232 - end 233 - local pr_activating =string.sub(activating,2) 234 - -- print(pr_activating) 235 235 236 - 237 - 238 - local status_text ="unknow" 239 - if addr_getbit("@Status Run")==1 then 240 - status_text = "RUNNING" 241 - else 242 - status_text = "STOP" 243 - end 244 -------------------------------------------------------------------------------------------------------------------------- 245 - 246 - local js = {type="status", 247 - mc_name ="FD300", 248 - status=status_text, 249 - elapsed_time={ 250 - hour=addr_getword("@Elapsed Time (Hour)"), 251 - min=addr_getword("@Elapsed Time (Minute)"), 252 - sec=addr_getword("@Elapsed Time (Second)") 253 - }, 254 - phase = phaseStatus, 255 - step = addr_getword("@Step"), 256 - activating_output = pr_activating, 257 - sv=addr_getshort("@SV Silicone")/10, 258 - pv=addr_getshort("@PV Silicone")/10, 259 - product1=addr_getshort("@Product 1")/10, 260 - 261 - product2=addr_getshort("@Product 2")/10, 262 - product3=addr_getshort("@Product 3")/10, 263 - product4=addr_getshort("@Product 4")/10, 264 - ice1=addr_getshort("@Ice condenser 1")/10, 265 - ice2=addr_getshort("@Ice condenser 2")/10, 266 - vacuum=addr_getfloat("@Vacuum") 267 - 268 - } 269 - local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 270 - ODPC = addr_getbit("@B_25395#W0.01"), 271 - MTPC=addr_getbit("@B_25395#W0.02"), 272 - HTT = addr_getbit("@B_25395#W1.03"), 273 - CPC = addr_getbit("@B_25395#W0.08"), 274 - CPSP =addr_getbit("@B_25395#W1.00"), 275 - CPVP =addr_getbit("@B_25395#W0.10"), 276 - CPRP =addr_getbit("@B_25395#W0.11"), 277 - HP =addr_getbit("@B_25395#W1.01"), 278 - PP= addr_getbit("@B_25395#W1.02"), 279 - PO=addr_getbit("@B_25395#W0.07"), 280 - FSE=addr_getbit("@B_25395#W2.04"), 281 - AVVSVV=addr_getbit("@B_25395#W1.12"), 282 - ICHT=addr_getbit("@B_25395#W3.06") 283 - 284 - } 285 - 286 - -- ("@B_25395#CIO1.02") 287 - mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 288 - mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 289 - else 290 - local stat, err = mq.m:connect(mq.config) -- connection 291 - if stat == nil then --Determine whether to connect 292 - print("mqtt connect failed:", err) 293 - return -- Connection failed, return directly 294 - end 295 - mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics 296 - 297 - end 298 - -- mq.m:unsubscribe("stc/test") 299 - -- mq.m:disconnect() -- close matt 300 - -- mq.m:close() -- close clase 301 - end 238 + local status_text ="unknow" 239 + if addr_getbit("@Status Run")==1 then 240 + status_text = "RUNNING" 241 + else 242 + status_text = "STOP" 243 + end 244 +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-- 245 +\\ local js = {type="status", 246 + mc_name ="FD300", 247 + status=status_text, 248 + elapsed_time={ 249 + hour=addr_getword("@Elapsed Time (Hour)"), 250 + min=addr_getword("@Elapsed Time (Minute)"), 251 + sec=addr_getword("@Elapsed Time (Second)") 252 + }, 253 + phase = phaseStatus, 254 + step = addr_getword("@Step"), 255 + activating_output = pr_activating, 256 + sv=addr_getshort("@SV Silicone")/10, 257 + pv=addr_getshort("@PV Silicone")/10, 258 + product1=addr_getshort("@Product 1")/10, 259 + 260 + product2=addr_getshort("@Product 2")/10, 261 + product3=addr_getshort("@Product 3")/10, 262 + product4=addr_getshort("@Product 4")/10, 263 + ice1=addr_getshort("@Ice condenser 1")/10, 264 + ice2=addr_getshort("@Ice condenser 2")/10, 265 + vacuum=addr_getfloat("@Vacuum") 266 + 267 + } 268 + local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 269 + ODPC = addr_getbit("@B_25395#W0.01"), 270 + MTPC=addr_getbit("@B_25395#W0.02"), 271 + HTT = addr_getbit("@B_25395#W1.03"), 272 + CPC = addr_getbit("@B_25395#W0.08"), 273 + CPSP =addr_getbit("@B_25395#W1.00"), 274 + CPVP =addr_getbit("@B_25395#W0.10"), 275 + CPRP =addr_getbit("@B_25395#W0.11"), 276 + HP =addr_getbit("@B_25395#W1.01"), 277 + PP= addr_getbit("@B_25395#W1.02"), 278 + PO=addr_getbit("@B_25395#W0.07"), 279 + FSE=addr_getbit("@B_25395#W2.04"), 280 + AVVSVV=addr_getbit("@B_25395#W1.12"), 281 + ICHT=addr_getbit("@B_25395#W3.06") 282 + 283 + } 284 +\\ ~-~- ("@B_25395#CIO1.02") 285 + mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 286 + mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 287 + else 288 + local stat, err = mq.m:connect(mq.config) ~-~- connection 289 + if stat == nil then ~-~-Determine whether to connect 290 + print("mqtt connect failed:", err) 291 + return ~-~- Connection failed, return directly 292 + end 293 + mq.m:subscribe("mqtt-v-box-epsilon", 0)~-~- Subscribe to topics 294 +\\ end 295 + ~-~- mq.m:unsubscribe("stc/test") 296 + ~-~- mq.m:disconnect() ~-~- close matt 297 + ~-~- mq.m:close() ~-~- close clase 298 + end 302 302 end 303 - {{/code}}300 +))) 304 304 305 305 == **2.2 V-Box connect with Azure platform** == 306 306 ... ... @@ -312,133 +312,125 @@ 312 312 313 313 Script is as below 314 314 315 -{{code language="Lua"}} 316 ---https://support.huaweicloud.com/qs-IoT/iot_05_0005.html mqtt.fx monitor to connect azure iot 312 +(% class="box infomessage" %) 313 +((( 314 +~-~-https:~/~/support.huaweicloud.com/qs-IoT/iot_05_0005.html mqtt.fx monitor to connect azure iot 317 317 sprint = print 318 318 319 ---Get custom configuration parameters (vbox custom information) 320 ---local CUSTOM = bns_get_config("bind") 321 ---local DS_ID = CUSTOM.DSID or "60a71ccbbbe12002c08f3a1a_WECON" 317 +~-~-Get custom configuration parameters (vbox custom information) 318 +~-~-local CUSTOM = bns_get_config("bind") 319 +~-~-local DS_ID = CUSTOM.DSID or "60a71ccbbbe12002c08f3a1a_WECON" 322 322 323 323 324 - 325 ---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) 322 +~-~-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) 326 326 local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg() 327 327 328 ---MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON' 329 ---MQTT_CFG.password='wecon123' 330 ---MQTT_CLIENTID = '60a71ccbbbe12002c08f3a1a_WECON_0_0_2021052110usernxame:60a71ccbbbe12002c08f3a1a_WECONpassword:a0a951581855aa8e0262129da6cf1b43f2c0ecfac4fa56117fc5a20c90be169a' 325 +~-~-MQTT_CFG.username = '60a71ccbbbe12002c08f3a1a_WECON' 326 +~-~-MQTT_CFG.password='wecon123' 327 +~-~-MQTT_CLIENTID = '60a71ccbbbe12002c08f3a1a_WECON_0_0_2021052110usernxame:60a71ccbbbe12002c08f3a1a_WECONpassword:a0a951581855aa8e0262129da6cf1b43f2c0ecfac4fa56117fc5a20c90be169a' 331 331 332 ---publish to topics 329 +~-~-publish to topics 333 333 local pub_RE_TOPIC = string.format('devices/wecon_02/messages/events/') 334 ---Subscribe topics 331 +~-~-Subscribe topics 335 335 local Subscribe_RE_TOPIC1 = string.format('devices/wecon_02/messages/devicebound/#') 336 336 337 ---variable 334 +~-~-variable 338 338 local last_time = 0 339 339 340 340 341 - 342 ---Timing main function 338 +~-~-Timing main function 343 343 function Azure.main() 344 344 345 - 346 - 347 - 348 - 349 - 350 - 351 - 352 - 353 - 354 - 355 - 356 - 357 - 358 - 341 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main start") 342 + if g_mq then 343 + if g_mq:isconnected() then 344 + send_Data() 345 + else 346 + if os.time() - last_time > 20 then 347 + last_time = os.time() 348 + mymqtt_connect() 349 + end 350 + end 351 + else 352 + mymqtt_init() 353 + end 354 + sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " Azureiot.main end") 359 359 end 360 360 361 --- Initialize MQTT 357 +~-~- Initialize MQTT 362 362 function mymqtt_init() 363 - 364 - 365 - 366 - 367 - 368 - 369 - 370 - 359 + sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID)) 360 + g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable 361 + if g_mq then 362 + g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks 363 + sprint("mqtt init success") 364 + else 365 + sprint("mqtt init failed:", err) 366 + end 371 371 end 372 372 373 --- Connect to MQTT server 369 +~-~- Connect to MQTT server 374 374 function mymqtt_connect() 375 - 376 - 377 - 378 - 379 - 380 - 381 - 382 - 383 - 371 + sprint("mqtt connecting...") 372 + local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART) 373 + if stat == nil then 374 + sprint("mqtt connect failed:", err) 375 + return 376 + else 377 + sprint("mqtt connected") 378 + end 379 + g_mq:subscribe(Subscribe_RE_TOPIC1, 0) 384 384 end 385 385 386 --- Receive MQTT message callback function 382 +~-~- Receive MQTT message callback function 387 387 function mymqtt_msg_callback(topic, msg) 388 - 389 - 390 - 391 - 392 --- if string.match(topic,Subscribe_RE_TOPIC1) then 393 - 394 - 395 - 384 + print("topic:",topic) 385 + print("revdata:",msg) 386 + ~-~- local revData = json.decode(msg) 387 + ~-~- if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud 388 +~-~- if string.match(topic,Subscribe_RE_TOPIC1) then 389 + ~-~- print("topi11:",topic) 390 + setValue(revData) 391 + ~-~- end 396 396 end 397 397 398 ---Process the received data 399 ---function setValue(revData) 400 - 401 - 402 - 403 - 404 - 405 ---end 394 +~-~-Process the received data 395 +~-~-function setValue(revData) 396 + ~-~- if revData ~~=nil then 397 + ~-~- for i,v in pairs(revData) do 398 + ~-~- print("Data received:",i,v) 399 + ~-~- end 400 + ~-~- end 401 +~-~-end 406 406 407 ---Get real-time data 403 +~-~-Get real-time data 408 408 function getData() 409 - 410 - 411 - 412 - 413 - 414 - 415 - 416 - 417 - 418 -end 405 + local jdata = {} 406 + local addr = bns_get_alldata() 407 + print(json.encode(addr)) 408 + for i,v in pairs(addr) do 409 + if v[2] == 1 then 410 + jdata[v[3]] = v[4] 411 + end 412 + end 413 + return jdata 414 +end 419 419 420 420 421 - 422 ---send data 417 +~-~-send data 423 423 function send_Data() 424 - local pub_data = {100 425 - -- services={{ 426 - 427 - --serviceId ='Temperature', 428 - -- properties={ 429 - -- value = 55 430 - -- }, 431 - -- }} 419 + local pub_data = {100 420 + ~-~- services=~{~{ 421 +\\ ~-~-serviceId ='Temperature', 422 + ~-~- properties={ 423 + ~-~- value = 55 424 + ~-~- }, 425 + ~-~- }} 432 432 } 433 433 sprint(json.encode(pub_data)) 434 434 print("..........",pub_RE_TOPIC) 435 - 429 + return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0) 436 436 end 437 -{{/code}} 438 - 439 -(% class="box infomessage" %) 440 -((( 441 - 442 442 ))) 443 443 444 444 == **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)** == ... ... @@ -713,348 +713,4 @@ 713 713 714 714 == **2.5 V-Box connect with AWS platform** == 715 715 716 -=== **Log in AWS** === 717 - 718 -Login aws account and click“Connect an IoT device” 719 - 720 -[[image:image-20220709165402-1.png]] 721 - 722 -[[image:image-20220709165402-2.png]] 723 - 724 - 725 -=== **Create policy** === 726 - 727 -Click “Secure”~-~-->“Policies”~-~-->“Create policy”~-~-->Click “Create” 728 - 729 -[[image:image-20220709165402-3.png]] 730 - 731 -Name the policy~-~-->Click “JSON”~-~-->Copy the following content~-~-->Click “Create” 732 - 733 -[[image:image-20220709165402-5.png]] 734 - 735 -[[image:image-20220709165402-4.png]] 736 - 737 -{{code language="java"}} 738 -{ 739 - 740 - "Version": "2012-10-17", 741 - 742 - "Statement": [ 743 - 744 - { 745 - 746 - "Effect": "Allow", 747 - 748 - "Action": [ 749 - 750 - "iot:Connect", 751 - 752 - "iot:Publish", 753 - 754 - "iot:Subscribe", 755 - 756 - "iot:Receive", 757 - 758 - "greengrass:Discover" 759 - 760 - ], 761 - 762 - "Resource": "*" 763 - 764 - } 765 - 766 - ] 767 - 768 -} 769 -{{/code}} 770 - 771 -1. **Create things** 772 - 773 -Click “Manage”~-~-->“Things”~-~-->“Create things”~-~-->“Create single thing” 774 - 775 - 776 -| 777 -| |[[image:image-20220709165402-6.png]] 778 - 779 -| 780 -| |[[image:image-20220709165402-7.png]] 781 - 782 -| 783 -| |[[image:image-20220709165402-8.png]] 784 - 785 -Name the thing~-~-->Click “Next” 786 - 787 - 788 -Select the way to create certificate 789 - 790 - 791 -| 792 -| |[[image:image-20220709165402-9.png]] 793 - 794 -Select policy 795 - 796 - 797 -| 798 -| |[[image:image-20220709165402-10.png]] 799 - 800 - 801 - 802 - 803 - 804 - 805 - 806 - 807 -| 808 -| |[[image:image-20220709165402-11.png]] 809 - 810 - 811 - 812 - 813 - 814 -1. **Test with MQTT.fx tool** 815 - 816 -Click “View Setting” to get the “Broker Adress” 817 - 818 - 819 -| 820 -| |[[image:image-20220709165402-12.png]] 821 - 822 -| 823 -| |[[image:image-20220709165402-13.png]] 824 - 825 - 826 - 827 - 828 - 829 - 830 - 831 -| 832 -| |[[image:image-20220709165402-14.png]] 833 - 834 -Create one connection in MQTT.fx tool, set broker port as 8883. 835 - 836 -Upload the CA File, Client Certificate File, Client Key File 837 - 838 - 839 -| 840 -| |[[image:image-20220709165402-15.png]] 841 - 842 -Publish message to topic “TEST” 843 - 844 - 845 -| 846 -| |[[image:image-20220709165402-16.png]] 847 - 848 -| 849 -| |[[image:image-20220709165402-17.png]] 850 - 851 -Click”Test”~-~-->”MQTT test client”~-~-->”Subscrible to a topic”, to get message publish from MQTT.fx tool. 852 - 853 -And we can also send message form AWS platform to MQTT.fx tool. 854 - 855 - 856 -| 857 -| |[[image:image-20220709165402-18.png]] 858 - 859 -1. **Configurate in CloudTool** 860 - 861 -Copy the same setting in MQTT.fx to MQTT configuration 862 - 863 - 864 -| 865 -| |[[image:image-20220709165402-19.png]] 866 - 867 - Add a lua script and copy the lua demo into it. 868 - 869 - 870 -| 871 -| |[[image:image-20220709165402-20.png]] 872 - 873 - 874 -sprint = print 875 - 876 -~-~-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) 877 - 878 -local MQTT_URL, MQTT_CLIENTID, MQTT_CFG, MQTT_LWT, MQTT_CART = mqtt.setup_cfg() 879 - 880 -~-~-publish to topics 881 - 882 -local pub_RE_TOPIC = string.format('TEST') 883 - 884 -~-~-Subscribe topics 885 - 886 -local Subscribe_RE_TOPIC1 = string.format('TEST') 887 - 888 -~-~-variable 889 - 890 -local last_time = 0 891 - 892 -~-~-Timing main function 893 - 894 -function aws.main() 895 - 896 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main start") 897 - 898 - if g_mq then 899 - 900 - if g_mq:isconnected() then 901 - 902 - send_Data() 903 - 904 - else 905 - 906 - if os.time() - last_time > 5 then 907 - 908 - last_time = os.time() 909 - 910 - mymqtt_connect() 911 - 912 - end 913 - 914 - end 915 - 916 - else 917 - 918 - mymqtt_init() 919 - 920 - end 921 - 922 - sprint(os.date("%Y-%m-%d %H:%M %S", os.time()) .. " aws.main end") 923 - 924 -end 925 - 926 - 927 -~-~- Initialize MQTT 928 - 929 -function mymqtt_init() 930 - 931 - sprint(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENTID)) 932 - 933 - g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENTID) ~-~- Create the object and declare it as a global variable 934 - 935 - if g_mq then 936 - 937 - g_mq:on("message", mymqtt_msg_callback) ~-~- Register to receive message callbacks 938 - 939 - sprint("mqtt init success") 940 - 941 - else 942 - 943 - sprint("mqtt init failed:", err) 944 - 945 - end 946 - 947 -end 948 - 949 -~-~- Connect to MQTT server 950 - 951 -function mymqtt_connect() 952 - 953 - sprint("mqtt connecting...") 954 - 955 - local stat, err = g_mq:connect(MQTT_CFG,MQTT_LWT, MQTT_CART) 956 - 957 - if stat == nil then 958 - 959 - sprint("mqtt connect failed:", err) 960 - 961 - return 962 - 963 - else 964 - 965 - sprint("mqtt connected") 966 - 967 - end 968 - 969 - g_mq:subscribe(TEST, 0) 970 - 971 -end 972 - 973 -~-~- Receive MQTT message callback function 974 - 975 -function mymqtt_msg_callback(topic, msg) 976 - 977 - print("topic:",topic) 978 - 979 - print("revdata:",msg) 980 - 981 - local revData = json.decode(msg) 982 - 983 - print (revData) 984 - 985 - if topic == Subscribe_RE_TOPIC1 then ~-~-Process topic information subscribed from the cloud 986 - 987 -if string.match(topic,Subscribe_RE_TOPIC1) then 988 - 989 - ~-~-if revData ~~= nil then 990 - 991 - for k,v in pairs (revData) do 992 - 993 - print("printing revdata after kv here") 994 - 995 - print (k,v) 996 - 997 - end 998 - 999 - print ("current state is",fanstate) 1000 - 1001 - ~-~-end 1002 - 1003 -end 1004 - 1005 -end 1006 - 1007 -end 1008 - 1009 - 1010 -~-~-Get real-time data 1011 - 1012 -function getData() 1013 - 1014 - local jdata = {} 1015 - 1016 - local addr = bns_get_alldata() 1017 - 1018 - print(json.encode(addr)) 1019 - 1020 - for i,v in pairs(addr) do 1021 - 1022 - if v[2] == 1 then 1023 - 1024 - jdata[v[3]] = v[4] 1025 - 1026 - end 1027 - 1028 - end 1029 - 1030 - return jdata 1031 - 1032 -end 1033 - 1034 -~-~-send data 1035 - 1036 -function send_Data() 1037 - 1038 - local pub_data = 1039 - 1040 - { 1041 - 1042 -123 1043 - 1044 -} 1045 - 1046 -sprint(json.encode(pub_data)) 1047 - 1048 -print("..........",pub_RE_TOPIC) 1049 - 1050 - return g_mq:publish(pub_RE_TOPIC, json.encode(pub_data), 0, 0) 1051 - 1052 -end 1053 - 1054 - 1055 - 1056 -Get message in AWS 1057 - 1058 - 1059 -| 1060 -| |[[image:image-20220709165402-21.png]] 705 +[[https:~~/~~/ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/AWS/AWS.zip>>https://ftp.we-con.com.cn/Download/WIKI/V-BOX/Demo/AWS/AWS.zip]]
- image-20220709165226-1.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.Jim - Size
-
... ... @@ -1,1 +1,0 @@ 1 -1.2 MB - Content
- 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