wifi.setmode(wifi.STATION)
wifi.sta.config("BELL464", "BLACKSTORM356")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led2, gpio.OUTPUT)
gpio.mode(led1, gpio.INT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,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
buf = buf.."<h1> LIGHTS CONTROL </h1>";
buf = buf.."<p>Aldo's Room <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led2, gpio.HIGH) ;
elseif(_GET.pin == "OFF1")then
gpio.write(led2, gpio.LOW) ;
else
gpio.trig(led1, "both", function(level)
gpio.write(led2, level)
end);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)