PlatformIO Community

ESP-IDF V4.1 esp_event_handler_instance_t not found

A few days ago I created a project using the ESP-IDF framework inside PlatformIO running in Atom. At that stage it was ESP-IDF V4.0 and I coded accordingly.
Today I saw that V4.1 was released and I upgraded the framework.
I also changed some of the code to conform to the V4.1 changes in the WiFi area so that it is a (slightly) modified version of their ‘station_example_main.c’ example program.
That code contains a reference to a typedef ‘esp_event_handler_instance_t’ which the compiler now flags as undefined. However it is exactly the same as in the sample code.
Everything else seems to compile OK (including the various ‘xxx_netif_xxx’ functions).
Has anyone else come across this?
Susan
(BTW I’m also posting this in the Espressif forum as I’m not sure if it is an ESP-IDF bug or the way that it has been implemented in PlatformIO - or if I’m doing something stupid!)

The current master branch contains the definition

but not release v4.1.

What full error message is GCC giving and what exact code are you compiling?

The source I compiling is https://github.com/espressif/esp-idf/blob/c77c4ccf6c43ab09fd89e7c907bf5cf2a3499e3b/examples/wifi/getting_started/station/main/station_example_main.c
which should be the latest example code from Espressif.

I have tried to use the example code directly which has resulted in some extraneous error messages as I have not set up the ‘menuconfig’ properly (not sure how to do that in PlatformIO).

The error that I get in my real code is the one for lines 78, 79 and 80: (It is surprisingly hard to cut/paste the error message - perhaps there is something I’m not doing correctly - sorry if this is a mess.)

Processing ttgo-t1 (platform: espressif32; board: ttgo-t1; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/ttgo-t1.html
PLATFORM: Espressif 32 (2.0.0) > TTGO T1
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.40100.200827 (4.1.0) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - tool-mkspiffs 2.230.0 (2.30) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.191205 (2.28.51) 
 - toolchain-xtensa32 2.80200.200827 (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/ttgo-t1/esp-idf/src/main.c.o


src/main.c: In function 'event_handler':
src/main.c:29:36: error: 'CONFIG_ESP_MAXIMUM_RETRY' undeclared (first use in this function); did you mean 'EXAMPLE_ESP_M
AXIMUM_RETRY'?
 #define EXAMPLE_ESP_MAXIMUM_RETRY  CONFIG_ESP_MAXIMUM_RETRY
                                    ^~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:50:27: note: in expansion of macro 'EXAMPLE_ESP_MAXIMUM_RETRY'
         if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
                           ^~~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:29:36: note: each undeclared identifier is reported only once for each function it appears in
 #define EXAMPLE_ESP_MAXIMUM_RETRY  CONFIG_ESP_MAXIMUM_RETRY
                                    ^~~~~~~~~~~~~~~~~~~~~~~~

src/main.c:50:27: note: in expansion of macro 'EXAMPLE_ESP_MAXIMUM_RETRY'
         if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
                           ^~~~~~~~~~~~~~~~~~~~~~~~~
src/main.c: In function 'wifi_init_sta':
src/main.c:78:5: error: unknown type name 'esp_event_handler_instance_t'; did you mean 'esp_event_handler_t'?
     esp_event_handler_instance_t instance_any_id;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
     esp_event_handler_t
src/main.c:79:5: error: unknown type name 'esp_event_handler_instance_t'; did you mean 'esp_event_handler_t'?
     esp_event_handler_instance_t instance_got_ip;
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
     esp_event_handler_t
In file included from /Users/Susan/.platformio/packages/framework-espidf/components/esp_common/include/esp_timer.h:44,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/portmacro.
h:84,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/portable.h
:96,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/FreeRTOS.h
:107,
                 from src/main.c:10:
src/main.c:80:21: error: implicit declaration of function 'esp_event_handler_instance_register'; did you mean 'esp_event_handler_unregister'? [-Werror=implicit-function-declaration]
     ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Susan/.platformio/packages/framework-espidf/components/esp_common/include/esp_err.h:118:31: note: in definition o
f macro 'ESP_ERROR_CHECK'
         esp_err_t __err_rc = (x);                                       \
                               ^
src/main.c:27:36: error: 'CONFIG_ESP_WIFI_SSID' undeclared (first use in this function); did you mean 'EXAMPLE_ESP_WIFI_
SSID'?
 #define EXAMPLE_ESP_WIFI_SSID      CONFIG_ESP_WIFI_SSID
                                    ^~~~~~~~~~~~~~~~~~~~
src/main.c:93:21: note: in expansion of macro 'EXAMPLE_ESP_WIFI_SSID'

             .ssid = EXAMPLE_ESP_WIFI_SSID,
                     ^~~~~~~~~~~~~~~~~~~~~
src/main.c:28:36: error: 'CONFIG_ESP_WIFI_PASSWORD' undeclared (first use in this function); did you mean 'ESP_ERR_WIFI_
PASSWORD'?
 #define EXAMPLE_ESP_WIFI_PASS      CONFIG_ESP_WIFI_PASSWORD
                                    ^~~~~~~~~~~~~~~~~~~~~~~~
src/main.c:94:25: note: in expansion of macro 'EXAMPLE_ESP_WIFI_PASS'
             .password = EXAMPLE_ESP_WIFI_PASS,
                         ^~~~~~~~~~~~~~~~~~~~~
In file included from /Users/Susan/.platformio/packages/framework-espidf/components/esp_common/include/esp_timer.h:44,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/portmacro.
h:84,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/portable.h
:96,
                 from /Users/Susan/.platformio/packages/framework-espidf/components/freertos/include/freertos/FreeRTOS.h
:107,
                 from src/main.c:10:
src/main.c:133:21: error: implicit declaration of function 'esp_event_handler_instance_unregister'; did you mean 'esp_ev
ent_handler_unregister'? [-Werror=implicit-function-declaration]
     ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip));
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Susan/.platformio/packages/framework-espidf/components/esp_common/include/esp_err.h:118:31: note: in definition o
f macro 'ESP_ERROR_CHECK'
         esp_err_t __err_rc = (x);                                       \
                               ^
cc1: some warnings being treated as errors
*** [.pio/build/ttgo-t1/esp-idf/src/main.c.o] Error 1
========================= [FAILED] Took 13.85 seconds =========================

Thanks for the assistance

Susan

The last change in that commit was Jun 03 2020, while when you switch to the v4.1 release branch version (https://github.com/espressif/esp-idf/blob/release/v4.1/examples/wifi/getting_started/station/main/station_example_main.c) it is from Jun 05 2020, so, more recent. So that branch is actually ahead of master, or has specific changes for that v4.1.

See docs https://docs.platformio.org/en/latest/frameworks/espidf.html#configuration-for-4-0, then you can configure the SSID and WiFi. If you’re in VSCode, start a PIO terminal (project tasks) and execute that command and configure it.

Does it work when you use the code specific for the v4.1 branch and after configuring the WiFi via menuconfig?

Thank you for the help - I’m now up and going again.
The thing that was confusing me is that the Espressif web site seems to naturally take you to the ‘latest’ release, and I was following the links from there to the examples. While V4.1 is the latest they have announced, it seems (as you say) that the ‘latest’ release is after V4.1. (I assume it must relate to a beta or something.)
Anyway - thanks again for your kind help.
Susan

In those repos (or pretty much anywhere) care needs to be taken to really get the correct example code version for an release, which is handled in branches. So clicking on the commit / branches / tags button should always be the first thing to do when looking at example code

image

Great that it’s working now :slight_smile: