the simple direct Wifi <---> NodeMCU (in AP Mode) single object switch, but adding 2 more connections/LED's, (a simple Common-Anode tri-color LED as the base setup right now.). now if I strip-out the extra 2 objects/LED's, it works fine, but the full code, all attempts to call-up the html page, are refused (web page reset)...
the code:
wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="turtle",pwd="5352475347"})
led1 = 3
led2 = 4
led3 = 2
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
gpio.mode(led3, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
buf = buf.."HTTP/1.1 200 OK\n\n"
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> ESP8266 Web Server</h1>";
buf = buf.."<p>GPIO3 <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO4 <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON3\"><button>ON</button></a> <a href=\"?pin=OFF3\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.LOW);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON3")then
gpio.write(led2, gpio.LOW);
elseif(_GET.pin == "OFF3")then
gpio.write(led2, gpio.HIGH);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
So, what is going wrong here? is the code too big for the NodeMCU to handle all at once? should I be splitting it into lua files , or, is there a incorrect piece of the code? be gentle, still a newbie at this.