1

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.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
 
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 Serial.print(WiFi.status());
}
 
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

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 ?

ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Dec 20, 2020 at 18:05
8
  • 6 is WL_DISCONNECTED. what is while while? Commented 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? Commented Dec 20, 2020 at 19:01
  • in the source code of esp8266 Arduino 2.7.4 in libraries/ESP8266WiFi/src/include/wl_definitions.h Commented Dec 20, 2020 at 19:10
  • run a sketch with WiFi.disconnect() only. run it only once. Commented Dec 20, 2020 at 19:13
  • 1
    @Juraj that did not fix it Commented Dec 21, 2020 at 14:40

2 Answers 2

1

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!

answered Dec 22, 2020 at 14:36
1
  • 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. Commented Dec 22, 2020 at 14:47
0

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:

WiFi.setPhyMode(WIFI_PHY_MODE_11G);
answered Feb 16, 2023 at 17:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.