-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WiFi.status shows connected when connection is lost #5912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a workaround, using the WiFiEventStationModeDisconnected event (which does fire), performing a disconnect (even though the connection is already disconnected) fixes the WiFi.status() problem.
|
That's a nice workaround for core release 2.5.0. edit: If a release is needed, version 2.4.2 hasn't this bug (it uses fw 2.2.1). |
Could this also be a nice work-around for core 2.4.x issues? |
@TD-er core-2.4.2 uses fw 2.2.1, same as with current master (by default). |
Well I have not tried this code myself. So I was hoping this would be some help also, since I have really no clue how to truly detect the connection status. |
I would be hesitant to implement a change as you did in your commit. It is a patch that does not solve the root cause. In my experience, WDT reset are caused by other types of problems. One of the most useful things is the ESP.getHeapFragmentation() recently introduced. It shows the state of memory better than just looking at the available memory from ESP.getFreeHeap(). You may have fragmentation problems. Also, if you are using char arrays, look out for overflows. Those will cause a lot of WDT resets. |
In the builds with core 2.6.0 I do have the heap fragmentation shown in the sysinfo page and also have been running some tests to see if the fragmentation was an issue. I know it isn't going to solve the root cause of these WDT resets, but it has already taken 100's of hours for me to get some grip on these WDT resets that I really want to try anything. I will now have a good look at parts that handle strings to see if there's something that may use char arrays since calling Also the inaccuracy of the wifi connected status is also bugging me in other ways. That SDK should not have this specific issue, right? |
I guess not (sdk 2.2.2-dev has not been extensively used though) |
I'm using 2.5.0 and the moment esp8266 does a network request, as getting NTP time, then the event fires... as a check, I keep pinging the router and bang, the event fires as soon as the router drops the connection. However, the ping is too intrusive and generates too much instability especially if using the AP mode. please advise. I'm using this kind of ping to maintain net activity, it works as a test and might shed some light on the problem origin... extern "C" {
#include <ping.h>
}
void tick_back(void *opt, void *resp) {
constexpr int ticks_tolerance=3;//how many fails in a row will we tolerate (or something like that)
static volatile int ticks_ok=0;
ping_resp* ping_resp = reinterpret_cast<struct ping_resp*>(resp);
if (ticks_ok>0&&ping_resp->ping_err==-1) ticks_ok--;
else if (ticks_ok<ticks_tolerance) ticks_ok++;
wifiConnected&=ticks_ok>0;//update my own state
}
//network tick, not using delay stuff and sending only one packet
void nw_tick(IPAddress dest) {
static ping_option tick_options;
memset(&tick_options, 0, sizeof(struct ping_option));
tick_options.count = 1;
tick_options.coarse_time = 0;
tick_options.ip = dest;
tick_options.sent_function = NULL;
tick_options.recv_function = reinterpret_cast<ping_recv_function>(&tick_back);
ping_start(&tick_options);
} |
@d-a-v yes I saw it, but I'm already using the wifi events. Changed to the latest core version: and the problem persists, I'm recovering ok from a lost connection as soon as I get my esp8266 is primarily a web server and it does not send network requests (unless set manually to do so)... thanks for your reply 👍 I'm open to any suggestions |
this ping thing is working for me, instability was due to a bug, I was requesting (and debug printing) it free-wheel on loop, now that I set up a proper 500ms the esp8266 seems stable and I get the events firing as soon as the connection is lost. still I'm missing a WL_CONNECTING state on WiFi.status(), well i can keep my own track on that of course, but it would be nice. a view ofesp8266/arduino code gave me no clue on how to solve this, so i guess it is even deeper. hope it helps |
@neu-rah Just to be sure, you use that internal ping trick at a 500 msec interval? |
@TD-er yes, I'm pinging the gateway. Not sure what you mean by "internal", I'm using the pasted code to ping the gateway and yes 500ms, experimented with other values, but this one seems enough and esp8266 seems stable. |
Most topics about this just suggested to let some host ping the node, which makes it "miraculously" work more stable. |
@TD-er What are your findings ? #2330(comment) |
@d-a-v
And on top of that, there is a setting to continuously send these ARP packets with an increasing interval. To be honest, I don't see a lot of differences in connectivity between enabling/disabling this last setting. In short, I don't think it does help resolving all missing packets, but it is strangely not missing any ping packet. Even the first ping sent when it is in low power mode does get a reply even when it may need a few 100 msec for such a reply. (sometimes up to 700 msec) |
facing this issue if i set autoreconnect off and use both wifi mode
currently below piece of code somehow working. i calling it in loop after every 10 seconds.
looking for any better suggestions/solution. |
good day! neu-rah, can you please tell me how you solved the problem in more detail or can you write the code that you used to solve the problem? I have the problem that the internet service is very unstable and it happens many times that I have connection to the router but there is no internet and in the ESP8266 WDT is activated, but when the internet connection returns I have to manually reset my ESP8266 !! thank you |
@javierferwolf all code is above, but after some update I had to remove it, guess it or something with same purpose was done into the core. Fell free to experiment with it thou. |
@neu-rah thanks for replying, I don't have much programming experience so I would like to know where in the code? or in which part of the ESP8266WiFi library do I have to put the mentioned code: extern "C" { void tick_back(void opt, void resp) { //network tick, not using delay stuff and sending only one packet |
@javierferwolf #5912 (comment) i have the include on top of sketch (with the others, if any) then the functions and then i call if i recall it correctly |
hi @neu-rah Thank you for your answers! but sorry I can't understand how I can implement your code in the sketch, as I understand it, the nw_tick funtion i only call 500ms But what do I do with this? for example how could I implement in this simple sketch?
thank you Rui! |
I'm facing the same issue in the latest 2.5.1 SDK. |
@yangyud-cn You should try again with latest release 2.7.1. @PurpleAir is it OK to close this issue ? |
@d-a-v, I'm using PlatformIO 2.5.1 which is Arduino 2.7.1, according to https://github.com/platformio/platform-espressif8266/releases Interestingly, enabling DEBUG with ESP8266WebServer actually lower the chance of failure. #define DEBUG_ESP_HTTP_SERVER This makes me suspicious that there could be some timing related issue in network stack code, possibly some race condition. Here are the log I collected, hope that helps. I also included my monitor and reconnect code. ping Gateway 192.168.8.67 => 192.168.8.1 ... OK ping Gateway 192.168.8.67 => 192.168.8.1 ... Fail -- Several minutes later The IP lost -- ping Gateway 192.168.8.67 => 192.168.8.1 ... Fail ping Gateway 192.168.8.67 => 192.168.8.1 ... Wifi not connected : 3 Mode: STA .... Then I have to fall back to Reboot to recover. My Ping code:
Fragment of my monitor code:
|
BTW, I tried the older version 2.6.2 (https://github.com/esp8266/Arduino/releases/tag/2.6.2) and with I actually managed to crash it with a simultaneous "ping -f" while doing the wgets with a WDT crash. But that is already pretty stable. WDT @ 0x40104185, which is located inside this: |
@yangyud-cn |
Per internal discussions, pushing back to v3. |
Just curious, what is the intended fix, @devyte ? My work-around for now (which is far from ideal) is to detect the inconsistency of the wifi state and if it has not improved after some timeout (15 seconds in my setup) it will turn off the WiFi and try again. It does seem to be a timing issue, as it occurs way more often when I have the UDP syslog feature in my software enabled. |
There isn't one. Per previous experience in such cases, this requires investigation, and that can take a while. We don't want to hold up v3 any further. |
A workaround for me when I detect such anomaly is to do a wifi.reconnect. |
Closing as duplicate #7432, let's follow-up there ! |
WiFi.status() returns WL_CONNECTED after connection is lost when using WiFi.setAutoReconnect( false );
The included MCVE produces the following output:
The AP was turned off shortly after the connection was established and you will notice the logs show loss of IP but status() returns WL_CONNECTED. This only happens when using WiFi.setAutoReconnect( false )
The text was updated successfully, but these errors were encountered: