How to fix ESP32 error: 'portTICK_PERIOD_MS' was not declared in this scope

Problem:

While trying to compile your ESP-IDF firmware (with or without PlatformIO), you see an error message such as

example.txt
src/main.cpp:13:27: error: 'portTICK_PERIOD_MS' was not declared in this scope
   13 |         vTaskDelay(1000 / portTICK_PERIOD_MS);

Solution

Include FreeRTOS by adding the following lines to the top of the file where the error occured (src/main.cpp in this example):

example.cpp
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

 


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