Changes for page 2 Script

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

From version 49.1
edited by Hunter
on 2023/05/06 10:09
Change comment: There is no comment for this version
To version 37.1
edited by Hunter
on 2023/01/03 09:36
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -447,37 +447,6 @@
447 447  end
448 448  {{/code}}
449 449  
450 -== **1.9 High-Low Byte Switch** ==
451 -
452 -The following example is converting the floating number from order 1234 to order 3412, and formating output the number with 2 decimal point. About which high-low word order corresponding to which value, please refer to the [[Address Operation Table>>doc:V-BOX.V-Net.Manual.04 Lua Script.01 Lua Functions.WebHome||anchor="H2Addressoperation"]].
453 -
454 -{{code language="lua"}}
455 -function highLowByteSwitch(floatNumber)
456 - addr_setfloat("@W_0#HDW23036",floatNumber,0,2)
457 - local newFloat = addr_getfloat("@W_0#HDW23036")
458 - local formattedFloat = string.format("%.2f",newFloat)
459 - print("The formatted float value is the : "..formattedFloat)
460 - return formattedFloat
461 -end
462 -{{/code}}
463 -
464 -== **1.10 Read 64bits Unsigned Value** ==
465 -
466 -In our built-in function library doesn't have the function for reading 64-bit unsigned format value, so the following function is for solve this. But if the number is greater 2^53, the precision will be lost. So the final result will be a little bit different from the original value.
467 -
468 -{{code language="lua"}}
469 -function addr_getquatra(address)
470 - local highAddress = addr_newnoaddr(address,2)
471 - local low32 = addr_getdword(address)
472 - local high32 = addr_getdword(highAddress)
473 - --print("the low number is "..low32)
474 - --print("the high number is "..high32)
475 - local formatVal = string.format("%64.0f",2^32*high32+low32)
476 - print("the format value is ".. formatVal)
477 - return formatVal
478 -end
479 -{{/code}}
480 -
481 481  = **2 V-Box connect with third part server** =
482 482  
483 483  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.
... ... @@ -496,9 +496,8 @@
496 496  
497 497  (% class="mark" %)2.If your server requires SSL certificate to log in,please use OpenCloud.Because only OpenCloud platform can support to upload certificate
498 498  
499 -{{info}}
468 +(% class="wikigeneratedid" %)
500 500  **✎Note: **Before program the script of MQTT, please make sure the server(MQTT broker) can be connected through MQTT Client tool.
501 -{{/info}}
502 502  
503 503  (% class="wikigeneratedid" %)
504 504  Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]**
... ... @@ -505,25 +505,6 @@
505 505  
506 506  == **2.1 V-Box connect with test server(General Example)** ==
507 507  
508 -The following example is trying to publish to the topic "testtopic/test/no1/7890", and subscribe the topic "testtopic/test/no1/123456".
509 -
510 -And the JSON message is like follows:
511 -
512 -{{code language="JSON"}}
513 -{
514 - "timestamp": 1631152760,
515 - "messageId": 1,
516 - "event": "test_data",
517 - "mfrs": "HMI/box",
518 - "data":
519 - {
520 - "id" : 1436217747670454274,
521 - "waterlevel" : 48,
522 - "temperture" : 23
523 - }
524 -}
525 -{{/code}}
526 -
527 527  {{code language="lua"}}
528 528  --MQTT configuration table
529 529  local MQTT_CFG={}
... ... @@ -565,13 +565,9 @@
565 565  --initialize mqtt
566 566  function mqtt_init()
567 567   print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID))
568 - if g_mq then
569 - mqtt.close() --Close mqtt object
570 - end
571 571   g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable
572 572   if g_mq then
573 573   g_mq:on("message", mqtt_msg_callback) -- Register a callback for receiving messages
574 - g_mq:on("offline", mqtt_msg_offline) -- Register a callback for offline
575 575   print("mqtt init success")
576 576   else
577 577   print("mqtt init failed:", err)
... ... @@ -591,11 +591,6 @@
591 591   g_mq:subscribe(SUBSCRIBE_TOPIC, 0)
592 592  end
593 593  
594 ---Offline callback function
595 -function mqtt_msg_offline(cause)
596 - print("mqtt offline, cause:", cause)
597 -end
598 -
599 599  -- Received message callback function
600 600  function mqtt_msg_callback(topic, msg)
601 601   print("topic:", topic)
... ... @@ -634,11 +634,9 @@
634 634   if g_mq:isconnected() then
635 635   send_data()
636 636   else
637 - --if exceed 5 sec not connect, reconnect once
638 - if os.time() - LAST_TIME > 5 then
577 + --if exceed 20 sec not connect, reconnect once
578 + if os.time() - LAST_TIME > 20 then
639 639   LAST_TIME = os.time()
640 - --reinitial the mqtt object
641 - mqtt_init()
642 642   --connect to mqtt or reconnect
643 643   mqtt_connect()
644 644   end