ESPNOW compiles for ESP8266 but not ESP32

Hi All:

Frustrating issue, have been using espressif espnow successfully with Generic ESP8266 dev boards. When trying to verify/compile for a ESP32 (Pico-D4 board) the compiler flags espnow.h as a file not found, tried other ESP32 boards - same issue.

Switching back to the ESP8266 board and all is good. I've closed and re-started the IDE, reinstalled the library, reinstalled the boards, etc. I even pulled out an old Win10 laptop - loaded the latest Arduino IDE, espnow library and boards - same compiling issue with the ESP32. Pretty stumped here!

Details:

  • Arduino IDE 2.3.2 2/20/24 update
  • Boards Mgr
    • Esp8266 by ESP8266 ver 3.1.2 installed
    • Esp32 by Espressif ver 2.0.14 installed (tried using older versions, no luck)
  • Boards selected:
    • Generic ESP8266 Module
    • ESP32 Pico-D4

ESP32 compiling error: compilation terminated. exit status 1
Compilation error: espnow.h: No such file or directory

Test code below...

// ESP32 TEST TO GET ESPNOW.H TO BE RECONGIZED BY THE ARDUINO IDE COMPILER


#include <espnow.h>

uint8_t senderMac[] = { };               //NOT NEEDED

void setup() {
  Serial.begin(9600);

  esp_now_init();
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(onDataReceived);
}

void onDataReceived(uint8_t *senderMac, uint8_t *data, uint8_t len) 
{
  Serial.print("DATA RECEIVED: ");
  
}

Welcome to the forum

For the ESP32 the name of the library is esp_now.h rather than espnow.h

Another welcome also from me!

Bob got there first, but my digging around also suggests the same. Try using the alternate header name or perhaps use an #if defined() statement to determine which one to load for the given platform:

  #if defined(ESP32)
    #include <esp_now.h>
  #elif defined(ESP8266)
    #include <espnow.h>
  #endif
1 Like

Thx so much for the code snippet, makes sense now! There are various web comments about esp_now changing over to espnow without clarifying about being dev board specific....

BTW - in the downloaded library, the only src folder file is espnow.h

I assume that there is a reason for the library names being different but can't imagine what the reason would be

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.