Changes for page 2 Script

Last modified by Devin Chen on 2025/12/10 10:32

From version 8.1
edited by Devin Chen
on 2025/10/30 13:46
Change comment: There is no comment for this version
To version 8.2
edited by Devin Chen
on 2025/11/05 09:27
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -590,7 +590,7 @@
590 590  
591 591  This demo shows how to obtain UTC standard time from the V-Box and get the local time based on the device's time zone.
592 592  
593 -**Register configuration**
593 +**Real-time tags configuration**
594 594  
595 595  [[image:1757043722849-910.png]]
596 596  
... ... @@ -599,11 +599,8 @@
599 599  (% style="text-align:center" %)
600 600  [[image:1757043900216-610.png||height="412" width="439"]]
601 601  
602 -
603 603  **Script**
604 604  
605 -
606 -
607 607  {{code language="lua"}}
608 608  function time.main()
609 609  
... ... @@ -638,6 +638,78 @@
638 638  (% style="text-align:center" %)
639 639  [[image:1757044137457-543.png||height="468" width="708"]]
640 640  
638 +
639 +== **1.13 JSON encoding and decoding** ==
640 +
641 +This demo shows how to encode tag values into JSON format and decode the JSON to assign data to new tags.
642 +
643 +**Real-time tags configuration**
644 +
645 +(% style="text-align:center" %)
646 +[[image:PixPin_2025-11-05_09-21-33.png]]
647 +
648 +(% class="wikigeneratedid" %)
649 +**Script configuration**
650 +
651 +(% style="text-align:center" %)
652 +[[image:PixPin_2025-11-05_09-23-03.png||height="376" width="400"]]
653 +
654 +(% class="wikigeneratedid" %)
655 +**Script**
656 +
657 +{{code language="lua"}}
658 +function json_test.main()
659 +
660 +-- Load JSON module for encoding and decoding JSON data
661 +local json = require("json")
662 +
663 +-- Read values from different types of address tags
664 +local a = addr_getbit("@bit") -- Read a bit (boolean) value
665 +local b = addr_getword("@word") -- Read a word (integer) value
666 +local c = addr_getfloat("@floating number") -- Read a floating point value
667 +local d = addr_getstring("@string",10) -- Read a string value with max length 10
668 +local e = json.null -- JSON null value constant
669 +
670 +-- Encode the data into JSON format
671 +local jsondata = json.encode({
672 + bit = a or 0, -- Bit value with default 0
673 + word = b or 0, -- Word value with default 0
674 + float = c or 0, -- Float value with default 0
675 + str = d or 0, -- String value with default 0
676 + {none= e} -- Nested table with null value
677 + })
678 +print("json encode:", jsondata) -- Print the encoded JSON data
679 +print(".......................")
680 +
681 +-- Decode the JSON string back to Lua table
682 +local data = json.decode(jsondata)
683 +
684 +-- Check if decoding was successful and print the results
685 +if type(data) == 'table' then
686 + print("json decode:")
687 + -- Iterate through all key-value pairs in the decoded table
688 + for k, v in pairs(data) do
689 + print(k, v)
690 + end
691 +end
692 +-- Write the decoded values back to corresponding address tags
693 +addr_setbit("@bit_copy", data["bit"] or 0) -- Write bit value
694 +addr_setword("@word_copy", data["word"] or 0) -- Write word value
695 +addr_setfloat("@floating number_copy", data["float"] or 0) -- Write float value
696 +addr_setstring("@string_copy", data["str"], 10) -- Write string value
697 +
698 +print("-----------------------")
699 +
700 +end
701 +{{/code}}
702 +
703 +(% class="wikigeneratedid" %)
704 +**Result**
705 +
706 +(% style="text-align:center" %)
707 +[[image:1762306008662-362.png||height="485" width="1228"]]
708 +
709 +
641 641  = **2 Third part server** =
642 642  
643 643  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.
1762306008662-362.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +66.9 KB
Content
PixPin_2025-11-05_09-21-33.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +65.8 KB
Content
PixPin_2025-11-05_09-23-03.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +60.9 KB
Content