-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.lua
130 lines (113 loc) · 3.05 KB
/
sms.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
gpio.mode(light,gpio.OUTPUT)
gpio.write(light,gpio.LOW)
gpio.mode(5, gpio.INPUT, gpio.PULLUP)
gpio.mode(2, gpio.INPUT)
flag = 0;
blink = 0;
noloop = 0;
just = 0;
justTimer=0;
number = {"89111111111","89122222222","89233333333"};
text = {"Invasion+detected!","Power+is+missing","Power+is+restored"};
inc = 1;
attempt = 0;
tmr.register(3,15000,tmr.ALARM_SEMI,function()
attempt=attempt+1;
print(text[1])
for inc=1,3,1 do
print(inc)
emailRequest(1);
tmr.delay(500000);
sendSms(1, inc);
end
if (attempt > 4) then
flag = 1;
tmr.stop(3)
end
end)
tmr.alarm(2,10, 1, function ()
if (security == 1 and just == 1) then
justTimer = justTimer - 1;
if (justTimer <= 0) then
just = 0
print("Time out")
end
else
if (security == 1) then
blink = blink+1
if (blink > 400) then
led = 2
blink = 0
end
end
if (gpio.read(5) == 1 and security == 1 and just == 0) then noloop = 1 end
if (noloop == 1 and security == 1 and just == 0) then
if (flag == 0) then
print("Invasion")
tmr.start(3)
flag = 1;
end
else
flag = 0
attempt = 0
tmr.stop(3)
end
if (gpio.read(2) == 0) then
if (pwr == 0) then
print(text[2])
for inc=1,3,1 do
print(inc)
emailRequest(2);
tmr.delay(500000);
sendSms(2, inc);
end
pwr = 1;
end
else
if (pwr == 1) then
pwr = 0
print(text[3])
for inc=1,3,1 do
print(inc)
emailRequest(2);
tmr.delay(500000);
sendSms(2, inc);
end
--attempt = 0
--tmr.stop(3)
end
end
end
end)
function sendSms(txt, nums)
tmr.wdclr();
request = "http://";
request = request..ip;
request = request..":8766/send.html?";
request = request..'smsto='..number[nums];
request = request..'&smsbody='..text[txt];
request = request..'&smstype=sms'
http.get(request, nil, function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
tmr.delay(500000)
tmr.wdclr()
end
function emailRequest(txt)
request = "http://";
request = request..ip;
request = request..":8766/[email protected]&smsbody="
request = request..text[txt]
request = request.."&smstype=email"
http.get(request, nil, function(code, data)
if (code < 0) then
print("HTTP request failed")
else
print(code, data)
end
end)
end