So I have a Wemos D1 mini which I want to connect to my WiFI in order to let is push sensor data to my server. But I cannot connect it with my WiFi as I get a code 6.

// We start by connecting to a WiFi network
Serial.print("Connecting to ");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connected");
Serial.println("IP address: ");

The Serial.print(WiFi.status()); prints 6 which is WL_CONNECT_FAILED if I'm right.

I checked the router and it uses WPA/WPA2, the ssid and password are correct. The router is using 2.4 GHz with WiFi 802.11b and 802.11g.

I used the board to scan, with the example code provided by the esp8266 board manager library thing, and it found my SSID with the ones of my neighbors.

Can somebody tell me what is going wrong?

I already checked solutions like: This one , github answers, etc.

Edit: It can connect to a mobile phone hotspot. It gives code 6 1 time and then it connects. Any one an idea how I connect to the WiFi the router is providing ?

  • 6 is WL_DISCONNECTED. what is while while?
    – Juraj
    Dec 20, 2020 at 18:10
  • @Juraj I see I copied a code I tried. One solution was to take WiFi.waitForConnectResult instead of WiFi.status(). It is fixed now. Where did you find that 6 is WL_DISCONNECTED?
    – Helper
    Dec 20, 2020 at 19:01
  • in the source code of esp8266 Arduino 2.7.4 in libraries/ESP8266WiFi/src/include/wl_definitions.h
    – Juraj
    Dec 20, 2020 at 19:10
  • run a sketch with WiFi.disconnect() only. run it only once.
    – Juraj
    Dec 20, 2020 at 19:13
  • 1
    @Juraj that did not fix it
    – Helper
    Dec 21, 2020 at 14:40

2 Answers 2


Apparently, something went wrong with connecting to the router. The router was casting 802.11 g + n, which for some reason, made the esp8266 give a code 6. I have tried 802.11 b, 802.11 b+g+n, 802.11 n, which work all fine.

So I updated the settings that the router now uses 802.11n and the esp8266 can now connect to the internet!

  • If you can later say more definitively what it was, you can edit your answer for future readers. In a little over a day, I think, you'll be able to accept your own answer, and probably should.
    – timemage
    Dec 22, 2020 at 14:47

For me, the solution was manually setting the mode to 802.11g as explained here: https://github.com/esp8266/Arduino/issues/8412

Add the following code before connecting the WiFi:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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