Changes for page 2 Script

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

From version 1.1
edited by Wecon
on 2025/09/03 21:04
Change comment: Imported from XAR
To version 6.1
edited by Devin Chen
on 2025/09/09 15:10
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Wecon
1 +XWiki.DevinChen
Content
... ... @@ -29,35 +29,61 @@
29 29  
30 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.
31 31  
32 -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.
33 33  
34 +Registers setting
35 +[[image:1757401730077-284.png]]
36 +
37 +Script is as below:
38 +
34 34  {{code language="lua"}}
35 35  function sms.main()
36 36  ------send condition------
37 -local temp1 = addr_getword("@Temperature1")
38 -local temp2 = addr_getword("@Temperature2")
39 -local temp3 = addr_getword("@Temperature3")
40 -local timer = addr_getword("@Timer")
41 -local tag = addr_getbit("@Tag")
42 -------lasting time------
43 -if temp1 > 5 and temp2 > 10 and temp3 < 20 then
44 - timer = timer + 1
45 - addr_setword("@Timer",timer)
46 -else
47 - timer = 0
48 - addr_setword("@Timer",timer)
49 -end
50 -------send sms & output Y0------
51 -if timer > 5 then
52 - if tag == 0 then
53 - send_sms_ira("19859254700","alarm trigger")
54 - 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)
55 55   end
56 -elseif tag == 1 then
57 -send_sms_ira("19859254700","alarm release")
58 -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
59 59  end
60 -end
61 61  {{/code}}
62 62  
63 63  == **1.5 Telegram notification** ==
... ... @@ -560,6 +560,58 @@
560 560  end
561 561  {{/code}}
562 562  
589 +== **1.12 Get UTC timestamp and local timezone timestamp** ==
590 +
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 +
593 +**Register configuration**
594 +
595 +[[image:1757043722849-910.png]]
596 +
597 +**Script configuration**
598 +
599 +(% style="text-align:center" %)
600 +[[image:1757043900216-610.png||height="412" width="439"]]
601 +
602 +
603 +**Script**
604 +
605 +
606 +
607 +{{code language="lua"}}
608 +function time.main()
609 +
610 + --Get Coordinated Universal Time
611 + local timestamp = os.time()
612 + local utcTimeTable = os.date("!*t", timestamp)
613 + local utcTimestamp = os.time(utcTimeTable)
614 + local formattedTime = os.date("%Y-%m-%d %H:%M:%S", utcTimestamp)
615 +
616 + print("UTC: " ..formattedTime)
617 +
618 + --Calculate the local time at the device's location
619 + local utc_7Timestamp = os.time(utcTimeTable) + 25200 -- Enter the corresponding number of seconds based on the time difference,used UTC+7 as an example..
620 + local formattedTime1 = os.date("%Y-%m-%d %H:%M:%S", utc_7Timestamp)
621 + print("UTC+7: " .. formattedTime1)
622 +
623 +
624 + --Assign the decomposed timestamp to the specified register
625 + addr_setword("@UTC+7_Second",os.date("%S", utc_7Timestamp))
626 + addr_setword("@UTC+7_Minute",os.date("%M", utc_7Timestamp))
627 + addr_setword("@UTC+7_Hour",os.date("%H", utc_7Timestamp))
628 + addr_setword("@UTC+7_Day",os.date("%d", utc_7Timestamp))
629 + addr_setword("@UTC+7_Month",os.date("%m", utc_7Timestamp))
630 + addr_setword("@UTC+7_Year",os.date("%Y", utc_7Timestamp))
631 + print("--------------------------------------")
632 +
633 +end
634 +{{/code}}
635 +
636 +**Result**
637 +
638 +(% style="text-align:center" %)
639 +[[image:1757044137457-543.png||height="468" width="708"]]
640 +
563 563  = **2 Third part server** =
564 564  
565 565  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.
1757043722849-910.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +74.4 KB
Content
1757043900216-610.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +62.9 KB
Content
1757044137457-543.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.DevinChen
Size
... ... @@ -1,0 +1,1 @@
1 +99.4 KB
Content
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