Cant build esp-idf espnow example

I tried to build the official espnow example project from esp-idf/examples/wifi/espnow at master · espressif/esp-idf · GitHub but it fails with

unknown type name ‘esp_now_send_info_t’

The above is defined in esp-idf/components/esp_wifi/include/esp_now.h at 5b11d5b26a8bf151fc6bac400158859eedd413bc · espressif/esp-idf · GitHub but this doesnt seem to get included into my copy of the project.

My CMakeLists.txt contains

idf_component_register(SRCS “espnow_example_main.c”
PRIV_REQUIRES nvs_flash esp_event esp_netif esp_wifi
INCLUDE_DIRS “.”)

It’s an official example yes, but that is literally the bleeding edge master you’re referencing.

Depending on which PlatformIO espressif32 platform you’re using, you must use an older version.

When you hit “Build”, what are the list of PACKAGES: that are printed?

Thanks for the prompt reply @maxgerhardt

The pio run output is below:

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin32_lite.html
PLATFORM: Espressif 32 (6.5.0) > WEMOS LOLIN32 Lite
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, 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.50102.0 (5.1.2)
 - tool-cmake @ 3.16.4
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - tool-idf @ 1.0.1
 - tool-mconf @ 1.4060000.20190628 (406.0.0)
 - tool-ninja @ 1.9.0
 - tool-riscv32-esp-elf-gdb @ 11.2.0+20220823
 - tool-xtensa-esp-elf-gdb @ 11.2.0+20230208
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0)
 - toolchain-xtensa-esp32 @ 12.2.0+20230208
Reading CMake configuration...
Warning! Flash memory size mismatch detected. Expected 4MB, found 2MB!
Please select a proper value in your `sdkconfig.defaults` or via the `menuconfig` target!
LDF: Library Dependency Finder -> https://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\lolin32_lite\src\espnow_example_main.o
Compiling .pio\build\lolin32_lite\console\argtable3\arg_lit.o
Compiling .pio\build\lolin32_lite\console\argtable3\arg_rem.o
Compiling .pio\build\lolin32_lite\console\argtable3\arg_rex.o
Compiling .pio\build\lolin32_lite\console\argtable3\arg_str.o
Compiling .pio\build\lolin32_lite\console\argtable3\arg_utils.o
Compiling .pio\build\lolin32_lite\console\argtable3\argtable3.o
Compiling .pio\build\lolin32_lite\cxx\cxx_exception_stubs.o
Compiling .pio\build\lolin32_lite\cxx\cxx_guards.o
src/espnow_example_main.c:70:42: error: unknown type name 'esp_now_send_info_t'
   70 | static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)

So this is the crux.

  1. Espressif32 platform 6.5.0 is old. 6.11.0 is the latest official one. It would use ESP-IDF v5.4.1.
  2. With your currently used 6.5.0 platform, it uses ESP-IDF 5.1.2. Which means you should use an example from the same tag or branch. https://github.com/espressif/esp-idf/tree/v5.2.1/examples/wifi/espnow.

Long story short: Consider updating your espressif32 platform (e.g. setting platform = espressif32@6.11.0 in the platformio.ini) and version-match the ESP-IDF version that your platform uses to the example code you copy and paste from the ESP-IDF repo.

1 Like

Thanks very much for your prompt and very useful advice @maxgerhardt