I've seen semi-similar posts outside of these forums regarding WL_CONNECTED, but am having trouble figuring this out. When I run the below code to connect my HiLetGo ESP8266 dev board to my router over WiFi, the status never changes to WL_CONNECTED - even after I get an IP address and actually do have a connection.
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, password);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("****");
Serial.println(status);
Serial.println(WL_CONNECTED);
Serial.println(WL_IDLE_STATUS);
// wait 10 seconds for connection:
delay(10000);
}
I end up in this continuous loop of trying to establish a connection. However if I change the code to this:
IPAddress none(0,0,0,0);
while ( WiFi.localIP() == none) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, password);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("****");
Serial.println(status);
Serial.println(WL_CONNECTED);
Serial.println(WL_IDLE_STATUS);
// wait 10 seconds for connection:
delay(10000);
}
I get past this while loop, have an IP address, but the status remains at 6 (WL_DISCONNECTED). However, I am able to connect it from my browser. I've had a button in the browser trigger code to output the status, but it remains at 6.
While the above code somewhat works for DHCP, it won't work for static as the WiFi.localIP(). Anyone have any thoughts on this?
Well that make more sense than the example I was following as I was confused how the status variable could even be updating. I will update after I get back to my board. Thanks!