print("STARTING UP") wifi.setmode(wifi.STATION) wifi.sta.config("Hacklab-Guests","") led1 = 5 gpio.mode(led1, 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+)=([^&]+)&*") do _GET[k] = v end end buf = buf.."

ESP8266 Web Server

"; buf = buf.."

Output 5  

"; local _on,_off = "","" if(_GET.set1 == "on") then gpio.write(led1, gpio.HIGH); end if(_GET.set1 == "off") then gpio.write(led1, gpio.LOW); end WebResponse(client, buf); collectgarbage(); end) end) function WebResponse(client, buf) local hd = "HTTP/1.1 200 OK\r\n" hd=hd.."Server: AvESP 0.1\r\n" hd=hd.."Content-Length: "..string.len(buf).."\r\n" hd=hd.."Content-Type: text/html\r\n" hd=hd.."\r\n" client:send(hd..buf) client:close() end