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 ?
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– timemage12/22/2020 14:47:23Commented 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:
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
while while
?