How to fix ESP8266 PlatformIO error: WIFI_STA was not declared in this scope

Problem:

When compiling your PlatformIO firmware, you see an error message like

example-4.txt
src/main.cpp:49:10: error: 'class WiFiClass' has no member named 'mode'
   49 |     WiFi.mode(WIFI_STA);
      |          ^~~~
src/main.cpp:49:15: error: 'WIFI_STA' was not declared in this scope
   49 |     WiFi.mode(WIFI_STA);
      |               ^~~~~~~~

Solution

You included WiFi.h instead of the correct ESP8266WiFi.h. This will cause multiple issues like reboots on WiFi.begin() even if it compiles correctly.

Replace

example-3.cpp

with

example-2.cpp

everywhere in your source code and does not support

example-1.txt

For more details, see our previous post on How to fix PlatformIO ESP8266 WiFi.h: No Such File or Directory


Check out similar posts by category: Electronics, ESP8266/ESP32, PlatformIO