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 esp-idf/station_example_main.c at c77c4ccf6c43ab09fd89e7c907bf5cf2a3499e3b · espressif/esp-idf · GitHub
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 (esp-idf/examples/wifi/getting_started/station/main/station_example_main.c at release/v4.1 · espressif/esp-idf · GitHub) 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 Espressif IoT Development Framework — PlatformIO latest documentation, 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

Great that it’s working now :slight_smile:

I believe I have an issue resembling this. With the “PIO Home>Platforms” I upgraded the Espressif 32 to release 2.0.0 (which I understand is esp-idf version 4.1?)
What was the solution in this tread, was the Espressif 32 upgrade roll-back to the previous release?

If you have code that is targeted at ESP-IDF v4.0, then write

platform = espressif32@1.12.4

in the platformio.ini to rollback to a platform version which still uses this version. Also see release page.

No the problem here was that code that was not targeted at ESP-IDF v4.1 was compiled with the ESP-IDF v4.1 framework. Solution is to use the example code that is targeted at the correct (aka currently used by PIO) version of ESP-IDF, not rollback to an older platform version…

Thanks for the prompt answer!
Ahh, neat trick - so you can “link” a project to a specific release of the esp-idf. :clap:

Okay I get it, the exampled code compiled was for release 4.2, I should be able to find example code for release 4.1 on the Git?

I hope that isn’t seen as a only-known-to-some trick since it’s documented in PIO’s Espressif32 page :smiley:.

If the example code comes from Espressif’s ESP-IDF repo, you can select the branch as shown above and try it. For more advanced errors when switching to ESP-IDF v4.1, please open a new topic. Or if rewrite is not feasible at this moment, pinning platform to the older version is okay I guess…

You are right, it is only me that are not up to date with PIO documentation (you just exposed me, now every one knows I am a new comer :slightly_smiling_face:). But I will give you a thumbs-up for the information, thanks. :+1:

One last question, in the framework-espidf folder there is a ‘version.txt’ file. Am I right in assuming that the version number stated in that file has nothing to do with the esp-idf release?

Thanks for you help! :mage:

For me that file reads

3.40100.200827

which is the PIO-internal version number, and it has meaning. As described in Find the mbed version which was used before a backup? - #4 by maxgerhardt this would decode as “Major (PIO) package revision 3, internal version 4.1.0, datecode 2020 August 27th.”.

Got it, that cleared it up.

Thanks again!