2016-01-07 23:08:44 +01:00
|
|
|
wifi.setmode(wifi.SOFTAP)
|
|
|
|
wifi.ap.config({ssid="test",pwd="12345678"})
|
2015-01-08 10:06:50 +01:00
|
|
|
gpio.mode(1, gpio.OUTPUT)
|
2016-01-07 23:08:44 +01:00
|
|
|
srv=net.createServer(net.TCP)
|
|
|
|
srv:listen(80,function(conn)
|
2015-01-08 10:06:50 +01:00
|
|
|
conn:on("receive", function(client,request)
|
2016-01-07 23:08:44 +01:00
|
|
|
local buf = ""
|
|
|
|
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
|
|
|
if(method == nil)then
|
|
|
|
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
2015-01-08 10:06:50 +01:00
|
|
|
end
|
|
|
|
local _GET = {}
|
2016-01-07 23:08:44 +01:00
|
|
|
if (vars ~= nil)then
|
|
|
|
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
|
|
|
|
_GET[k] = v
|
|
|
|
end
|
2015-01-08 10:06:50 +01:00
|
|
|
end
|
2016-01-07 23:08:44 +01:00
|
|
|
buf = buf.."<h1> Hello, NodeMcu.</h1><form src=\"/\">Turn PIN1 <select name=\"pin\" onchange=\"form.submit()\">"
|
2015-01-08 10:06:50 +01:00
|
|
|
local _on,_off = "",""
|
|
|
|
if(_GET.pin == "ON")then
|
2016-01-07 23:08:44 +01:00
|
|
|
_on = " selected=true"
|
|
|
|
gpio.write(1, gpio.HIGH)
|
2015-01-08 10:06:50 +01:00
|
|
|
elseif(_GET.pin == "OFF")then
|
2016-01-07 23:08:44 +01:00
|
|
|
_off = " selected=\"true\""
|
|
|
|
gpio.write(1, gpio.LOW)
|
2015-01-08 10:06:50 +01:00
|
|
|
end
|
2016-01-07 23:08:44 +01:00
|
|
|
buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>"
|
|
|
|
client:send(buf)
|
2015-01-08 10:06:50 +01:00
|
|
|
end)
|
2016-01-07 23:00:24 +01:00
|
|
|
conn:on("sent", function (c) c:close() end)
|
2015-01-08 10:06:50 +01:00
|
|
|
end)
|