How can I reconnect to my router in case the connection is lost?
-- 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):
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)