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