- Fri Jun 09, 2017 11:09 am
#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>