esp8266-12 wifi disconnects
Posted: Tue May 05, 2015 1:56 pm
Hello, i don't know yet if is a bug or not but maybe we can clarify it here.
I wrote a LUA program for periodically read temperature with ds18b20 and read a LDR connected to adc pin.
Module is in station mode and as server on port 8080 listening for connections.
My router is a Netgear R7000 with DD-WRT on it.
Module is doing it's job good, but from time to time it disconnects from wifi and is reconnecting again after 1hour. The longest connection time was around 23hours.
I haven't managed to understand why is disconnecting and what can i do to prevent this behavior or at least try to reconnect imediatelly, not after 1 hour.
I made a test and if i restart wifi on router, esp is connecting itself right after wifi becomes active.
Can someone tell me how can i make esp module's connection more stable?
init.lua:
server.lua
I wrote a LUA program for periodically read temperature with ds18b20 and read a LDR connected to adc pin.
Module is in station mode and as server on port 8080 listening for connections.
My router is a Netgear R7000 with DD-WRT on it.
Module is doing it's job good, but from time to time it disconnects from wifi and is reconnecting again after 1hour. The longest connection time was around 23hours.
I haven't managed to understand why is disconnecting and what can i do to prevent this behavior or at least try to reconnect imediatelly, not after 1 hour.
I made a test and if i restart wifi on router, esp is connecting itself right after wifi becomes active.
Can someone tell me how can i make esp module's connection more stable?
init.lua:
Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("AP_name","password")
wifi.sta.connect()
tmr.delay(1000000)
print("ESP8266 mode is: " .. wifi.getmode())
print("The module MAC address is: " .. wifi.sta.getmac())
--print("Config done, IP is "..ip)
--Startup file--
NextFile="server.lua"
l = file.list();
for k,v in pairs(l) do
-- print("name:"..k..", size:"..v)
if k == NextFile then
print("Wait 5 seconds please")
tmr.alarm(0, 5000, 0, function() dofile(NextFile) end)
print("Started file ".. NextFile)
else
-- do nothing
end
end
print("End of startup")
server.lua
Code: Select all
require('ds18b20')
gpio4 = 1
ds18b20.setup(gpio4)
print("server.lua started")
tmr.alarm(0, 1000, 1, function()
tmr.wdclr()
if wifi.sta.status() < 5 then
node.restart()
end
end )
pin=7
gpio.mode(pin,gpio.OUTPUT)
srv=net.createServer(net.TCP,50)
srv:listen(8080,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
if payload == "[status]" then
temp = ds18b20.read()
temp1 = temp%10000
temp = temp/10000
light = adc.read(0)
conn:send("["..temp.."."..temp1..","..light.."]")
end
if payload == "heat_on" then
gpio.write(pin,gpio.HIGH)
conn:send(gpio.read(pin))
elseif payload == "heat_off" then
gpio.write(pin,gpio.LOW)
conn:send(gpio.read(pin))
end
end)
end)
package.loaded["ds18b20"]=nil