ESP-IDF WiFi example build fails

I am trying to build the scan example from the official repository: esp-idf/scan.c at master · espressif/esp-idf · GitHub
It seems that esp_netif.h header is not present in PlatformIO. Anyone knows how can I solve this issue?

> Executing task in folder esp-wifi: platformio run <

Processing esp32dev (platform: https://github.com/platformio/platform-espressif32.git; board: esp32dev; framework: espidf)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.12.0 #9bc9c3a > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (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-espidf 3.40000.200303 (4.0.0) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.190618 (2.28.51) 
 - toolchain-xtensa32 2.80200.200226 (8.2.0)
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/esp32dev/esp-idf/src/main.c.o
Archiving .pio/build/esp32dev/esp-idf/app_update/libapp_update.a
Indexing .pio/build/esp32dev/esp-idf/app_update/libapp_update.a
In file included from /Users/kdubovikov/.platformio/packages/framework-espidf/components/esp_common/include/esp_timer.h:44,
                 from /Users/kdubovikov/.platformio/packages/framework-espidf/components/freertos/include/freertos/portmacro.h:84,
                 from /Users/kdubovikov/.platformio/packages/framework-espidf/components/freertos/include/freertos/portable.h:96,
                 from /Users/kdubovikov/.platformio/packages/framework-espidf/components/freertos/include/freertos/FreeRTOS.h:105,
                 from src/main.c:12:
src/main.c: In function 'wifi_scan':
src/main.c:104:21: error: implicit declaration of function 'esp_netif_init'; did you mean 'esp_wifi_init'? [-Werror=implicit-function-declaration]
     ESP_ERROR_CHECK(esp_netif_init());
                     ^~~~~~~~~~~~~~
/Users/kdubovikov/.platformio/packages/framework-espidf/components/esp_common/include/esp_err.h:118:31: note: in definition of macro 'ESP_ERROR_CHECK'
         esp_err_t __err_rc = (x);                                       \
                               ^
src/main.c:106:5: error: unknown type name 'esp_netif_t'; did you mean 'esp_err_t'?
     esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
     ^~~~~~~~~~~
     esp_err_t
src/main.c:106:30: error: implicit declaration of function 'esp_netif_create_default_wifi_sta' [-Werror=implicit-function-declaration]
     esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:106:30: warning: initialization of 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
src/main.c:19:32: error: 'CONFIG_EXAMPLE_SCAN_LIST_SIZE' undeclared (first use in this function); did you mean 'DEFAULT_SCAN_LIST_SIZE'?
 #define DEFAULT_SCAN_LIST_SIZE CONFIG_EXAMPLE_SCAN_LIST_SIZE
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:112:23: note: in expansion of macro 'DEFAULT_SCAN_LIST_SIZE'
     uint16_t number = DEFAULT_SCAN_LIST_SIZE;
                       ^~~~~~~~~~~~~~~~~~~~~~
src/main.c:19:32: note: each undeclared identifier is reported only once for each function it appears in
 #define DEFAULT_SCAN_LIST_SIZE CONFIG_EXAMPLE_SCAN_LIST_SIZE
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:112:23: note: in expansion of macro 'DEFAULT_SCAN_LIST_SIZE'
     uint16_t number = DEFAULT_SCAN_LIST_SIZE;
                       ^~~~~~~~~~~~~~~~~~~~~~
src/main.c:113:22: warning: unused variable 'ap_info' [-Wunused-variable]
     wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
                      ^~~~~~~
cc1: some warnings being treated as errors
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/encode.c.o
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/mem.c.o
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/net.c.o
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/option.c.o
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/pdu.c.o
Compiling .pio/build/esp32dev/esp-idf/coap/libcoap/src/resource.c.o
*** [.pio/build/esp32dev/esp-idf/src/main.c.o] Error 1
======================================================================= [FAILED] Took 8.84 seconds =======================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

My platformio.ini:
[env:esp32dev]
platform = GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO
board = esp32dev
framework = espidf
monitor_speed = 115200
upload_speed = 115200

I have noticed that netif is missing from the esp-idf components at /Users/kdubovikov/.platformio/packages/framework-espidf/components. It is present in the official IDF repository though: github. com/espressif/esp-idf/tree/master/components/esp_netif.

You are running the example from the master branch which is a bleeding edge version after release v4.1. PlatformIO runs on

so v4.0. Su just run the example from the v4.0 release branch instead.

2 Likes

Is it possible to manually use 4.1 ?

The path of least resistance is using the latest PlatformIO released platform and packages versions with the compatible examples of the same version, aka v4.0, everything else unreleased is untested.

You may still have some success if you use platform_packages (docs) to point framework-espidf at a ESP-IDF v4.1 using

platform_packages = 
    framework-espidf @ https://github.com/espressif/esp-idf.git#release/v4.1

in the platformio.ini.

I suspect I will break something else when trying to upgrade…
Is it planned to support 4.1 or will only the next major be supported again ?

Since PlatformIO manages all installed packages in seperate folders, when it downloads v4.1 it will not touch any other previously downloaded package. Removing the lines will revert back to the original state, so it’s a pretty safe thing to do.

Ask the devs at Issues · platformio/platform-espressif32 · GitHub.