sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
230 stars 124 forks source link

Not reconnecting to Sinric Server after Internet Drop #92

Closed akaith closed 3 years ago

akaith commented 3 years ago

This is a general problem i faced with the old version of sinric as well as the new one, whenever there is a wifi drop from ISP, the nodemcu doesnt seem to detect it, also whenever the internet is back again it doesnt seem to reconnect to the sinric server. The only solution i found was to reset the nodemcu after every internet drop, but that seems to defeat the purpose of home automation. Any solution for the same??? Thanks

sivar2311 commented 3 years ago

Usually this is handled by SinricPro SDK and i have tested this (see below). If the websocket connection is disconnected, the SDK reconnects automaticly. Implemented here and here. Additionally a user defined callback is called, which can be set by using SinricPro.onDisconnected see here for more information / example code.

The SDK and the SinricPro server makes use of the websocket ping/pong protocol. On SDK side a ping is sent every 5 minutes and timesout after 10 seconds. Retry count is set to 2, so at least after 10 minutes the underlying websocket should securely detect the disconnection.

Reconnect test:

[SinricPro:Websocket]: connected
Connected to SinricPro
[SinricPro:Websocket]: receiving data
[SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue
[SinricPro.handleReceiveQueue()]: Signature is valid. Processing message...
[SinricPro:extractTimestamp(): Got Timestamp 1602007627
[SinricPro:Websocket]: disconnected
Disconnected from SinricPro
[SinricPro:Websocket]: connected
Connected to SinricPro
[SinricPro:Websocket]: receiving data
[SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue
[SinricPro.handleReceiveQueue()]: Signature is valid. Processing message...
[SinricPro:extractTimestamp(): Got Timestamp 1602007937

As you can see there is a gap by exact 310 seconds between both timestamps (5 Minutes and 10 seconds).

sivar2311 commented 3 years ago

Any info on this? (You closed this issue without a comment)

akaith commented 3 years ago

I was testing various possibilities with the internet drop. I found that whenever the drop is longer that 5 mins, it detected the drop successfully and whenever internet was back on, it immediately reconnected. But i found a problem when the internet drop was less than 5 minutes, the device is unable to respond even after the internet was functioning properly. Any solution for this????

sivar2311 commented 3 years ago

The test i did (above) was such a short drop (took less than a minute) and was detected sucessfully after 5min 10seconds. How long did you wait?

akaith commented 3 years ago

The wifi network is available all the time, the drop occurs when the wifi router isnt connected to the internet due to a problem at the ISP end. If the ssid itself isnt available then i got the same results as u. What i was mentioning was that the wifi ssid is available and connected, but isnt connected to the internet. In such a case, after about 5 minutes when a ping is sent, and the internet(not ssid) is down, the server disconnection is detected and whenever the internet is back, the device reconnects. As i mentioned before, when this internet(not ssid) outage is less than 5 minutes then it does not detect either outage nor reconnection occurs. To try this, I suggest u remove the WAN input of ur router or switch of mobile data if using a hotspot after the device has connected successfully to the ssid. Hope the problem description is detailed enough for u to understand . Thanks

sivar2311 commented 3 years ago

I have understood the error exactly. And did exactly what you suggested (disconnect the Internet connection). The WiFi was available all the time and the ESP was connected to it. Only the Internet connection was disconnected for less than a minute. You can see the result in my log above. Everything worked perfectly.

Which version of the Arduino framework do you use?

The problem could be both the underlying TCP layer and your router. Both are things that the SDK cannot influence.

There are similar discussions in the websocket repository. https://github.com/Links2004/arduinoWebSockets/issues/363 https://github.com/Links2004/arduinoWebSockets/issues/203

The SDK is based on this websocket library.

akaith commented 3 years ago

Im using Arduino version 1.8.13 , esp8266 - version 2.7.4, Im using a TP-Link router. I tried the same using mobile hotpot as well but had the same result. Anything u can suggest that i do, to be able to use the device to its full potential

sivar2311 commented 3 years ago

I am using VS-Code PlatformIO but same Arduino Framework Version (2.7.4) and my router is a AVM FritzBox 7490.
I don't have any other suggestions, but a question: How did you the test with mobile hotspot? This will disconnect the WiFi, not only the ISP connection?!

akaith commented 3 years ago

I use mobile data on mobile hotspot, n connect my alexa and nodemcu to same network

Is there a way to change to 5 minute ping to something shorter??

sivar2311 commented 3 years ago

No, there are no plans to shorten the ping time. Solution for you could be to try http request to google.com or somete other website and check if the connection can be established.

akaith commented 3 years ago

Thanks