How to fix PlatformIO ESP8266 WiFi.h: No Such File or Directory
Problem:
When compiling your PlatformIO firmware, you see an error message like
platformio_wifi_error.txt
src/main.cpp:2:10: fatal error: WiFi.h: No such file or directory
**************************************************************
* Looking for WiFi.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:WiFi.h"
* Web > https://platformio.org/lib/search?query=header:WiFi.h
*
**************************************************************
2 | #include <WiFi.h>
Solution
Instead of
include_wifi_h.cpp
#include <WiFi.h>
use
include_esp8266wifi_h.cpp
#include <ESP8266WiFi.h>
Now delete the .pio
folder from the project directory to ensure a clean build by using:
remove_pio_dir.sh
rm -rf .pio
In case that doesn’t help, see our article on how to fix this issue by adding the WiFi library to the dependencies: How to fix PlatformIO WiFi.h: No Such File or Directory
Check out similar posts by category:
Arduino, Electronics, ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow