PlatformIO Community

ESP8266 Async Web Server Error

Hey all, new to PlatformIO I was testing out the async web server tutorial from Random Nerd Tutorials. This one specifically, ESP8266 NodeMCU Async Web Server – Control Outputs | Random Nerd Tutorials

I’m using VSCode PlatformIO extension and I get this error: src\main.cpp: In function ‘String processor(const String&)’:
src\main.cpp:62:137: error: ‘outputState’ was not declared in this scope
62 | buttons += "

Output - GPIO 5

<label class=“switch”><input type=“checkbox” onchange=“toggleCheckbox(this)” id=“5” " + outputState(5) + “><span class=“slider”>”;

The only thing I’ve changed from the tutorial is the WiFi creds. It works perfectly fine if I run the same code in the Arduino IDE but not PlatformIO. Any ideas?

Here is my platform.ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples

[env:d1_mini_lite]
platform = espressif8266
board = d1_mini_lite
framework = arduino
lib_deps =
github link to me-no-dev ESPAsyncTCP
github link to me-no-dev ESPAsyncWebServer

You must properly convert the given Arduino sketch code (.ino) in C++ code if you write your code in a *.cpp file in PlatformIO. See FAQ. Specifically, you need to place the function declaration

String outputState(int output);

at the top of the program but after Arduino.h and the libraries are included.

Converting the .ino file into .cpp will give you better Intellisense in VSCode. If you just want to quickly try out a sketch though, rename your src/main.cpp into src/main.ino and then PlatformIO will behave like the Arduino IDE and no code changes are needed.

Ah thank you so much! That worked!