-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.lua
More file actions
57 lines (51 loc) · 1.6 KB
/
action.lua
File metadata and controls
57 lines (51 loc) · 1.6 KB
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
--action.lua
--URL and host come out of customurl.txt file
print("Sending URL")
print("URL: " .. customurl)
print("Host: " .. customhost)
conn = nil
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
-- show a green LED for 3 seconds before shutting down
gpio.write(red,gpio.LOW)
gpio.write(green,gpio.HIGH)
gpio.write(blue,gpio.LOW)
tmr.delay(3000000)
--Close all LED lights
gpio.write(red,gpio.LOW)
gpio.write(green,gpio.LOW)
gpio.write(blue,gpio.LOW)
-- set GPIO00(3) to LOW linked to CH_PD (will shutdown the module)
gpio.write(3, gpio.LOW)
--If ESP is enabled after 2 seconds that means the button is still pushed!
--in this case, will reset the configuration
tmr.alarm(0, 2000, 1, function()
print("Button is still pressed.")
reset()
end)
end)
conn:on("connection", function(conn, payload)
conn:send("GET " .. customurl
.." HTTP/1.1\r\n"
.."Host: " .. customhost .. "\r\n"
.."Accept: */*\r\n"
.."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n"
.."\r\n")
print("URL request sent.")
end)
conn:dns(customhost,function(conn,ip)
if (ip) then
print("We can connect to " .. ip)
conn:connect(80,ip)
else
reset()
end
end)
function reset()
print("Resetting Wifi..")
wifi.sta.disconnect()
wifi.sta.config("","")
file.remove('customurl.txt')
--all values are deleted, on next button press it will go into configuration mode
print("Settings cleared, please restart.")
end