Same code, different results. ESP32 WiFi works with Arduino IDE, not with VSCode/PIO

Hello folks, I’m new to ESP32 and PlatformIO, and know relatively little about programming in general. I hope I posted this in the right place :slightly_smiling_face:.

I bought some Seeed Studio Xiao ESP32-c6 boards, and have installed the Arduino IDE v2.3.4 (CLI 1.1.1) on a Debian 12 Linux machine.

I also have installed VSCode, PlatformIO v6.1.16/3.4.4 and ESP-IDF v5.3.2. I modified the platformio.ini for my project according to the Seeed Studio wiki to support the Xiao c6 boards, and used arduino as the framework.

I compiled several example projects on both setups and they worked in both IDEs as expected. If I’m not mistaken, I had a simple webserver example project working and connecting to WiFi using PlaformIO as well as Arduino. But then when I tried a sample project (ESP32/ESP8266 Thermostat Web Server - Control Output Based on Temperature | Random Nerd Tutorials), and compiled in PlaformIO it failed to connect. Here’s the part of the setup() code that should do the connecting:

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Failed!");
    return;
  }
  Serial.println();
  Serial.print("ESP IP Address: http://");
  Serial.println(WiFi.localIP());

I modified it a bunch of times, trying to figure out what was happening, and ended up with this (with my real network ssid and password):

const char *ssid = "xxxxxxx";
const char *password = "xxxxxxxx";
IPAddress local_IP(192, 168, 0, 8);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(192, 168, 0, 1); //optional
IPAddress secondaryDNS(192, 168, 0, 1); //optional

void setup(void) {
  delay(3000);
  Serial.begin(115200);
    
  Serial.println("Connecting to WiFi");
  Serial.println(ssid);
  Serial.println(password);
  
  WiFi.setHostname("test");
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }
  if (strlen(ssid) == 0) {
    WiFi.begin();
  } else {
    WiFi.begin(ssid, password);
  }
    
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println(WiFi.status());
    delay(500);
  }
  Serial.println();
  Serial.print("ESP IP Address: http://");
  Serial.println(WiFi.localIP());

The network status that it prints out is something like 6666666611111111111, and very occasionally it will give me a 3 and print out an assigned IP address. Even then the server that should be at that IP is unreachable. And even stranger, the chip will get so hot I can hardly touch it.

In Arduino IDE the same code will connect immediately and stay connected all night, and the example project functions as expected. Also, the chip doesn´t get hot.

My suspicion is that whatever is contained in wifi.h is not behaving the same in PlatformIO’s version. I don’t know where to look. Any advice will be greatly appreciated because I would prefer to use VSCode/PIO/ESP-IDF on my project if I can. Thanks!

The wiki says

platform_packages = 
    framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2
    framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip

Afaik this won’t work any longer.

Long story short:

The ESP32-C6 requires Espressif Aruduino 3.x which will not be supported by PlatformIO - See Support Arduino ESP32 v3.0 based on ESP-IDF v5.1 · Issue #1225 · platformio/platform-espressif32 · GitHub

Fortunately there is community a fork called pioarduino which brings you a full working Arduino 3.x.

Change your platformio.ini

platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10/platform-espressif32.zip

remove the platform_packages and try again.

Ok, I did that, and it updated some things. Now it says:
UnknownBoard: Unknown board ID ‘seeed_xiao_esp32c6’

I do have “board = seeed_xiao_esp32c6” in the platformio.ini file.

It looks like that this board manifest ist not (yet) part of the release.
Create a “boards” directory in your project directory. Download the seed_xiao_esp32c6.json into this directory.

.
├── .pio
├── .vscode
├── boards
│   └── seeed_xiao_esp32c6.json
├── include
├── lib
├── src
│   └── main.cpp
├── test
├── .gitignore
└── platformio.ini

Ok, that is helpful! Thanks so much! I would never have figured out what to do. I did that and it downloaded lots of dependencies and reconfigured everything. The program code compiled without errors and it readily connects to the wifi network…but then immediately crashes with message and reboots:

ESP IP Address: http://192.168.0.8

assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)
Core 0 register dump:

Then follows the register dump and the stack memory. I googled that error and found people talking about it and working on fixes back in October. I don’t quite understand it yet. Any suggestions on this one?

This was fixed finally last Week and is included in Arduino 3.1.0 fix(sntp): Lock / Unlock LWIP if CONFIG_LWIP_TCPIP_CORE_LOCKING is set by mathieucarbou · Pull Request #10725 · espressif/arduino-esp32 · GitHub

We need to find out the differences between the ArduinoIDE and PlatformIO project.

Which Espressif32 Arduino version do you have installed in the ArduinoIDE and which libraries and versions do you use there?

Please show the content of your platformio.ini to allow a comparison.

Interestingly, both versions appear to be the same.

/home/_____/.platformio/packages/framework-arduinoespressif32/platform.txt says:

name=ESP32 Arduino
version=3.1.0

plaformio.ini contains

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples

[env:stable]
;platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10/platform-espressif32.zip

framework = arduino
board = seeed_xiao_esp32c6
lib_ignore = OneWire
lib_deps =
ESP Async WebServer
pstolarz/OneWireNg @ ^0.13.3
milesburton/DallasTemperature

In the Arduino IDE 3.1.0 is installed.

If the core is the same, the differences must be in the libraries.
Which exact libaries do you use in the ArduinoIDE?

In your platformio.ini I see you’re using “ESP AsyncWebServer” (which I guess is the cause for your issue).
Unfortunately you do not specify the exact library (and version) - - There are multiple “ESP Async WebServers” in the PlatformIO Registry

So the question is, which one (and what version) do you use in your Aruino project?

In the Arduino IDE, I show ESP Async Webserver v3.4.3 by Me-No-Dev, and it depends on Async TCP v3.3.1 by the same author. This is the setup that’s working.

In the PlatformIO vscode extension, I have installed versions by Hristo Gochkov, v1.2.4 and 1.1.1 respectively.

I bet that’s the problem! Those are like 5 years old. Is it possible to copy the libraries from wherever Arduino keeps them over to PIO? The versions I need don’t show up as available in the PIO extension.

I’m learning things :-).

Thanks!

The library you’re referencing in ArduinoIDE is this one

So try

lib_deps =
  https://github.com/mathieucarbou/ESPAsyncWebServer @ 3.4.5
  pstolarz/OneWireNg @ ^0.13.3
  milesburton/DallasTemperature

It works! Thank you so much for your patience with me and for figuring this problem out!

The learning curve feels a little bit steep for me :-). I’ve only done my previous MCU projects in Assembler on 8 bit controllers like the HC05, 908 and S08 devices. But I need WiFi :-).

Thanks again!

1 Like

The C6 requires Arduino 3.x which is not directly supported by PlatformIO. And many libraries are also not yet adapted to Arduino 3.x.

I’m glad that everything is working now.
Once you get used to PlatformIO, you won’t want to use anything else.

I’ll know what to watch out for now. Thanks! I’m glad I didn’t give up on it.