ESP8266 Wemos D1 mini wifi won't connect until new wifi CH

Hi there,

i have a Wemos D1 mini with ESP8266 on it and can connect to my wifi with the following code:

#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <string>

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

const char* SSID = "MYSSID";
const char* PSK = "MYPSK";

WiFiClientSecure espClient;         /* Secure client connection class, as opposed to WiFiClient */
PublicKey key(pubkey);

void setup_wifi() {
    WiFi.mode(WIFI_STA);
    WiFi.begin(SSID, PSK);
    Serial.println("Try to connect to wifi ");
    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
    }   
    Serial.println(WiFi.localIP());
    espClient.setX509Time(timeClient.getEpochTime());
    Serial.write(timeClient.getEpochTime());
}

void setup() {
     
    // Serial Monitor
    Serial.begin(115200);
   
    // STATUS LED
    pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output

    // WIFI
    setup_wifi(); 
}

 
void loop()
{     
 
}

So far, everything is fine, it connects as expected and it. But when i turn off the power supply of the ESP and restart it a few hours (or a day) later then the only solution to get an wifi connection again is to go to my routers settings and change the wifi channel from 11 to 10 or something else below 11. After that channel change the ESP is properly connecting to wifi again. Without changing the wifi channel, there will no wifi connection be established.

Is this a known issue or can someone help me out?

Thanks and best regards from germany.

It's not a known problem as far as I know. I have experienced one router (not my home router) which refused to allow a wemos to connect even one time.

Have you tried other code with this wemos and router? Do you think the problem is unique to this code or could it be a problem with your router or wemos?

Hi PaulRB,

thanks for your reply.
Do you have an other code for me to test? That's the only code i have tested so far.
I exchanged the Wemos right now with another one, but that's no solution.

Use one of the example sketches such as the simple server sketch. Any that connects to your WiFi.

The problem with the examples is, that they use WifiClient instead of WifiClientSecure. I need WifiClientSecure for the X509 cert. of the MQTT Broker.

But yes, with WifiClient (if i remove all the security stuff like X509 and HTTPS) it will work without changing the channel in the router.

Another strange behavior is, that when i turn on Debug for Wifi i can see, that Wifi is connected, but return code is still (6) from Wifi.status(). Therefore the while loop will still be executed .... i don't get it...

connected with <MY_SSID>, channel 11
dhcp client start...
wifi evt: 0
6
Mode: STA
PHY mode: N
Channel: 11
AP id: 0
Status: 1
Auto connect: 1
SSID (6): <MY_SSID>
Passphrase (20): <MY_PSK>
BSSID set: 0

wifi.status(): 6

Meanwhile i could figure out, that the wifi connection got stuck here:

connected with <MY_SSID>, channel 6
dhcp client start...
wifi evt: 0
pm open,type:0 0

The power management (pm) is set to "never go to sleep" for wifi. Otherwise there would be pm open, type: 2 0

Hi, I have the same problem. I need to change ch in my router (asus AX58U) to get my Wemos D1 mini v4.0.0 reconnect after reboot or reflash. Did you find a cure?

I have been flashing with both arduino code and ESPhome, but problem persists.

This is interesting, I also have a Asus Router (AX82U) and the Wemos often gets stuck until I change the wifi channel.

I probably have a similar issue. The D1 mini only connects after I change the 2.4GHz channels. Then it is able to connect if I reset it within a short time.
But if I try to connect again in an hours time, it needs a channel change again from the router. Very strange. Am using the same WiFiClient library and a Virgin Media HUB 6 modem/router.

The only change I've made to the board is to solder header pins facing upwards on the antenna side of the board where the 8266 is also housed. The chip and antenna are sort of jailed within those headers; unlikely that's causing it, I also thought my soldering might have killed something!

Update: If I assign it a static IP address, the problem goes away. It immediately gets onto the WiFi now. Wondering if this is related to how different routers implement DHCP and how long IPv4 addresses are reserved, leased or cached

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.