It turns on the red and/or blue leds on the ESP8266 board and that works fine. I added some code to display a slider and display the value the user sets it to. This seems to work fine.
There is a block commented out by me as a test (lines 14 to 25). Commenting this out does not seem to affect the operation so I'm guessing it does something else but cannot figure out just what it is there for.
Can anyone give me a clue on this? Thanks!
wifi.setmode(wifi.STATION)
wifi.sta.config("xxx","zzz")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP,3600)
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
]]
conn:send('<h1><center>ESP8266 Web Server </center></h1>')
conn:send('<p><center>GPIO0 <a href=\"?pin=ON1\"><button style="font-size:300%;">ON</button></a> <a href=\"?pin=OFF1\"><button style="font-size:300%;">OFF</button></center></a></p>')
conn:send('<p><center>GPIO2 <a href=\"?pin=ON2\"><button style="font-size:300%;">ON</button></a> <a href=\"?pin=OFF2\"><button style="font-size:300%;">OFF</button></center></a></p>')
-- local _on,_off = "",""
if(_GET.pin == "OFF1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "ON1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.LOW);
end
conn:send('<center><font color=red><b>OFF</b></font>')
conn:send('<input style="width:550px; height:50px" type="range" name="cmd" id="cmd" value="" min=1 max=128 step=1 onchange="myFunction()"/>')
conn:send('<font color=red><b>ON</b></font></center></form>')
conn:send('<center><p id="demo" /p></center>')
conn:send('<script>')
conn:send('function myFunction() {')
conn:send(' var x = document.getElementById("cmd").value;')
conn:send(' document.getElementById("demo").innerHTML = "Slider value is : " + x + " units";')
conn:send('}</script>')
client:close();
collectgarbage();
end)
end)