Changes for page 2 Script
Last modified by Devin Chen on 2025/12/10 10:32
From version 2.1
edited by Devin Chen
on 2025/09/05 11:50
on 2025/09/05 11:50
Change comment:
There is no comment for this version
To version 9.1
edited by Devin Chen
on 2025/11/05 09:27
on 2025/11/05 09:27
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Attachments (0 modified, 5 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,6 +4,3 @@ 1 -= = 2 - 3 - 4 4 = **1 General Script Demo** = 5 5 6 6 == **1.1 Address Operation** == ... ... @@ -30,37 +30,63 @@ 30 30 31 31 == **1.4 Short message** == 32 32 33 -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. 34 34 35 -When the alarm condition is released,then send an "alarm release" sms. Script is as below:32 +When the alarm condition is released,then send an "alarm release" sms. 36 36 34 +Real-time tags setting 35 +[[image:1757401730077-284.png]] 36 + 37 +Script is as below: 38 + 37 37 {{code language="lua"}} 38 38 function sms.main() 39 39 ------send condition------ 40 -local temp1 = addr_getword("@Temperature1") 41 -local temp2 = addr_getword("@Temperature2") 42 -local temp3 = addr_getword("@Temperature3") 43 -local timer = addr_getword("@Timer") 44 -local tag = addr_getbit("@Tag") 45 -------lasting time------ 46 -if temp1 > 5 and temp2 > 10 and temp3 < 20 then 47 - timer = timer + 1 48 - addr_setword("@Timer",timer) 49 -else 50 - timer = 0 51 - addr_setword("@Timer",timer) 52 -end 53 -------send sms & output Y0------ 54 -if timer > 5 then 55 - if tag == 0 then 56 - send_sms_ira("19859254700","alarm trigger") 57 - 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) 58 58 end 59 -elseif tag == 1 then 60 -send_sms_ira("19859254700","alarm release") 61 -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 62 62 end 63 -end 64 64 {{/code}} 65 65 66 66 == **1.5 Telegram notification** == ... ... @@ -563,11 +563,11 @@ 563 563 end 564 564 {{/code}} 565 565 566 -= **1.12 Get UTC timestamp and local timezone timestamp** = 589 +== **1.12 Get UTC timestamp and local timezone timestamp** == 567 567 568 568 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. 569 569 570 -**Re gisterconfiguration**593 +**Real-time tags configuration** 571 571 572 572 [[image:1757043722849-910.png]] 573 573 ... ... @@ -576,11 +576,8 @@ 576 576 (% style="text-align:center" %) 577 577 [[image:1757043900216-610.png||height="412" width="439"]] 578 578 579 - 580 580 **Script** 581 581 582 - 583 - 584 584 {{code language="lua"}} 585 585 function time.main() 586 586 ... ... @@ -615,6 +615,78 @@ 615 615 (% style="text-align:center" %) 616 616 [[image:1757044137457-543.png||height="468" width="708"]] 617 617 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 + 618 618 = **2 Third part server** = 619 619 620 620 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.
- 1757387490907-390.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.DevinChen - Size
-
... ... @@ -1,0 +1,1 @@ 1 +47.9 KB - Content
- 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