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

SinricPro does not report lost connection in a timely manner #348

Closed lilbuzz closed 7 months ago

lilbuzz commented 7 months ago

Using WEMO MINI Esp32. Connected to SinricPro server using cell phone hotspot. I disable the hotspot, but calls to SinricPro.isConnected() continue to return true. This is true for more than 10 minutes. I am calling SinricPro.handle() in my loop, and then polling SinricPro.isConnected().

Here is some sample debug output:

2023-11-12 16:52:29 --> ets Jul 29 2019 12:21:46 2023-11-12 16:52:29 --> 2023-11-12 16:52:29 --> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOO 2023-11-12 16:52:29 --> T) 2023-11-12 16:52:29 --> configsip: 0, SPIWP:0xee 2023-11-12 16:52:29 --> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 2023-11-12 16:52:29 --> mode:DIO, clock div:1 2023-11-12 16:52:29 --> load:0x3fff0030,len:1184 2023-11-12 16:52:29 --> load:0x40078000,len:13260 2023-11-12 16:52:29 --> load:0x40080400,len:3028 2023-11-12 16:52:29 --> entry 0x400805e4 2023-11-12 16:52:31 --> 2023-11-12 16:52:31 --> BOOT 2023-11-12 16:52:31 --> 2023-11-12 16:52:31 --> 2023-11-12 16:52:31 --> WiFi status before connect attempt: 6, WL_DISCONNECTED 2023-11-12 16:52:31 --> Disconnecting WiFi... Attempts: 0 2023-11-12 16:52:31 --> WiFi status after disconnect: 6, WL_DISCONNECTED 2023-11-12 16:52:31 --> Calling WiFi reconnect 2023-11-12 16:52:31 --> Setting Cert for Telegram app 2023-11-12 16:52:31 --> Connecting to WiFi... 2023-11-12 16:52:32 --> . 2023-11-12 16:52:32 --> . 2023-11-12 16:52:32 --> . 2023-11-12 16:52:32 --> . Attempts: 5 2023-11-12 16:52:32 --> Connected to the WiFi network. 2023-11-12 16:52:32 --> WiFi status: 3, 2023-11-12 16:52:33 --> WL_CONNECTED 2023-11-12 16:52:33 --> [SinricPro]: Device "xxxx" does not exist. Creating new device 2023-11-12 16:52:33 --> [SinricPro:add()]: Adding device with id "xxxx". 2023-11-12 16:52:33 --> 2023-11-12T17:52:22Z 2023-11-12 16:52:33 --> In central standard time. 2023-11-12 16:52:33 --> Finished setup. 2023-11-12 16:52:33 --> [SinricPro:Websocket]: Connecting to WebSocket Server using SSL (ws.sinric.pro) 2023-11-12 16:52:33 --> [SinricPro:Websocket]: headers: 2023-11-12 16:52:33 --> appkey:xxxx 2023-11-12 16:52:33 --> deviceids:xxxx 2023-11-12 16:52:33 --> restoredevicestates:false 2023-11-12 16:52:33 --> 2023-11-12 16:52:33 --> ip:192.168.57.246 2023-11-12 16:52:33 --> mac:C8:F0:9E:F1:4F:60 2023-11-12 16:52:33 --> platform:ESP32 2023-11-12 16:52:33 --> SDKVersion:3.0.0 2023-11-12 16:52:36 --> [SinricPro:Websocket]: connected 2023-11-12 16:52:36 --> Connected to SinricPro 2023-11-12 16:52:36 --> Freezer door contact sensor state is closed now. 2023-11-12 16:52:36 --> [SinricPro:sendMessage()]: pushing message into sendQueue 2023-11-12 16:52:36 --> SinricPro is connected. 2023-11-12 16:52:36 --> [SinricPro:Websocket]: receiving data 2023-11-12 16:52:36 --> [SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue 2023-11-12 16:52:36 --> [SinricPro.handleReceiveQueue()]: Signature is valid. Processing message... 2023-11-12 16:52:36 --> [SinricPro:extractTimestamp(): Got Timestamp 1699829545 2023-11-12 16:52:36 --> [SinricPro:handleSendQueue()]: 1 message(s) in sendQueue 2023-11-12 16:52:36 --> [SinricPro:handleSendQueue()]: Sending message... 2023-11-12 16:52:36 --> { 2023-11-12 16:52:36 --> "header": { 2023-11-12 16:52:36 --> "payloadVersion": 2, 2023-11-12 16:52:36 --> "signatureVersion": 1 2023-11-12 16:52:36 --> }, 2023-11-12 16:52:36 --> "payload": { 2023-11-12 16:52:36 --> "action": "setContactState", 2023-11-12 16:52:36 --> "cause": { 2023-11-12 16:52:36 --> "type": "PHYSICAL_INTERACTION" 2023-11-12 16:52:36 --> }, 2023-11-12 16:52:36 --> "createdAt": 1699829545, 2023-11-12 16:52:36 --> "deviceId": "xxxx", 2023-11-12 16:52:36 --> "replyToken": "xxxx", 2023-11-12 16:52:36 --> "type": "event", 2023-11-12 16:52:36 --> "value": { 2023-11-12 16:52:36 --> "state": "closed" 2023-11-12 16:52:36 --> } 2023-11-12 16:52:36 --> }, 2023-11-12 16:52:36 --> "signature": { 2023-11-12 16:52:36 --> "HMAC": "xxxx" 2023-11-12 16:52:36 --> } 2023-11-12 16:52:36 --> } 2023-11-12 16:52:36 --> [SinricPro:handleSendQueue]: Sending to websocket 2023-11-12 16:52:36 --> [SinricPro:handleSendQueue()]: message sent. 2023-11-12 16:52:59 --> [SinricPro:Websocket]: disconnected 2023-11-12 16:52:59 --> Disconnected from SinricPro 2023-11-12 16:52:59 --> SinricPro is disconnected. 2023-11-12 16:53:02 --> [SinricPro:Websocket]: connected 2023-11-12 16:53:02 --> Connected to SinricPro 2023-11-12 16:53:02 --> SinricPro is connected. 2023-11-12 16:53:02 --> [SinricPro:Websocket]: receiving data 2023-11-12 16:53:02 --> [SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue 2023-11-12 16:53:02 --> [SinricPro.handleReceiveQueue()]: Signature is valid. Processing message... 2023-11-12 16:53:02 --> [SinricPro:extractTimestamp(): Got Timestamp 1699829571 2023-11-12 16:56:47 --> [SinricPro:Websocket]: disconnected 2023-11-12 16:56:47 --> Disconnected from SinricPro 2023-11-12 16:56:47 --> SinricPro is disconnected. 2023-11-12 16:56:49 --> [SinricPro:Websocket]: connected 2023-11-12 16:56:49 --> Connected to SinricPro 2023-11-12 16:56:49 --> SinricPro is connected. 2023-11-12 16:56:49 --> [SinricPro:Websocket]: receiving data 2023-11-12 16:56:49 --> [SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue 2023-11-12 16:56:49 --> [SinricPro.handleReceiveQueue()]: Signature is valid. Processing message... 2023-11-12 16:56:49 --> [SinricPro:extractTimestamp(): Got Timestamp 1699829798 I have tested this with delays over 10 minutes, but the call to isConnected still returns true until the hotspot is re-enabled.
kakopappa commented 7 months ago

Hi @lilbuzz

Are you using the sketch here for testing or your own sketch https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/examples/Switch/Switch/Switch.ino#L94

  #if defined(ESP8266)
    WiFi.setSleepMode(WIFI_NONE_SLEEP); 
    WiFi.setAutoReconnect(true);
  #elif defined(ESP32)
    WiFi.setSleep(false); 
    WiFi.setAutoReconnect(true);
  #endif
lilbuzz commented 7 months ago

Yes I am. Here are the lines in my setup:

    // Assuming you want your ESP32 to act like any other client (STAtion) on your Wi-Fi

    WiFi.mode(WIFI_STA);

    // Store Wi-Fi configuration in EEPROM? Not a good idea as it will never forget these settings.

    WiFi.persistent(false);

    // Reconnect if connection is lost

    WiFi.setAutoReconnect(true);

    // Modem sleep when in WIFI_STA mode not a good idea as someone might want to talk to it

    WiFi.setSleep(false);
kakopappa commented 7 months ago
  1. Set logging to Verbose (Tools -> Core Debug Level -> Verbose)
  2. flash the example code
  3. Connect ESP to Iphone14
  4. Turn off Hotspot.
  5. Disconnects immediately.
  6. Reconnection does not seem to happen though. need to look into this.

https://github.com/sinricpro/esp8266-esp32-sdk/assets/7474406/af1e5d4a-9739-43da-be67-4aea09fe2750

lilbuzz commented 7 months ago

I'm not sure what was supposed to happen. I set debug to verbose.

The following is the last portion of the debug output after I disabled the cell phone hotspot. It only ended when I re-enabled the hotspot. The onDisconnected event (not shown here) fired when the hotspot was disabled, unlike when debug was set to none.

2023-11-12 22:39:01 --> [ 47885][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:01 --> [ 47906][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:03 --> [ 50322][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:03 --> [ 50322][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:03 --> [ 50330][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:03 --> [ 50337][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:04 --> [ 50358][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:06 --> [ 52774][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:06 --> [ 52774][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:06 --> [ 52782][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:06 --> [ 52788][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:06 --> [ 52810][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:08 --> [ 54605][E][WiFiUdp.cpp:172] beginPacket(): could not get host from dns: 11 2023-11-12 22:39:08 --> [ 54605][E][WiFiUdp.cpp:185] endPacket(): could not send data: 118 2023-11-12 22:39:08 --> [ 55226][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:08 --> [ 55226][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:08 --> [ 55234][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:08 --> [ 55241][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:08 --> [ 55262][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:11 --> [ 57677][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:11 --> [ 57678 2023-11-12 22:39:11 --> ][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:11 --> [ 57685][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:11 --> [ 57692][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:11 --> [ 57713][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:13 --> [ 60129][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:13 --> [ 60129][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:13 --> [ 60137][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:13 --> [ 60144][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:13 --> [ 60165][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:16 --> [ 62581][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:16 --> [ 62581][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:16 --> [ 62589][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:16 --> [ 62595][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:16 --> [ 62617][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:18 --> [ 65033][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:18 --> [ 65034][D][WiFiGeneric.cpp:10 2023-11-12 22:39:18 --> 35] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:18 --> [ 65041][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:18 --> [ 65048][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:18 --> [ 65069][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:21 --> [ 67485][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 0 2023-11-12 22:39:21 --> 0:00:00:00:00:00, Reason: 201 2023-11-12 22:39:21 --> [ 67485][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:21 --> [ 67493][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:21 --> [ 67499][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:21 --> [ 67521][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:23 --> [ 69937][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:23 --> [ 69937][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:23 --> [ 69945][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:23 --> [ 69951][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:23 --> [ 69973][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:24 --> [ 70609][E][WiFiUdp.cpp:172] beginPacket(): could not get host from dns: 11 2023-11-12 22:39:24 --> [ 70609][E][WiFiUdp.cpp:185] endPacket(): could not send data: 118 2023-11-12 22:39:26 --> [ 72389][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:26 --> [ 72389][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:26 --> [ 72397][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:26 --> [ 72403][D][WiFiGeneric.cpp:1081] _eventCallback(): 2023-11-12 22:39:26 --> WiFi AutoReconnect Running 2023-11-12 22:39:26 --> [ 72425][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:28 --> [ 74841][V][WiFiGeneric.cpp:362] _arduino_event_cb(): STA Disconnected: SSID: Bussey, BSSID: 00:00:00:00:00:00, Reason: 201 2023-11-12 22:39:28 --> [ 74841][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED 2023-11-12 22:39:28 --> [ 74848][W][WiFiGeneric.cpp:1057] _eventCallback(): Reason: 201 - NO_AP_FOUND 2023-11-12 22:39:28 --> [ 74855][D][WiFiGeneric.cpp:1081] _eventCallback(): WiFi AutoReconnect Running 2023-11-12 22:39:28 --> [ 74876][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0 2023-11-12 22:39:29 --> [ 75646][V][WiFiGeneric.cpp:355] _arduino_event_cb(): STA Connected: SSID: Bussey, BSSID: ae:6d:b7:f5:af:c4, Channel: 1, Auth: WPA2_PSK 2023-11-12 22:39:29 --> [ 75648][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 4 - STA_CONNECTED 2023-11-12 22:39:29 --> [ 75691][V][WiFiGeneric.cpp:369] _arduino_event_cb(): STA Got Same IP:192.168.57.246 2023-11-12 22:39:29 --> [ 75692][D][WiFiGeneric.cpp:1035] _eventCallback(): Arduino Event: 7 - 2023-11-12 22:39:29 --> STA_GOT_IP 2023-11-12 22:39:29 --> [ 75695][D][WiFiGeneric.cpp:1098] _eventCallback(): STA IP: 192.168.57.246, MASK: 255.255.255.0, GW: 192.168.57.136 2023-11-12 22:39:29 --> [ 75705][V][ssl_client.cpp:62] start_ssl_client(): Free internal heap before TLS 209184 2023-11-12 22:39:29 --> [ 75713][V][ssl_client.cpp:68] start_ssl_client(): Starting socket 2023-11-12 22:39:29 --> [ 75948][V][ssl_client.cpp:146] start_ssl_client(): Seeding the random number generator 2023-11-12 22:39:29 --> [ 75949][V][ssl_client.cpp:155] start_ssl_client(): Setting up the SSL/TLS structure... 2023-11-12 22:39:29 --> [ 75952][D][ssl_client.cpp:176] start_ssl_client(): WARNING: Skipping SSL Verification. INSECURE! 2023-11-12 22:39:29 --> [ 75961][V][ssl_client.cpp:254] start_ssl_client(): Setting hostname for TLS session... 2023-11-12 22:39:29 --> [ 75969][V][ssl_client.cpp:269] start_ssl_client(): Performing the SSL/TLS handshake... 2023-11-12 22:39:31 --> [ 77355][V][ssl_client.cpp:290] start_ssl_client(): Verifying peer X.509 certificate... 2023-11-12 22:39:31 --> [ 77355][V][ssl_client.cpp:298] start_ssl_client(): Certificate verified. 2023-11-12 22:39:31 --> [ 77358][V][ssl_client.cpp:313] start_ssl_client(): Free internal heap after TLS 166140 2023-11-12 22:39:31 --> [ 77367][V][ssl_client.cpp:369] send_ssl_data(): Writing HTTP request with 411 bytes... 2023-11-12 22:39:31 --> [SinricPro:Websocket]: connected 2023-11-12 22:39:31 --> onConnected event fired from SinricPro 2023-11-12 22:39:31 --> SinricPro is connected. 2023-11-12 22:39:31 --> [SinricPro:Websocket]: receiving data 2023-11-12 22:39:31 --> [SinricPro.handleReceiveQueue()]: 1 message(s) in receiveQueue 2023-11-12 22:39:31 --> [SinricPro.handleReceiveQueue()]: Signature is valid. Processing message... 2023-11-12 22:39:31 --> [SinricPro:extractTimestamp(): Got Timestamp 1699850360 2023-11-12 22:39:31 --> WiFi is reconnected.

kakopappa commented 7 months ago

Which version of ESP32 core are you using?

kakopappa commented 7 months ago

Hi @lilbuzz

When WiFi.setSleep(false); reconnect seems to never happen. Removing it or setting it to WiFi.setSleep(true); worked. Seems bit strange.

#define BAUD_RATE         115200

#define WIFI_SSID         "xxx"    
#define WIFI_PASS         "xx"

#include <WiFi.h>

// setup function for WiFi connection
void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");

  //WiFi.setSleep(WIFI_PS_NONE); 
   WiFi.setSleep(false);
   WiFi.setAutoConnect(true);
   WiFi.setAutoReconnect(true);

  WiFi.begin(WIFI_SSID, WIFI_PASS); 

  while (WiFi.status() != WL_CONNECTED) {
    Serial.printf(".");
    delay(250);
  }
  Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());

}

// main setup function
void setup() {
  //esp_log_level_set("*", ESP_LOG_VERBOSE); 
  Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
  setupWiFi(); 
}

const char* wl_status_to_string(wl_status_t status) {
  switch (status) {
    case WL_NO_SHIELD: return "WL_NO_SHIELD";
    case WL_IDLE_STATUS: return "WL_IDLE_STATUS";
    case WL_NO_SSID_AVAIL: return "WL_NO_SSID_AVAIL";
    case WL_SCAN_COMPLETED: return "WL_SCAN_COMPLETED";
    case WL_CONNECTED: return "WL_CONNECTED";
    case WL_CONNECT_FAILED: return "WL_CONNECT_FAILED";
    case WL_CONNECTION_LOST: return "WL_CONNECTION_LOST";
    case WL_DISCONNECTED: return "WL_DISCONNECTED";
  }

  return "NO";
}

 String lastStatus = "";

void loop() {   
    String currentStatus =  wl_status_to_string(WiFi.status());

    if(currentStatus != lastStatus) {
      Serial.print("currentStatus:");
      Serial.println(currentStatus);

      Serial.print("lastStatus:");
      Serial.println(lastStatus);

      lastStatus = currentStatus;
    }
}
lilbuzz commented 7 months ago

I am using the latest esp core. I always keep my libraries up to date.

lilbuzz commented 7 months ago

Are you asking me to change the setting of the setSleep() method?

lilbuzz commented 7 months ago

I commented the line containing the setSleep call, but that did not change the behavior.

lilbuzz commented 7 months ago

Notes on the disconnected behavior: With debug set to verbose, the onDisconnected event is inconsistent. Sometimes it fires when the hotspot is disabled, and sometimes it does not fire until the hotspot is re-enabled, followed by the onConnected event. When debug is set to none, the onDisconnected event never fires when the hotspot is disabled, but always fires when the hotspot is re-enabled, followed by the onConnected event.

kakopappa commented 7 months ago

Yes. i noticed the unpredictable behavior.

a similar issue has been fixed in 3.0.0-alpha2 may be you can give it a try

https://github.com/espressif/arduino-esp32/commit/7c79cdd6e3f12c2ce61275b062ca73c27de37f9b

lilbuzz commented 7 months ago

An alpha version of the esp32 core? I am not sure that I want to try that. I don't want to risk bricking my esp32.

kakopappa commented 7 months ago

Hi,

did some testing with @sivar2311

  1. When I tested the sketch on my IPhone, never connected back to IPhone AP. Looks like bug in Arduino Core https://github.com/espressif/arduino-esp32/issues/8877
  2. When I tested it on my WiFi Repeter, sometimes it failed to connect back to AP.
  3. For Boris, tested it on his WiFi Repeter, it always connects back

I think it's better to use WiFi.status() != WL_CONNECTED in the loop() to detect disconnections rather than depending on callback.

Check this: https://microcontrollerslab.com/reconnect-esp32-to-wifi-after-lost-connection/

lilbuzz commented 7 months ago

I will change my code to use the WiFi.status() method.
Thanks for the link - I will check that out as well.

github-actions[bot] commented 7 months 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!

lilbuzz commented 7 months ago

Do you know if this issue is an issue inside the ESP32 code, or is it in the SinricPro code?

sivar2311 commented 7 months ago

I never had such issues. All my devices reconnects fine after a loss of the wifi and/or internet connection. The issue might be also located at the wifi accesspoint / internet router.

lilbuzz commented 7 months ago

The issue wasn't about reconnecting, it was about SinricPro not firing the onDisconnected event until the connection actually was re-established, which could be minutes or even hours after the connection was lost.

sivar2311 commented 7 months ago

Sorry for the confusion.

It is not the WiFi connection that is being checked, but the WebSocket connection. The WebSocket client seems to have a problem with recognizing a broken connection. (The internal disconnect callback is not triggered).

lilbuzz commented 7 months ago

So, since the WebSocket client is not a part of SinricPro, then we should close this issue.

sivar2311 commented 7 months ago

I'll do some investigations on this.

sivar2311 commented 7 months ago

Debug in progress...

sivar2311 commented 7 months ago

@lilbuzz I was able to identify the cause and I'm working on a fix.

sivar2311 commented 7 months ago

@lilbuzz Fix #355 will be included in version 3.0.1.

To use the changes before the new release is published and available in the library registries:

lilbuzz commented 7 months ago

That is great news!

lilbuzz commented 7 months ago

I tried this out as the new library version automatically updated in the arduino IDE. It now works as expected.

sivar2311 commented 7 months ago

Thanks for the feedback! I am closing this issue now that the problem has been fixed.