Left here for archival purposes.

User avatar
By Warthog
#5083 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? :?:

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 allsk=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)   
User avatar
By ThomasW
#5131
Warthog wrote: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? :?:


Are you sure it's the connection to the router that gets lost and not just the webserver closing the tcp-connection? I can't tell what's running on http://www.domain.my but personally, i wouldn't trust a webserver to keep a connection open for days, even with "connection: keep-alive"...

Thomas
User avatar
By Warthog
#5133 Hmm, I can see on my router that the module is disconnected from Wifi. So I assume there is a problem with the Wifi network.

In the logs of the router it is written that the module is disconnected because it is not answering.
User avatar
By zeroday
#5142
Warthog wrote:Hmm, I can see on my router that the module is disconnected from Wifi. So I assume there is a problem with the Wifi network.

In the logs of the router it is written that the module is disconnected because it is not answering.


If you can detect this disconnection.

Code: Select allwifi.sta.disconnect()
wifi.sta.connect()


will resume the connection to router