Fatal error: WiFiServer.h: No such file or directory

This is odd when I put fatal error: WiFiServer.h: No such file or directory in main.cpp No Problem but in
Parsing.cpp
include <Arduino.h>

#include <esp32-hal-log.h>
#include “WiFiServer.h”
#include “WiFiClient.h”
#include “WebServer.h”
#include “detail/mimetable.h”
I get
C:/Users/ats37/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/Parsing.cpp:24:10: fatal error: WiFiServer.h: No such file or directory
I tried it with
-I C:\Users\ats37.platformio\packages\framework-arduinoespressif32\libraries\WebServer\src
-I C:\Users\ats37.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src
no success the same with esp32 and esp32-S3
my
[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

; Spezifische Konfiguration für ESP32-S3 mit 16MB Flash und 8MB PSRAM
board_build.flash_mode = qio
board_build.flash_size = 16MB
board_build.psram_type = opi
board_build.f_flash = 80000000L
board_build.f_cpu = 240000000L

; PSRAM aktivieren und konfigurieren

; Partitionstabelle für großen Flash-Speicher
board_build.partitions = huge_app.csv

monitor_port = COM6
upload_port = COM6
monitor_speed = 115200
build_type = debug

upload_speed = 921600
build_flags =

#-I C:\Users\ats37.platformio\packages\framework-arduinoespressif32\libraries\WebServer\src
#-I C:\Users\ats37.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src
-D bWiFiTest=true
-D ssidWoWi=‘“Wokwi-GUEST”’
-D passwordWokWi=‘“”’
-D ssidWiFi=‘“GigisBoost”’
-D passwordWiFi=‘“Ulrike#123”’

lib_deps = WiFi
mobizt/ESP-Google-Sheet-Client@^1.4.3
git@github.com:me-no-dev/ESPAsyncWebServer.git
git@github.com:me-no-dev/AsyncTCP.git
arduino-libraries/Arduino_JSON@^0.2.0
git@github.com:adafruit/Adafruit_Sensor.git
adafruit/Adafruit BMP280 Library@^2.6.8
adafruit/Adafruit BusIO@^1.15.0
git@github.com:marian-craciunescu/ESP32Ping.git
bblanchon/ArduinoJson@^7.0.1
khoih-prog/ESP32TimerInterrupt@^2.3.0
git@github.com:marian-craciunescu/ESP32Ping.git

If this file cannot be found your platform seems to be broken.

What platform version do you use exactly?

Is deprecated and should be replaced by esp32async/ESPAsyncWebServer

I don’t know what you’re trying to do with WiFiServer but since you’re using AsyncWebServer, why not using AsyncTCP for creating Async servers?

I try this do make

[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev

PlatformIO Core, version 6.1.18

Unfortunately, this does not answer the question about the version as you did not specify the platform version. What’s the version of your installed espressif32 platform?

I have exactly the same problem. Did you find the reason or a solution?

I can even navigate from Parsing.cpp to WiFiServer.h. But in the build, it is not found.

What is your platformio.ini?

I reinstalled the espressif32 framework already multiple times (by deleting the folder .platformio\packages\framework-arduinoespressif32) together with all folders for the different versions (.platformio\packages\framework-arduinoespressif32@....).

platformio.ini is as follows:

[env:esp32TFTDisplay]
platform = espressif32 
board = esp32dev 
framework = arduino
lib_deps =
    squix78/Mini Grafx@^1.2.4
    paulstoffregen/XPT2046_Touchscreen@0.0.0-alpha+sha.26b691b2c8
    contrem/arduino-timer@^3.0.1
    esp32async/AsyncTCP @ ^3.4.10
    esp32async/ESPAsyncWebServer@^3.9.5
monitor_speed = 115200
monitor_filters = esp32_exception_decoder

That’s the cause! If you remove ESPAsyncWebServer from your project, the WiFiServer will work.

If want to you use ESPAsyncWebServer to run an asynchrounus Web-Server in your project, your custom server should also based on AsyncServer instead of WiFiServer! See AsyncTCP’s chargen example about how to write an asynchronous server.

You can remove esp32async/AsyncTCP @ ^3.4.10 from your platformio.ini. AsyncTCP is listed as dependency of ESPAsyncWebServer and the correct version will be installed automatically to your project. See


Alternatively but not recommended:

You can add “lib_ldf_mode = deep+” to your platformio.ini. This allows you to include WiFiServer.h even if ESPAsyncWebServer is present in your project.

Running a synchronous and asynchronous servers at the same time doesn’t make much sense or is bad practice.

Hello sivar2311,

thank you very much for taking care of this.

Remove ESPAsyncWebServer from your project, the WiFiServer will work.

I do not want to get WiFiServer work. I only want to use ESPAsyncWebServer, and when I try to do that, the supposed “absence” of WiFiServer causes problems. So in my project, WiFiServer itself is never needed. But it is searched for when ESPAsyncWebServer is included.

Thank you also for the information that including AsyncTCP in platformini is not necessary. But just to clarify for others who read this thread: It is merely a simplification of platformini and has nothing to do with the original problem. Removing it leads to the uninstallation and reinstallation of exactly the same version:

Library Manager: Removing AsyncTCP @ 3.4.10
Library Manager: AsyncTCP@3.4.10 has been removed!
Library Manager: Installing ESP32Async/AsyncTCP @ ^3.4.10
Downloading [####################################] 100%
Unpacking [####################################] 100%
Library Manager: AsyncTCP@3.4.10 has been installed!

I will try the option “lib_ldf_mode = deep+”.

Running a synchronous and an asynchronous server at the same time makes little sense or is bad practice.

I think you are right. But if I am not mistaken, it is not me who is trying to do that. It is the ESPAsyncWebServer library that ultimately tries to include WiFiServer.h.

The project compiles with this option. Thank you very much for now.

But does this mean that the ESPAsyncWebServer library cannot be used without this option?
If so, shouldn’t this be fixed in the library?
I would just like to have the opinion of someone more experienced than I am before I submit a bug report.

ESPasyncWebserver does not depend on WiFiServer.h! There must be something completely wrong. Can you share your project for a deeper investigation?

I might have the time later today to take a closer look.

To make things easier I created a brand new project without any changes in the default main.cpp file. The only thing I added was the ESPAsyncWebServer-dependency:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = esp32async/ESPAsyncWebServer@^3.9.5

After I ran in some other problems I was bold enough to delete completely the content of .platformio\packages.
In addition I had to run a “Full Clean”.

After that I am now running into the same problem, which I had in my original project:

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------
Library Manager: Installing esp32async/ESPAsyncWebServer @ ^3.9.5
Unpacking  [####################################]  100%
Library Manager: ESPAsyncWebServer@3.9.5 has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing ESP32Async/AsyncTCP @ ^3.4.10
Unpacking  [####################################]  100%
Library Manager: AsyncTCP@3.4.10 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.12.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20017.241212+sha.dcc1105b 
 - tool-esptoolpy @ 2.40900.250804 (4.9.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ESPAsyncWebServer @ 3.9.5
Building in release mode
Compiling .pio\build\esp32dev\src\main.cpp.o
Building .pio\build\esp32dev\bootloader.bin
Generating partitions .pio\build\esp32dev\partitions.bin
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFi.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiAP.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiClient.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiGeneric.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiMulti.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiSTA.cpp.o
esptool.py v4.9.0
Creating esp32 image...
Merged 1 ELF section
Successfully created esp32 image.
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiScan.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiServer.cpp.o
Compiling .pio\build\esp32dev\lib3da\WiFi\WiFiUdp.cpp.o
Compiling .pio\build\esp32dev\lib2d9\AsyncTCP\AsyncTCP.cpp.o
Compiling .pio\build\esp32dev\libf8e\FS\FS.cpp.o
Compiling .pio\build\esp32dev\libf8e\FS\vfs_api.cpp.o
Compiling .pio\build\esp32dev\libf0b\WebServer\Parsing.cpp.o
Compiling .pio\build\esp32dev\libf0b\WebServer\WebServer.cpp.o
Compiling .pio\build\esp32dev\libf0b\WebServer\detail\mimetable.cpp.o
Compiling .pio\build\esp32dev\libd59\ESPAsyncWebServer\AsyncEventSource.cpp.o
Archiving .pio\build\esp32dev\lib3da\libWiFi.a
Compiling .pio\build\esp32dev\libd59\ESPAsyncWebServer\AsyncJson.cpp.o
Archiving .pio\build\esp32dev\lib2d9\libAsyncTCP.a
C:/Users/XXXXXX/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/Parsing.cpp:24:10: fatal error: WiFiServer.h: No such file or directory

********************************************************************
* Looking for WiFiServer.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:WiFiServer.h"
* Web  > https://registry.platformio.org/search?q=header:WiFiServer.h
*
********************************************************************

 #include "WiFiServer.h"
          ^~~~~~~~~~~~~~
compilation terminated.
Compiling .pio\build\esp32dev\libd59\ESPAsyncWebServer\AsyncWebHeader.cpp.o
*** [.pio\build\esp32dev\libf0b\WebServer\Parsing.cpp.o] Error 1
C:/Users/XXXXXX/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.cpp:28:10: fatal error: WiFiServer.h: No such file or directory

********************************************************************
* Looking for WiFiServer.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:WiFiServer.h"
* Web  > https://registry.platformio.org/search?q=header:WiFiServer.h
*
********************************************************************

 #include "WiFiServer.h"
          ^~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\esp32dev\libf0b\WebServer\WebServer.cpp.o] Error 1
==================================================== [FAILED] Took 44.63 seconds ====================================================

 *  The terminal process "C:\Users\XXXXXX\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

(XXXXXX is a replacement of my User-ID)

Adding ESPAsyncWebserver as dependency without including the header will lead to problems. (Execept if you use chain mode deep+).

I wanted to recreate what exactly lead to your problems.

But i had never seen that ESPAsyncWebserver tries to include WiFiServer.h! Also if I check the source files, i don’t see such an include statement.

The include is in libraries/WebServer/src/Parsing.cpp line 24.

But you are right. Adding #include <ESPAsyncWebServer.h> to main.cpp did the trick, in the test-project as well as in my real project.
In my real project I had the include only in a separate class in the lib-Folder, where I wanted to encapsulate the webserver-stuff.

So the problem is solved, but to be honest, I don’t understand why. I thought a library should compile independent of the main program. But my c++ knowledge is pretty limited.

The reason is the Library Dependency Finder (LDF). I am not a PlatformIO dev, so I cannot explain the details as I don’t know them.

OK. In any case, thank you very much.

As an experiment:
Convert your library to a platformio library by using the correct file structure and adding a library.json.
Then add ESPAsyncWebserver as a dependency to your library. This might also fix the issue. This might help the LDF to do its job correctly.

That works also. I did not have to change the structure at all as it was already as recommended for local libraries:

myProjectFolder
   lib
      MyWebClass
         MyWebClass.cpp
         MyWebClass.h

I added into the same folder (MyWebClass) a library.json file with the simple content:

{
    "dependencies": {
        "esp32async/ESPAsyncWebServer": "^3.9.5"
    }
}

After that I could remove the include of ESPAsyncWebServer from main.cpp and the project still compiles.

1 Like