Changes for page 2 Script
Last modified by Devin Chen on 2025/12/10 10:32
From version 5.1
edited by Devin Chen
on 2025/09/09 11:17
on 2025/09/09 11:17
Change comment:
There is no comment for this version
To version 10.2
edited by Devin Chen
on 2025/12/10 10:32
on 2025/12/10 10:32
Change comment:
Update document after refactoring.
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 4 added, 0 removed)
Details
- Page properties
-
- Parent
-
... ... @@ -1,1 +1,1 @@ 1 -V- BOX.V-Net.Training.WebHome1 +V-Net 2\.0.Demo.WebHome - Content
-
... ... @@ -27,12 +27,12 @@ 27 27 28 28 == **1.4 Short message** == 29 29 30 -The following demo shows that when the alarm condition is reached: temp1 > 5 & temp2 >10& temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms.30 +The following demo shows that when the alarm condition is reached: temp1 > 50 (lasts more than 5 seconds) , then send an "alarm trigger" sms. 31 31 32 32 When the alarm condition is released,then send an "alarm release" sms. 33 33 34 -Re gisters setting35 - \\[[image:1757387490907-390.png]]34 +Real-time tags setting 35 +[[image:1757401730077-284.png]] 36 36 37 37 Script is as below: 38 38 ... ... @@ -39,35 +39,51 @@ 39 39 {{code language="lua"}} 40 40 function sms.main() 41 41 ------send condition------ 42 -local temp1 = addr_getword("@Temperature1") 43 -local temp2 = addr_getword("@Temperature2") 44 -local temp3 = addr_getword("@Temperature3") 45 -local timer = addr_getword("@Timer") 46 -local tag = addr_getbit("@Tag") 47 -------lasting time------ 48 -if temp1 > 5 and temp2 > 10 and temp3 < 20 then 49 - timer = timer + 1 50 - addr_setword("@Timer",timer) 51 -else 52 - timer = 0 53 - addr_setword("@Timer",timer) 54 -end 55 -------send sms & output Y0------ 56 -if timer > 5 then 57 - if tag == 0 then 58 - --send SMS to 2 recipients 59 - send_sms_ira("198****4700","alarm trigger") 60 - local id = send_sms_ira("187****3130","alarm trigger") 61 - --get the SMS state from ID 62 - local state = sms_get_state(id) 63 - addr_setword("@state",state) 64 - addr_setbit("@Tag",1) 42 + local temp1 = addr_getword("@Temperature1") 43 + local timer = addr_getword("@Timer") 44 + local tag = addr_getbit("@Tag") 45 + local tag2 = addr_getbit("@Y0") 46 + local sms_timer = addr_getword("@SMSTimer") 47 + local sms_id = addr_getword("@id") -- SMS ID 48 + 49 + ------lasting time------ 50 + if temp1 > 50 then 51 + timer = timer + 1 52 + addr_setword("@Timer", timer) 53 + else 54 + timer = 0 55 + addr_setword("@Timer", timer) 65 65 end 66 -elseif tag == 1 then 67 -send_sms_ira("198****4700","alarm release") 68 -addr_setbit("@Tag",0) 57 + 58 + ------send sms & output Y0------ 59 + if timer > 5 then 60 + if tag == 0 then 61 + --send SMS to 2 number 62 + local id = send_sms_ira("198****4800", "alarm trigger") 63 + local id = send_sms_ira("187****3130", "alarm trigger") 64 + addr_setword("@id", id) -- Store SMS ID to dedicated variable 65 + addr_setbit("@Tag", 1) 66 + addr_setword("@SMSTimer", 0) -- Reset SMS status check timer 67 + else 68 + -- If SMS already sent, increment timer 69 + sms_timer = sms_timer + 1 70 + addr_setword("@SMSTimer", sms_timer) 71 + 72 + -- Check SMS status after 20 seconds 73 + if sms_timer >= 20 then 74 + local state = sms_get_state(sms_id) 75 + addr_setword("@state", state) 76 + addr_setword("@SMSTimer", 0) -- Reset timer 77 + end 78 + end 79 + elseif tag == 1 then 80 + -- Send alarm release SMS 81 + send_sms_ira("198****4800","alarm release") 82 + send_sms_ira("187****3130", "alarm release") 83 + addr_setbit("@Tag", 0) 84 + addr_setword("@SMSTimer", 0) -- Reset timer 85 + end 69 69 end 70 -end 71 71 {{/code}} 72 72 73 73 == **1.5 Telegram notification** == ... ... @@ -574,7 +574,7 @@ 574 574 575 575 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. 576 576 577 -**Re gisterconfiguration**593 +**Real-time tags configuration** 578 578 579 579 [[image:1757043722849-910.png]] 580 580 ... ... @@ -583,11 +583,8 @@ 583 583 (% style="text-align:center" %) 584 584 [[image:1757043900216-610.png||height="412" width="439"]] 585 585 586 - 587 587 **Script** 588 588 589 - 590 - 591 591 {{code language="lua"}} 592 592 function time.main() 593 593 ... ... @@ -622,6 +622,77 @@ 622 622 (% style="text-align:center" %) 623 623 [[image:1757044137457-543.png||height="468" width="708"]] 624 624 638 +== **1.13 JSON encoding and decoding** == 639 + 640 +This demo shows how to encode tag values into JSON format and decode the JSON to assign data to new tags. 641 + 642 +**Real-time tags configuration** 643 + 644 +(% style="text-align:center" %) 645 +[[image:PixPin_2025-11-05_09-21-33.png]] 646 + 647 +(% class="wikigeneratedid" %) 648 +**Script configuration** 649 + 650 +(% style="text-align:center" %) 651 +[[image:PixPin_2025-11-05_09-23-03.png||height="376" width="400"]] 652 + 653 +(% class="wikigeneratedid" %) 654 +**Script** 655 + 656 +{{code language="lua"}} 657 +function json_test.main() 658 + 659 +-- Load JSON module for encoding and decoding JSON data 660 +local json = require("json") 661 + 662 +-- Read values from different types of address tags 663 +local a = addr_getbit("@bit") -- Read a bit (boolean) value 664 +local b = addr_getword("@word") -- Read a word (integer) value 665 +local c = addr_getfloat("@floating number") -- Read a floating point value 666 +local d = addr_getstring("@string",10) -- Read a string value with max length 10 667 +local e = json.null -- JSON null value constant 668 + 669 +-- Encode the data into JSON format 670 +local jsondata = json.encode({ 671 + bit = a or 0, -- Bit value with default 0 672 + word = b or 0, -- Word value with default 0 673 + float = c or 0, -- Float value with default 0 674 + str = d or 0, -- String value with default 0 675 + {none= e} -- Nested table with null value 676 + }) 677 +print("json encode:", jsondata) -- Print the encoded JSON data 678 +print(".......................") 679 + 680 +-- Decode the JSON string back to Lua table 681 +local data = json.decode(jsondata) 682 + 683 +-- Check if decoding was successful and print the results 684 +if type(data) == 'table' then 685 + print("json decode:") 686 + -- Iterate through all key-value pairs in the decoded table 687 + for k, v in pairs(data) do 688 + print(k, v) 689 + end 690 +end 691 +-- Write the decoded values back to corresponding address tags 692 +addr_setbit("@bit_copy", data["bit"] or 0) -- Write bit value 693 +addr_setword("@word_copy", data["word"] or 0) -- Write word value 694 +addr_setfloat("@floating number_copy", data["float"] or 0) -- Write float value 695 +addr_setstring("@string_copy", data["str"], 10) -- Write string value 696 + 697 +print("-----------------------") 698 + 699 +end 700 +{{/code}} 701 + 702 +(% class="wikigeneratedid" %) 703 +**Result** 704 + 705 +(% style="text-align:center" %) 706 +[[image:1762306008662-362.png||height="485" width="1228"]] 707 + 708 + 625 625 = **2 Third part server** = 626 626 627 627 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.
- 1757401730077-284.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.DevinChen - Size
-
... ... @@ -1,0 +1,1 @@ 1 +92.2 KB - Content
- 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