Simple NodeMCU web server
II’m trying to learn LUA, but the following code has me confused…
[code]
function get_http_req (instr)
local t = {}
local first = nil
local key, v, strt_ndx, end_ndx
for str in string.gmatch (instr, “([^\n]+)”) do – WHAT DOES THIS DO
– First line in the method and path
if (first == nil) then
first = 1
strt_ndx, end_ndx = string.find (str, “([^ ]+)”) – WHAT DOES THIS DO
v = trim (string.sub (str, end_ndx + 2))
key = trim (string.sub (str, strt_ndx, end_ndx))
t[“METHOD”] = key
t[“REQUEST”] = v
else – Process and reamaining “:” fields
strt_ndx, end_ndx = string.find (str, “([^:]+)”) – WHAT DOES THIS DO
if (end_ndx ~= nil) then
v = trim (string.sub (str, end_ndx + 2))
key = trim (string.sub (str, strt_ndx, end_ndx))
t[key] = v
end
end
end
[/code]
I want to add this + more but cannot get it working when I click the box ie POST = 10 ~~~90 etc
I get table values, totally don’t understand, I’m totally confused
[code]
cn:send(’<form action="" method=“POST”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“ON”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“10”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“20”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“30”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“40”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“50”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“60”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“70”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“80”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“90”>\n’)
cn:send(’<input type=“submit” name=“pwmi” value=“OFF”>\n</form><br>’)