C++ code check has "ghost errors"

I am getting error messages in VSCode I cannot deduct from the code (a simple UDP server test). The code is compiling and running fine. Errors are as follows:
Bildschirmfoto vom 2024-05-03 14-43-45

My platformio.ini is:

platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
lib_deps = 
monitor_speed = 115200
monitor_dtr = 0
monitor_rts = 0
lib_ldf_mode = deep+
monitor_filters = esp32_exception_decoder
build_flags = -DMY_SSID=\"hidden\" -DMY_PASS=\"hidden_as_well\"

The code is:

#include <Arduino.h>

#define UDPMODE 2

#if UDPMODE == 1
  #include <WiFi.h>
  #include <WiFiUdp.h>
#elif UDPMODE == 2
  #include <Ethernet.h>
  #include <EthernetUdp.h>

/* WiFi network name and password */
const char * ssid = MY_SSID;
const char * pwd = MY_PASS;

// IP address to send UDP data to.
// it can be ip address of the server or 
// a network broadcast address
// here is broadcast address
// const char * udpAddress = "";
const int udpPort = 502;

//create UDP instance
#if UDPMODE == 1
WiFiUDP udp;
#elif UDPMODE == 2
// The WIZ5500 module needs the reset line connected to a GPIO
#define RESET_P GPIO_NUM_26
EthernetUDP udp;

// Reset W5500 module
void WizReset() {
  Serial.print("Resetting Wiz W5500 Ethernet Board...  ");
  pinMode(RESET_P, OUTPUT);
  digitalWrite(RESET_P, HIGH);
  digitalWrite(RESET_P, LOW);
  digitalWrite(RESET_P, HIGH);


void setup(){

#if UDPMODE == 1
  //Connect to the WiFi network
   WiFi.begin(ssid, pwd);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("Connected to ");
  Serial.print("IP address: ");

#elif UDPMODE == 2
  // Fire up Ethernet
  IPAddress lIP;
  byte mac[6]={0xAA,0xAB,0xAC,0xAD,0xAE,0xAF}; // Fill in appropriate values here!

  // prime the WIZ5500 module

  // Try to get an IP via DHCP
  if (Ethernet.begin(mac) == 0) {
    // No. DHCP did not work.
    Serial.print("Failed to configure Ethernet using DHCP\n");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.print("Ethernet shield was not found.  Sorry, can't run without hardware. :(\n");
    } else {
      if (Ethernet.linkStatus() == LinkOFF) {
        Serial.print("Ethernet cable is not connected.\n");
    while (1) {}  // Do nothing any more
  // We seem to have a connection to the router
  lIP = Ethernet.localIP();
  Serial.printf("My IP address: %u.%u.%u.%u\n", lIP[0], lIP[1], lIP[2], lIP[3]);

  //This initializes udp and transfer buffer

void loop(){
  //processing incoming packet, must be called before reading the buffer
  uint32_t bts = udp.parsePacket();
  //receive response from server, it will be HELLO WORLD
  if (bts) {
    char *buffer = new char[bts + 1];
    if(udp.read(buffer, bts) > 0){
      buffer[bts] = 0;
    delete[] buffer;

I suppose the static code check is missing to scan platformio.ini for additional defines and include paths, but why?

Everything works fine for me. No errors are reported.
Neither with #define UDPMODE 1 nor with #define UPDMODE 2

I guess that a setting or an addon is not correct.

Thank you for checking.

In the meantime I manually added ${workspaceFolder}/.pio/** to the list of include paths for IntelliSense and now at least the errors resulting from the lib_deps setting seem to be gone, while those referring to the build_flags still are shown.

I suppose that something still is missing or has been lost. Rats. :cry:

The umpteenth “Rebuild Intellisense Index” seems to have fixed it now. VSCode kind of sucks at times…

1 Like