Relay switch runs ESP8266 crazy
Posted: Fri Sep 04, 2015 2:49 pm
Hello,
I am new to the forum, and sorry if i missed the topic So, I programed my ESP8266 for a simple webserver, so i can control my relay over Wi-Fi... And everything works perfect, until the relay actually gets loaded... When I connect my lights on the relay, it can turn them off and on one time, than the ESP just goes crazy, it writes some dibrish ->
(x 2ü<–ń =xń ź Ź_tĘ„.ČSMŚü2Y ÂÖyůÂA$IÚ¬ý)
in lualoader, and i need to reset it. Than it again runs normally for one switch and goes crazy... I am wondering if anyone else run to a problem of this sort, any suggestions would be most helpful.
I am using an arduino relay (5V) connected to GPIO0, I also tried to connect it to the GPIO2 on the ESP but it doesn’t mater.
THE CODE: (but I doubt that there is the problem)
wifi.setmode(wifi.STATION)
wifi.sta.config("BBQ","1004199399")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, 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> Zan soba </h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON2")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "OFF1")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON1")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
Thank you,
Žan
I am new to the forum, and sorry if i missed the topic So, I programed my ESP8266 for a simple webserver, so i can control my relay over Wi-Fi... And everything works perfect, until the relay actually gets loaded... When I connect my lights on the relay, it can turn them off and on one time, than the ESP just goes crazy, it writes some dibrish ->
(x 2ü<–ń =xń ź Ź_tĘ„.ČSMŚü2Y ÂÖyůÂA$IÚ¬ý)
in lualoader, and i need to reset it. Than it again runs normally for one switch and goes crazy... I am wondering if anyone else run to a problem of this sort, any suggestions would be most helpful.
I am using an arduino relay (5V) connected to GPIO0, I also tried to connect it to the GPIO2 on the ESP but it doesn’t mater.
THE CODE: (but I doubt that there is the problem)
wifi.setmode(wifi.STATION)
wifi.sta.config("BBQ","1004199399")
print(wifi.sta.getip())
led1 = 3
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, 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> Zan soba </h1>";
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON2")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "OFF1")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON1")then
gpio.write(led2, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
Thank you,
Žan