NodeMCU ESP8266 simple httpd (web server) example

I want to add a simple webserver to my NodeMCU bot, and…<begin old man grump>In looking, I did not find anything really clean-cut, most of the examples I find for anything these days are so cluttered and look like they where written by a robot monkey (a poorly coded one). It’s seems if there


This is a companion discussion topic for the original entry at https://community.robotshop.com/blog/show/nodemcu-esp8266-simple-httpd-web-server-example

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>’)