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
227 stars 121 forks source link

Device shows as unresponsive in App and Dashboard after router IP rotation, but is actually responsive #373

Closed joseportillodev closed 1 month ago

joseportillodev commented 2 months ago

Dear developers, I'm facing an issue that I suspect may be server-related. Here are the details and info to try to diagnose the issue.

Background info:

Issue: Devices show as unresponsive in App and Dashboard after router IP rotation

What was expected to happen:

What actually happens:

Steps to reproduce:

Screenshots:

Thank you Jose

kakopappa commented 2 months ago

Hi Jose,

Thanks for reporting this and also putting as much as information you can.

Issue is likely related to the arrival of disconnect event later so that system thinks device has been disconnected from the server. This seems to be a very odd case.

Currently I am on holiday. Will update you when I get back.

On Thu, 11 Apr 2024 at 12:18 AM joseportillodev @.***> wrote:

Dear developers, I'm facing an issue that I suspect may be server-related. Here are the details and info to try to diagnose the issue.

Background info:

  • Device ESP8266 board (Wemos D1 Mini clone)
  • ESP8266 SinricPro Library: v3.0.1
  • Arduino Sketch: Relatively complex sketch but simple SinricPro Integration (5x SinricProSwitch devices, similar to the Switch Tutorial Part 3 - Multiple relays https://help.sinric.pro/pages/tutorials/switch/part-3 example)
  • iPhone App: SinricPro 2.25.1 (unrelated)

Issue: Devices show as unresponsive in App and Dashboard after router IP rotation

  • My 4G internet router rotates its public IP daily in the early morning.
  • After that, my SinricProSwitches appear in the SinricPro App as "Offline" (red circle) and "Device is unresponsive". However, they do respond to commands and then show as Online (green circle) and "Switch is turned XXXX".
  • The logs from the Sinric Portal show a connection event (websocket [X,Y,Z] connected) from the new IP address, but a few minutes later, a disconnection event (websocket [X,Y,Z] disconnected) from the old IP address is registered.
  • My guess is that this latter event makes Sinric servers think my devices are finally disconnected.

What was expected to happen:

  • The device detects the websocket disconnection and reconnects to Sinric servers. Everything remains in green.

What actually happens:

  • The device detects the websocket disconnection and reconnects to Sinric servers. Sinric Web Dashboard and App show the devices as offline but let me turn them on/off and then they show up as online in green.

Steps to reproduce:

  • Wait a few minutes after IP address rotation on my router.
  • Login to Sinric Portal Dashboard or Sinric App and see the devices showing as offline.
  • Switch any device on or off (regardless of previous state) and see it execute the action and then appear online on Dashboard and App. The rest of devices will still appear offline.

Screenshots:

  • Logs showing a connection event from the new 88.X IP, then a disconnection event from the old 5.X IP:

Captura.de.pantalla.2024-04-10.a.las.18.45.41.1024px.png (view on web) https://github.com/sinricpro/esp8266-esp32-sdk/assets/166513883/5ba814d8-353b-4da7-b035-288ddcadcf08

  • App showing the state of devices (those in green were actioned despite of being shown previously offline):

IMG_0343.PNG (view on web) https://github.com/sinricpro/esp8266-esp32-sdk/assets/166513883/3a570b8c-8277-4670-a73d-b13f67aeae60

Thank you Jose

— Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/373, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZXSBTYR3A76RANIRALY4WCRNAVCNFSM6AAAAABGA6HOCGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIZTMMRRGIYDENA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kakopappa commented 2 months ago

Thanks. This is an interesting problem. here's what's going on.

  1. When the ESP connects it connects to the Load Balancer (LB). LB forwards the connection to one of many WebSocket servers running internally.

  2. IP Resets

  3. ESP reconnects from a new IP. This time, it forwards the connection to another web socket server.

  4. After some time, the connection in step 1 becomes stale and disconnects. The server thinks the ESP went offline.

I am working on a fix. I'll let you know when it's ready.

joseportillodev commented 2 months ago

Ok, thank you.

Some days I don't see any disconnection event. The ESP just reconnects, updates the current state of all devices and sits there connected. When I wake up, I find them all online on the Dashboard and on the App.

Captura de pantalla 2024-04-19 a las 9 51 34
kakopappa commented 2 months ago

Hi, I have uploaded the fix now. Please monitor for the next few days whether this issue still persist.

kakopappa commented 1 month ago

If you still have this issue please create a new issue.

joseportillodev commented 1 month ago

I've been monitoring it for a few days and haven't seen the issue happen anymore. When my router gets a new IP address, the logs show "websocket | Login via App key" and then "websocket | [Device1, Device2, ...] connected" and then no disconnection event from the old IP address. They all now show as 'online'. Thank you!