So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By gelfling6
#66773
atexit8 wrote:You have to crawl before you can walk.

While what you want may seem simple, it isn't.

I found http://www.martyncurrey.com/arduino-esp8266-web-server/ to be very helpful in understanding what is happening behind the scenes. It is a very simple example.


Okay.. I'm looking at the example, but that's in the Expressif 'AT' command format, not Lua. I'm trying to base this as a internal HTML in Program, similar to the simple LED web server (from NodeMCU_Firmware_master (V2.0.0), lua_examples, webap_toggle_pin.lua) (not with a pull-down On/Off, but a simple center [Fwd] top button, [Left][Right] on the next line, and [Back] on the next, followed by a slider below..) Putting together the html, is one problem, creating the output from the ESP8266's serial port is the other. the key, being the direction buttons will actually submit the response back to the ESP, but only read the value from the slider, but hold it til one of the 4 submit buttons is pressed..
User avatar
By JackB
#66779 Not sure I understand exactly what you are trying to do, but it sounds like it is a HTML/javascript problem and not really an esp8266 problem.
Can you create such a HTML interface on your PC? You don't need a web server to create
html pages and test them, just create a file with the HTML, and the web browswer can view them (e.g. file://home/fred/testit.html) Get the html interface to look/work like you want. You can use javascript embedded in the html page to do almost anything in the browser these days,
and then have it submit a form to the esp8266(web server) when you want with the data you want.
hope that helps..
User avatar
By gelfling6
#66952
JackB wrote:Not sure I understand exactly what you are trying to do, but it sounds like it is a HTML/javascript problem and not really an esp8266 problem.
Can you create such a HTML interface on your PC? You don't need a web server to create
html pages and test them, just create a file with the HTML, and the web browswer can view them (e.g. file://home/fred/testit.html) Get the html interface to look/work like you want. You can use javascript embedded in the html page to do almost anything in the browser these days,
and then have it submit a form to the esp8266(web server) when you want with the data you want.
hope that helps..

I'm already putting the raw html together, but not using Javascript, trying to do it UDP.. (?? Like I said, Total Newby, forgive me if I botch names.) Next problem, not a problem with the 8266, but trying to insert the html into a lua program, similar to the simple html of webap_toggle_pin.lua. I've added a print() steps into that program, so it would output the values of the variables sent (buf & _GET.pin)
This is the code so-far:
Code: Select allwifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="tardis3",pwd="0728196354"})
gpio.mode(1, gpio.OUTPUT)
srv=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
        buf = buf.."<h1> Hello, NodeMcu.</h1><form src=\"/\">Turn PIN1 <select name=\"pin\" onchange=\"form.submit()\">"
        local _on,_off = "",""
   print(_GET.pin)
   if(_GET.pin == "ON")then
              _on = " selected=true"
              gpio.write(1, gpio.HIGH)
        elseif(_GET.pin == "OFF")then
              _off = " selected=\"true\""
              gpio.write(1, gpio.LOW)
       print(buf)
        end
        buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>"
        client:send(buf)
    end)
    conn:on("sent", function (c) c:close() end)
end)

I left the gpio assignment code in it, just for the tinkering, But... the print() statements are writing the values out the serial I/O as I want... where it sends the ON or OFF values in _GET.pin, is where I want the 'F1000' result, (If I had the slider equal to 1.000, 1 second, and when i click the Fwd button, it will multiply the 1.000 X1000, then send the "F" from the Fwd button, and the value 1000.) Result, the arduino receives the "F1000", telling it roll forward 1-second (1000mS)


I'm still working on the html raw code, It's starting to fit together, But still need to figure the button arrangement... Then comes the fun of writing it into the lua code...
Code: Select all<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Robot</title>
</head>
<body>
<label for="range">Seconds</label> <input min="0" max="10" step="0.25" required type="range" id="range" name="range"/>
<input type="submit" name="F" value="Fwd"><input type="submit" name="B" value="Back">

</body>
</html>