Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -465,9 +465,8 @@ 465 465 466 466 (% class="mark" %)2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate 467 467 468 - {{info}}468 +(% class="wikigeneratedid" %) 469 469 **✎Note: **Before program the script of MQTT, please make sure the server(MQTT broker) can be connected through MQTT Client tool. 470 -{{/info}} 471 471 472 472 (% class="wikigeneratedid" %) 473 473 Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]** ... ... @@ -515,13 +515,9 @@ 515 515 --initialize mqtt 516 516 function mqtt_init() 517 517 print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID)) 518 - if g_mq then 519 - mqtt.close() --Close mqtt object 520 - end 521 521 g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable 522 522 if g_mq then 523 523 g_mq:on("message", mqtt_msg_callback) -- Register a callback for receiving messages 524 - g_mq:on("offline", mqtt_msg_offline) -- Register a callback for offline 525 525 print("mqtt init success") 526 526 else 527 527 print("mqtt init failed:", err) ... ... @@ -541,11 +541,6 @@ 541 541 g_mq:subscribe(SUBSCRIBE_TOPIC, 0) 542 542 end 543 543 544 ---Offline callback function 545 -function mqtt_msg_offline(cause) 546 - print("mqtt offline, cause:", cause) 547 -end 548 - 549 549 -- Received message callback function 550 550 function mqtt_msg_callback(topic, msg) 551 551 print("topic:", topic) ... ... @@ -584,11 +584,9 @@ 584 584 if g_mq:isconnected() then 585 585 send_data() 586 586 else 587 - --if exceed 5sec not connect, reconnect once588 - if os.time() - LAST_TIME > 5then577 + --if exceed 20 sec not connect, reconnect once 578 + if os.time() - LAST_TIME > 20 then 589 589 LAST_TIME = os.time() 590 - --reinitial the mqtt object 591 - mqtt_init() 592 592 --connect to mqtt or reconnect 593 593 mqtt_connect() 594 594 end ... ... @@ -1246,9 +1246,7 @@ 1246 1246 1247 1247 [[image:image-20220709165402-20.png]] 1248 1248 1249 -{{info}} 1250 -**✎Note:** Before using the following demo script, please make sure the V-Box firmware is newer than 22110701 1251 -{{/info}} 1237 +**Before using the following demo script, please make sure the V-Box firmware is newer than 22110701:** 1252 1252 1253 1253 {{code language="lua"}} 1254 1254 sprint = print