Compile error in PIO while Arduino IDE compiles fine for ESP32

Hello All,

the code attached at the end, which does not do anything meaningful after I stripped it down in an attempt to locate the issue, compiles fine in Arduino IDE.

In VSC/Platformio 1.97.2, using platform Espressif32 3.2.0, I am receiving the following error messages duirng compile time. I could not find anything on the internet, that gave me a clue what is causing this:

Compiling .pio\build\esp-wrover-kit\libbf6\WebSockets\WebSockets.cpp.o
In file included from .pio\libdeps\esp-wrover-kit\WebSockets\src\SocketIOclient.cpp:9:0:
.pio\libdeps\esp-wrover-kit\WebSockets\src\WebSocketsClient.h:59:51: error: missing binary operator before token "("
 #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
                                                   ^
.pio\libdeps\esp-wrover-kit\WebSockets\src\WebSocketsClient.h:126:51: error: missing binary operator before token "("
 #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)
                                                   ^
Compiling .pio\build\esp-wrover-kit\libbf6\WebSockets\WebSocketsClient.cpp.o
*** [.pio\build\esp-wrover-kit\libbf6\WebSockets\SocketIOclient.cpp.o] Error 1
In file included from .pio\libdeps\esp-wrover-kit\WebSockets\src\WebSocketsClient.cpp:26:0:
.pio\libdeps\esp-wrover-kit\WebSockets\src\WebSocketsClient.h:59:51: error: missing binary operator before token "("
 #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)

At first glance, it looked as if there would be bugs in the WebsocketsServer.h library. However, this was hard to believe and after all it did compile fine in Arduino IDE. I had version 2.6.1 of this lib installed, both in Platformio and in Arduino IDE. After several hours of trial and error I am at the end of ideas how to solve this.
Any ideas by anyone what could be causing this and how this can be avoided?

#include <Arduino.h>

#include <WiFi.h>
#include <WebSocketsServer.h> 
#include <WebServer.h>

const char* ssid = "xxxx";
const char* password = "xxxx"; 

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 3600;
const int   daylightOffset_sec = 3600;

WebServer server(80); // Deklariert ein Objekt der WebServer Bibliothek dass auf HTTP Anfragen auf Port 80 hört
WebSocketsServer webSocket = WebSocketsServer(81); // Deklariert ein Objekt der WebSocketServer Bibliothek auf Port 81

void webSocketEvent (byte num, WStype_t type, uint8_t * payload, size_t length) {
  Serial.println("What's happening?");
  int typ = type;
  switch(typ) {
    case WStype_DISCONNECTED: // enum that reads status, this is used for debugging
      Serial.println("Websocket: Client Disconnected");
      break; 
    case WStype_CONNECTED: // Check if a WebSocket Client is connected or not
      Serial.println("Websocket: Client Connected");
      //add code here what to do when connected
      break;
    case WStype_TEXT: // check response from client
      Serial.println("Response received");
      break;
    default: 
      Serial.println("Gemsen?");
  }
}

void setup()
{
  Serial.begin(115200); 
  //-----------------------------------------------
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED){Serial.print("."); delay(500);}
  WiFi.mode(WIFI_STA); // Connecting to an existing WiFi network in Station mode
  Serial.println();
  Serial.print("Local IP: ");
  Serial.println(WiFi.localIP());
  //-----------------------------------------------
  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);

  
  // server.on("/", serverRouting); // War deaktiviert und funktioniert - warum auch immer - trotzdem. 
  //-----------------------------------------------
  server.begin(); // Startet den Webserver, der hier aber noch gar nichts tut
 
  webSocket.begin(); // Startet den Websocket Server
  webSocket.onEvent(webSocketEvent); // Bei einer hereinkommenden websocket Nachricht gehe zu Funktion 'WebSocketEvent'
  Serial.println(F("HTTP server and Websocket server started"));
}

void loop() {
  
}

Note: The lines “int typ = type; switch(type) …” were one of my attempts but turned out unnecessary and without impact to the issue. A simple "switch(type) has the same effect.

In advance thanks for your help.

Greetings
Werner

Are you sure about platform = espressif32 @ 3.2.0 ?

That’s Espressif32 Arduino 1.0.6 based on ESP-IDF 3.3.5 and was released in march 2021!

This would not match WebSockets @ 2.6.1 which was released in September 2024!

The latest official available Espressif32 platform version is 6.10.0 (Arduino 2.0.17 based on ESP-IDF 4.4.7).

If you want to use Arduino 3.x you have to use pioarduino/platform-espressif32.
You can get the latest Espressif32 Arduino version by changing the platformio.ini

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

This is currently version 3.1.2 (released on February 13, 2025)

A detailed overview of the versions can be found here.

@sivar2311, thank you very much for your reply!

Are you sure about platform = espressif32 @ 3.2.0 ?

Well, platformio.ini actually just says platform = espressif32
but when I open PIO Home and click on “Platforms” button, I can see, besides the “Atmel AVR” 3.3.0 a second entry “Espressif 32” and on the right side it says 3.2.0. That is where I took the version info from.


Arduino IDE is version 2.3.3.

I did not realize that the ESP-IDF was so old.
I will now change to pioarduino as you have suggested above.
I suppose this will address the issues.

Thanks again for your help!

Regards
Werner

Well, with pioarduino version 3.1.2, the previous issues have indeed disappeared, using the same short source code as above.
There were a few warnings and I had to move the project to a path that only had “english characters in the path”. I had a “µC” folder in the path where the “µ” disqualifies and caused the linking step to fail. Luckily, I was not the first one to run into this issue.

Next, I will use the complete code, as it was before I started to strip it down. I know it is still buggy, let’s see if there are further issues which are accounted to the… compiler (?).
I made a quick test before and saw lot’s of OneWire related defects…

Note that there are breaking API changes between Arduino 2.x and 3.x.
Please check Migration from 2.x to 3.0 - - — Arduino ESP32 latest documentation

Seems you both are completely lost in versions mixage. Arduino IDE version have nothing to do with Arduino versions etc.

@sivar2311, I looked through the Espressif page about the API changes between Arduino 2.x and 3.x but nothing caught my eye, ie. no changes related to OneWire.

I found a forum entry about significant changes in the version 3.0.0 of the esp32 boards platform that adds support to Arduino IDE for the ESP32. As a consequence, a change had to be done to the OneWire library.
Not sure if this is relevant in any way for Platformio, suppose not.
I did upgrade the OneWire lib in Platformio to the latest 2.3.8 release just in case but it made no difference. There are still about 8 OneWire related compiler errors saying all in different places of the OneWire_direct_gpio.h:

error: ‘GPIO’ was not declared in this scope.

Running out of ideas again.

Werner

Correct. Not just your code must match the new API, also the libraries used must match the new API.

From the forum you linked, the solution is to use the library directly from github.
There was an update on Sep 4, 2024: Update OneWire_direct_gpio.h

Unfortunately, this update is not (yet) part of a release.

Remove the OneWire from your lib_deps and use the github-link instead:

lib_deps = 
  https://github.com/PaulStoffregen/OneWire

Wow, it just compiled successfully, besides a few warnings that were not OneWire related.
Thank you very much!

I can see now how working with an ESP32 in PIO is not trivial.
Last week I had a problem with the WiFi.h lib, which took me a day to fix, although, admittedly, in this case PIO provided instructions.
Today I was really close to going back to Arduino IDE, despite all the bells and whistles of PIO. It is no fun, if I have to spend days to find fixes for what I would call infrastructure stuff that should just be working. For people with little programming experience like me, finding these fixes is mostly possible only thanks to helpful people like you.

Werner

1 Like

Using Espressif32 Arduino 3.x with an outdated / incompatible library would cause the same issues on ArduinoIDE.