0

I am stumped. I have a few Wemos D1 Mini boards that were working on the local WiFi yesterday, yet today none of them will connect. More puzzling is that I can flash Tasmota on them and they all connect to the WiFi, but none with this code that was working yesterday. Any tips would be appreciated.

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(wifi_ssid);

  //Connect to WiFi network so we can reach the MQTT broker and publish messages to topics.
  WiFi.mode(WIFI_STA);
  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.print(F("WiFi connected, "));
  Serial.print(F("IP address: "));
  Serial.println(WiFi.localIP());
}
  • did you update the esp8266 boards package? – Juraj May 22 at 18:16
  • Thanks for the response. No updates- I just turned on my PC to continue on my project from the previous day, and none of the Wemos devices will connect to the WiFi. But I can flash them with Tasmota and they connect to WiFi, so it's not a hardware issue. – user3573562 May 22 at 18:27
  • I think it problem with your wifi master or with your slaves. But if few slaves can't connect to master wifi it can't be problem with your slaves. That restart your computer. It can be problem with avrdude or Arduino IDE. – TheFnafException May 22 at 18:53
  • and what version of the arduino esp8266 package you use? does it use the same SDK version as the Tasmota firmware? – Juraj May 22 at 19:10
  • It looks like Version 2.2.2 of the WiFiesp library. But I've changed nothing. The sketch flashed and worked yesterday, but not today. – user3573562 May 22 at 19:43
0

Solved. (sort of). This is a working workaround.

I have determined that if I use ESP8266WiFi library Version 2.5.0 or later, all I get from WiFi.status() is WL_NO_SSID_AVAIL.

By reverting to ESP8266WiFi library Version 2.4.2, I can get a connection with the same sketch.

(Juraj's comments pushed me in the direction of trying older library versions.)

0

Assuming that it's not something silly and accidental like the password or ssid being changed in your code, there are two things you may be running in to:

  1. The WiFi.begin() function is technically not needed more than once. Values written with it are stored in a separate part of flash memory that is not overwritten by any sketch uploads. Since it's stored persistently, it may start connecting before your connection code is called. This causes a race condition that triggers a bug in the library that is, to my knowledge, still present, and can break the WiFi subsystem. If this has happened, the reason that the other firmware might work is if it fixes the error or somehow uses a different method. You can work around this by waiting a few seconds and then trying to connect if it's not currently connected. Try this fix: https://github.com/kentaylor/EraseEsp8266Flash to see if that's the problem. Alternatively, you can try some of the options in the first link of my next item to see if those work for this purpose.

  2. Remember how I said that the functions persist data in flash? That has a limited write count, and no, that partition has no wear-leveling. After so many writes (and, since begin() is called in setup, it does so every time the device starts or wakes!) it will fail to hold the correct values. The endurance can be quite poor on some cheaper flash devices (and cheaper boards). But, if you want to keep using begin() to set up the WiFi (rather than set it once the normal way and then make sure begin() isn't called again by your code), delete the stored parameters (Does the ESP8266 somehow remember wifi access data?) and then turn off persistence (esp8266 advertising AP even when flashed with custom firmware). I also suggest running the following code fragment to turn off persistence and then stop turning it off (since THAT change persists too!):

    if (WiFi.getPersistent()) { WiFi.persistent(false); }

This latter case is known to break Arduino projects, but NOT nodeMCU Lua ones. If the Tazmota firmware uses a different method, it could also ignore this issue but your code might experience it. To test this, try running the code on a different board (can be the same type, just so long as it's not the same one).

  • the SDK doesn't write the same configuration value to flash – Juraj May 26 at 15:37
  • Did they fix that, or was this always the case? I was under the impression that it did this at least at one point. – RDragonrydr May 26 at 22:05
  • Thanks for the useful information. Is the "Erase Flash: All Flash Contents" in the Arduino IDE different from Kent Taylor's program? I've tried the same sketch on a few Wemos D1 Minis and a couple of NodeMCU boards. When using ESP8266WiFi library Version 2.4.2, they all compile, upload to the ESP, and connect to the WiFi. When using ESP8266WiFi library Version 2.5.0 or later, none of them connect to the WiFi. I strongly suspect my Router, even though I rebooted and later reset it to the original setup. Time for a new router. – user3573562 May 27 at 3:44
  • @RDragonrydr, AT firmware reference Appendix 'A' Notice – Juraj May 27 at 5:07
0

Fixed. My router is ancient and does not support WPA. As of ESP8266WiFi library Version 2.5.0, WPA is is the preferred mode. The solution is to get a better router, or add WiFi.enableInsecureWEP(); before calling WiFi.begin().

WiFi.enableInsecureWEP();
WiFi.begin(wifi_ssid, wifi_password);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.