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
236 stars 125 forks source link

Server connection troubles #261

Closed khorner116 closed 2 years ago

khorner116 commented 2 years ago

I am having an intermittent problem with my IOT setup. It has been running and upgraded at various times over the past two years. Recently, it has had trouble connecting to the Sinric server. On maybe 1 in 5 resets it hangs.

The code has defined the SinricPro.onConnected([]() function within a startup routine...

SinricPro.onConnected([](){ if(DisplayOnConsole)Serial.printf("Connected to SinricPro\r\n"); tft_scroll("..SinricPro connected",3); Sinric_connected=true;}); // Set this flag to let the rest of the code know

And once it executes the statement it flows into a waiting loop. SinricPro.begin(APP_KEY, APP_SECRET); delay(1000);
FailTime=millis(); while (!Sinric_connected) { // Hold in this loop until if(DisplayOnConsole)Serial.printf("."); // we reconnect or we let the watch timerWrite(timer1, 0); // dog timer trip after a 5 min delay. SinricPro.handle(); delay(250); if((millis()- FailTime) >300000) while(1); // Watch dog times out here } }

As shown above, the code following the Begin statement loops and calls the handler till the Sinric_connected variable becomes true.

This works almost all the time, but occasionally it will hang forever. As shown above, I've recently implemented a watchdog timer routine to let it hang for 5 minutes and then reboot the ESP32, But sometimes even a complete restart doesn't clear the issue. After a 1/2 hour or so it seems to go away. I'm looking for insight into the issue. Should I be doing some sort of formal disconnect (like I do for the WIFI startup). Or what? Ideas please.

sivar2311 commented 2 years ago

You can retrieve the connection status directly with SinricPro.isConnected().

Remove the delay(250) statement in your loop. delay() blocks the entire sketch and thus SinricPro.handle() (which establishes the connection). Please use a non-blocking code (like Blink without Delay) for the output of the dots.

But I suspect the problem is more likely to be on the WiFi side. Please test this first via a mobile hotspot using your smartphone. If there are no problems, please restart your WiFi router and test the connection again via your WiFi router.

khorner116 commented 2 years ago

Thanks. I've added the SinricPro.isConnected() call and removed the delay stmt. I also added a test earlier to only call Sinric Start or Restart if we have a good wifi link and the Sinric server is disconnected. We will do some more testing to see what's what.

Just another question... is there a Sinric Disconnect call similar to WiFi.disconnect(true) that would effectively force a wipe of any parameters? Create clean slate so to speak.

sivar2311 commented 2 years ago

SinricPro.begin() works differently than WiFi.begin()! SinricPro.begin() does not save any credentials - this is up to the user.

SinricPro.stop() disconnects the underlying websocket connection to the SinricPro server. SinricPro.handle() will reconnect automatically if ithe (websocket) connection was disconnected - except SinricPro.stop() was called before.

stale[bot] commented 2 years ago

This issue has gone quiet. Spooky quiet. We currently close issues after 14 days of inactivity. It’s been at least 7 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks for being a part of the SinricPro community!

stale[bot] commented 2 years ago

Hey again! It’s been 14 days since anything happened on this issue, so our friendly robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder, the best way to fix this or any other problem is to provide a detailed error description including a serial log. Thanks again for being a part of the SinricPro community!