Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wifi.setmode(wifi.STATION)
- wifi.sta.config("YourSSID","YourPASSWORD")
- print(wifi.sta.getip())
- rele = 1;
- gpio.mode(rele, gpio.OUTPUT)
- 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> ESP8266 Web Server</h1>";
- buf = buf.."<p><a href=\"?rele=ON\"><button>OPEN</button></a></p>";
- local _on,_off = "",""
- if(_GET.rele == "ON")then
- print("Gate Open");
- gpio.write(rele, gpio.HIGH);
- tmr.alarm(0, 400, 0, function() gpio.write(rele, gpio.LOW); print("Rele OFF"); end )
- end
- client:send(buf);
- client:close();
- collectgarbage();
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement