PlatformIO Community

ESP32 issues connecting Wifi network

Hi,
I’m having some issues doing a simple code that connects to my Wifi Network.
(never gets a IP address).

Using the same code in Arduino IDE works well

Code:

My platformio.ini:

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps = WiFi PubSubClient

pio version:

Updating tool-scons                      @ 3.20501.2      [Up-to-date]
Updating tool-unity                      @ 1.20302.1      [Up-to-date]
Updating contrib-pysite                  @ 0.1.4          [Up-to-date]
Updating contrib-piohome                 @ 0.6.1          [Up-to-date]
Updating tool-pioplus                    @ 0.13.8         [Up-to-date]

Platform Manager
================
Platform Espressif 32
--------
Updating espressif32                     @ 0.12.0         [Up-to-date]
Updating tool-esptoolpy                  @ 1.20100.0      [Up-to-date]
Updating toolchain-xtensa32              @ 1.50200.2      [Up-to-date]
Updating framework-arduinoespressif32    @ 1.4.0          [Up-to-date]
Updating framework-espidf                @ 2.211.0        [Up-to-date]
Updating tool-espotapy                   @ 1.1.0          [Up-to-date]

Platform Espressif 32
--------
Updating espressif32                     @ c0bdf20        [Up-to-date]
Updating tool-esptoolpy                  @ 1.20100.0      [Up-to-date]
Updating toolchain-xtensa32              @ 1.50200.2      [Up-to-date]
Updating framework-arduinoespressif32    @ 1.4.0          [Up-to-date]
Updating framework-espidf                @ 2.211.0        [Up-to-date]
Updating tool-espotapy                   @ 1.1.0          [Up-to-date]

Serial console:

Connecting.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
``` 

Can you help this issue, and how to debug it?

Thanks

Could you try staging version?

I had similar problems with the 8266. I could go all evening without a connect. I wound up creating this sub and calling it before trying to connect, even at startup.

/*
 * ESP is a pain to ensure statup
 * happens on a clean slate.
 */
void WiFiReset() {
    WiFi.persistent(false);
    WiFi.disconnect();
    WiFi.mode(WIFI_OFF);
    WiFi.mode(WIFI_STA);
}

It’s worth a try…

Ivan, I have had a similar issue. I was able to compile and connect over the weekend but then all of a sudden with nearly identical code I have been unable to connect to my wifi network with this code.

I had to rollback to 0.10.0 to get this code working again.

[env:m5stack-core-esp32]
platform = espressif32@0.10.0
board = m5stack-core-esp32
framework = arduino
upload_port = COM[7]

Could you reproduce this issue with staging version?

i had this issue i managed to fix it by changing while (WiFi.status() != WL_CONNECTED) {

to while (WiFi.status() == WL_CONNECTED) {

was driving me nuts i was looking at loads of code a noticed this was different in one of the sketches