As the title says... Chat on...

User avatar
By jankop
#4867 I need advice, please. How can I get a variable name = "stat" and value = "1" to lua variables for next operation?
Can someone show me a simple example? GET or POST, what is easier.

Code: Select allsrv=net.createServer(net.TCP) srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload) print(payload)
    conn:send("HTTP/1.1 200 OK\n\n")
    conn:send('<!DOCTYPE html>')
    conn:send('<html>')
    conn:send('<head><meta charset="utf-8" /></head>')
    conn:send('<body>')
    conn:send('<form action="" method="get"><input type="submit" name="stat" value="1"></form>')
    conn:send("</html></body>")
    conn:on("sent",function(conn) conn:close() end)
  end)
end)


Thanks
User avatar
By NeiroN
#6069
Code: Select allsrv=net.createServer(net.TCP)
srv:listen(80,function(conn)
     conn:on("receive", function(client,request)
          local buf = "";
          local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)%?(.-) HTTP");
          if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end
          local _GET = {}
          if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end
          -- Now we can use _GET['name'] or _GET.name
          buf = buf.."<h1> Hello, NodeMcu.</h1><form src=/>Turn GPIO2 <select name=pin onchange=\"form.submit()\">";
          print("\nMethod: "..method);
          print("Path: "..path);
          local _on,_off = "",""
          if(_GET.pin == "ON")then
                 _on = " selected=true";
                 gpio.write(4, gpio.HIGH);
          elseif(_GET.pin == "OFF")then
                 _off = " selected=true";
                 gpio.write(4, gpio.LOW);
          end
          buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>";
          client:send(buf);
          client:close();
          collectgarbage();
     end)
end)
User avatar
By Melih Atasever
#41435 Hello,

Thank you for your help. I have very similar problem with form issue.
I need to get two information from user by using forms. Almost all examples shows those information sent to a .php page. I dont need that.
In your example there is choices, but in my issue there will be a word. So how can I use it?