ESPNOW Compile Error: 'esp_now_send_status_t' has not been declared

I am having a strange Problem.

As soon as I move my OnDataRecv Function to any tab other than first tab, even if it is on top of second tab (before setup and loop , which are on third or fourth tab)

The Error

'esp_now_send_status_t' has not been declared

appears while compilation/verification; this error appears in OnDataSent Function.

If I move OnDataRecv back to end of first tab, verification is done , code works perfectly

I am using base code from, with slight modifications as per my project requirement

Even if I split the code from above site at OnDataSent ... into two tabs ... , no change in sequence of commands this error occurs

We can't see your requirements or your code.

  Rui Santos
  Complete project details at
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

#include <esp_now.h>
#include <WiFi.h>

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

Adafruit_BME280 bme;

// REPLACE WITH THE MAC Address of your receiver 
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

// Define variables to store BME280 readings to be sent
float temperature;
float humidity;
float pressure;

// Define variables to store incoming readings
float incomingTemp;
float incomingHum;
float incomingPres;

// Variable to store if sending data was successful
String success;

//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
    float temp;
    float hum;
    float pres;
} struct_message;

// Create a struct_message called BME280Readings to hold sensor readings
struct_message BME280Readings;

// Create a struct_message to hold incoming sensor readings
struct_message incomingReadings;

// Callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("\r\nLast Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
  if (status ==0){
    success = "Delivery Success :)";
    success = "Delivery Fail :(";

// Callback when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  Serial.print("Bytes received: ");
  incomingTemp = incomingReadings.temp;
  incomingHum = incomingReadings.hum;
  incomingPres = incomingReadings.pres;
void setup() {
  // Init Serial Monitor

  // Init BME280 sensor
  bool status = bme.begin(0x76);  
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);

  // Init OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
  // Set device as a Wi-Fi Station

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  // Register peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6); = 0;  
  peerInfo.encrypt = false;
  // Add peer        
  if (esp_now_add_peer(&peerInfo) != ESP_OK){
    Serial.println("Failed to add peer");
  // Register for a callback function that will be called when data is received
void loop() {
  // Set values to send
  BME280Readings.temp = temperature;
  BME280Readings.hum = humidity;
  BME280Readings.pres = pressure;

  // Send message via ESP-NOW
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &BME280Readings, sizeof(BME280Readings));
  if (result == ESP_OK) {
    Serial.println("Sent with success");
  else {
    Serial.println("Error sending the data");
void getReadings(){
  temperature = bme.readTemperature();
  humidity = bme.readHumidity();
  pressure = (bme.readPressure() / 100.0F);

void updateDisplay(){
  // Display Readings on OLED Display
  display.setCursor(0, 0);
  display.println("INCOMING READINGS");
  display.setCursor(0, 15);
  display.print("Temperature: ");
  display.setCursor(0, 25);
  display.print("Humidity: ");
  display.setCursor(0, 35);
  display.print("Pressure: ");
  display.setCursor(0, 56);
  // Display Readings in Serial Monitor
  Serial.println("INCOMING READINGS");
  Serial.print("Temperature: ");
  Serial.println(" ºC");
  Serial.print("Humidity: ");
  Serial.println(" %");
  Serial.print("Pressure: ");
  Serial.println(" hPa");

Split it at Line 60 , and move line 60 onwards to another tab , while verification the Error will Occur

I am using WEMOS D1 Mini ESP32 , but this happens on ESP32 Dev Module too

This is code is from

No Error if verified on single Arduino IDE tab using Arduino 1.8.13

I’ve just found a solution to the problem, what i understood is that function prototype of this callback is missplaced at some point and defaults is type to int instead of esp_now_send_status_t, so you only need to put the function prototype of your callback at the first ino file, the one named same as your project folder and the code now compiles without problem, i´ll leave this explanation in spanish because i can explain more clearly.

Acabo de encontrar una solución para el problema, al parecer todo tiene que ver con que el prototipo de la función de callback se pierde en algún punto antes de incluir los archivos de la librería esp_now y por eso no encuentra la definición de esp_now_send_status_t y lo define por defecto como int, entonces lo único que hay que hacer es declarar el prototipo de la función callback en el archivo ino principal, el que tiene el mismo nombre que la carpeta y todo compila bien. Espero te ayude.



#include <esp_now.h>
#include <sys/time.h>
#include <WiFi.h>

void EnEnvioDatos(const uint8_t *DireccionMAC, esp_now_send_status_t Estado);


void EnEnvioDatos(const uint8_t *DireccionMAC, esp_now_send_status_t Estado) {
  char MAC[18];

Worked like a Charm:

void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);

1 Like

@athersaleem, your topic was moved to a more suitable location on the forum.

Thanks for marking as solved (solution).

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