httpserver = function ()
srv=net.createServer(net.TCP)
srv:listen(80,
function(conn)
conn:on("receive", function(conn, payload) print(payload) end)
conn:send("HTTP/1.0 200 OK\r\nContent-type: text/html\r\nServer: test123\r\n\n")
conn:send("</head><body><h1>DK v1 hello world Served from ESP8266</h1>")
--conn:send("hello world")
conn:send("<FORM action=\"\" method=\"POST\">")
conn:send("<button type=\"button\" value=\"Led On\">led on</button><br>")
conn:send("<INPUT type=\"submit\"")
conn:send("</html></body>")
conn:on("sent",function(conn) conn:close() end)
end --conn
)
end
---------------
print("Now scanning for valid IP")
tmr.alarm(1000, 1, function()
if wifi.sta.getip()=="0.0.0.0" then
print("Waiting for connection to AP")
else
print('Now connect to AP, IP: ',wifi.sta.getip())
httpserver()
tmr.stop()
end
end)
result is
POST / HTTP/1.1
Host: xx.xx.0.105
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://xx.xx.0.105/
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
xx.xx.0.105 is a real IP with xx replacing the real values so as to be secure
I was expecting the value Led On to be somewhere on the returned form
What do I need to learn about POST
The goal is to have the web page transfer a requested led state and have the lua code set GPIO0 to that state