Closed lilbuzz closed 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
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);
https://github.com/sinricpro/esp8266-esp32-sdk/assets/7474406/af1e5d4a-9739-43da-be67-4aea09fe2750
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.
Which version of ESP32 core are you using?
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;
}
}
I am using the latest esp core. I always keep my libraries up to date.
Are you asking me to change the setting of the setSleep() method?
I commented the line containing the setSleep call, but that did not change the behavior.
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.
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
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.
Hi,
did some testing with @sivar2311
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/
I will change my code to use the WiFi.status() method.
Thanks for the link - I will check that out as well.
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!
Do you know if this issue is an issue inside the ESP32 code, or is it in the SinricPro code?
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.
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.
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).
So, since the WebSocket client is not a part of SinricPro, then we should close this issue.
I'll do some investigations on this.
Debug in progress...
@lilbuzz I was able to identify the cause and I'm working on a fix.
@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:
lib_deps = https://github.com/sinricpro/esp8266-esp32-sdk
in platformio.ini
That is great news!
I tried this out as the new library version automatically updated in the arduino IDE. It now works as expected.
Thanks for the feedback! I am closing this issue now that the problem has been fixed.
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: