-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·61 lines (61 loc) · 2 KB
/
init.lua
File metadata and controls
executable file
·61 lines (61 loc) · 2 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
58
59
60
61
wifi.setmode(wifi.STATION)
wifi.sta.config("my-wifi","my-password")
print(wifi.sta.getip())
gpio2 = 4
gpio.mode(gpio2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
if (string.find(request,"favicon") ~= nil) then
return
end
print("request received")
print(request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
local redchecked,greenchecked,bluechecked = "","",""
red,green,blue = 0,0,0
if(_GET.red == "red")then
--gpio.write(led1, gpio.HIGH);
red = 255
redchecked = " checked "
end
if(_GET.green == "green")then
green = 255
greenchecked = " checked "
end
if(_GET.blue == "blue")then
-- gpio.write(led2, gpio.LOW);
blue = 255
bluechecked = " checked "
end
buf = buf.."<h1> ESP8266 Web Server</h1><form>";
buf = buf.."<p>RED <input type=checkbox name=red value=red "
buf = buf..redchecked
buf = buf.."></p>";
buf = buf.."<p>GREEN <input type=checkbox name=green value=green "
buf = buf..greenchecked
buf = buf.."></p>";
buf = buf.."<p>BLUE <input type=checkbox name=blue value=blue "
buf = buf..bluechecked
buf = buf.."></p>"
buf = buf.."<p><input type=submit></p></form>"
--red = 255
--green = 0
--blue = 0
ws2812.writergb(gpio2,string.char(red,green, blue))
tmr.delay(1000000)
client:send(buf);
client:close();
collectgarbage();
end)
end)