Autoconnect will not work
Posted: Thu Dec 18, 2014 11:30 am
When I establish a connection to my router, I can send 3-10 GET requests to my external webspace. But then the connection gets lost while IP is still valid.
How can I reconnect to my router in case the connection is lost?
DS18B20.lua (DS1820 stuff is not shown here):
How can I reconnect to my router in case the connection is lost?
Code: Select all
-- init.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
wifi.sta.autoconnect(1)
tmr.alarm(1,2000, 1, function()
if wifi.sta.getip()==nil then
print(" Wait for IP --> "..wifi.sta.status())
else
print("New IP address is "..wifi.sta.getip())
tmr.stop(1)
print('load DS18B20')
dofile('DS18B20.lua')
end
end)
DS18B20.lua (DS1820 stuff is not shown here):
Code: Select all
sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c) print(c) end )
-- hopefully this does not change
ip="x.x.x.x"
sk:connect(80,ip)
tmr.alarm(2,60000, 1, function()
getTemp()
t1 = lasttemp / 10000
t2 = (lasttemp >= 0 and lasttemp % 10000) or (10000 - lasttemp % 10000)
sendstring = "GET /esp8266.php?Module=ESP01".."&Temp="..t1.."."..string.format("%04d", t2).."&Counter="..zaehler.." HTTP/1.1\r\n"
print(sendstring)
sk:send(sendstring.."Host: www.domain.my\r\n".."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
zaehler=zaehler+1
end)