rgbmatrixscreen/nodemcu/http/reprog.lua
2021-04-29 21:46:54 -04:00

31 lines
1 KiB
Lua

return function (connection, req, args)
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nCache-Control: private, no-store\r\n\r\n")
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Reprogram</title></head>')
connection:send('<body>')
connection:send('<h1>Arguments</h1>')
local form = [===[
<form method="POST">
<textarea name="program"></textarea>
<input type="submit" value="Submit">
</form>
]===]
if req.method == "GET" then
connection:send(form)
elseif req.method == "POST" then
local rd = req.getRequestData()
-- connection:send(cjson.encode(rd))
connection:send('<h2>Received the following values:</h2>')
connection:send("<ul>\n")
for name, value in pairs(rd) do
connection:send('<li><b>' .. name .. ':</b> ' .. tostring(value) .. "<br></li>\n")
end
connection:send("</ul>\n")
else
connection:send("NOT IMPLEMENTED")
end
connection:send('</body></html>')
end