ESP NOW delay on transmitting data

Hi everyone, as the title says I am getting a delay of about 10 sec which is not great for my application. I am using two Xiao ESP32C3 Modules (both battery powered). One module reads the sensor values and passes it to another using ESP NOW protocol (one way communication). Both modules have an antenna attached to them and are relatively closed to one another (10 meters).
I cannot understand what am I doing wrong. Any help is appreciated. The code for both modules is down below.

Sender:

// Include Libraries
#include <esp_now.h>
#include <WiFi.h>

// Set sensorPins
const int sensorPin = A0;

// Variables for test data
int int_value;
float float_value;

// MAC Address of responder - edit as required
uint8_t broadcastAddress[] = {0x34, 0x85, 0x18, 0x03, 0x45, 0xC8};

// Define a data structure
typedef struct struct_message {
  int a;
  float b;
} struct_message;

// Create a structured object
struct_message myData;

// Peer info
esp_now_peer_info_t peerInfo;

// Callback function called 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");
}

void setup() {
  // Set Pin and resolution xiao has 12bit resolution
  pinMode(sensorPin, INPUT);
  analogReadResolution(12);

  // Set up Serial Monitor
  Serial.begin(115200);
 
  // Set ESP32 as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

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

  // Register the send callback
  esp_now_register_send_cb(OnDataSent);
  
  // Register peer
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
  
  // Add peer        
  if (esp_now_add_peer(&peerInfo) != ESP_OK){
    Serial.println("Failed to add peer");
    return;
  }
}

void loop() {

  // Create test data
  int sensorVal = analogRead(sensorPin);
  float percentage = (sensorVal/4096.0) * 100.0;

  
  // Format structured data
  myData.a = sensorVal;
  myData.b = percentage;
  
  // Send message via ESP-NOW
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
   
  if (result == ESP_OK) {
    Serial.println("Sending confirmed");
  }
  else {
    Serial.println("Sending error");
  }
  delay(125);
}

Receiver:

// Include Libraries
#include <esp_now.h>
#include <WiFi.h>

#define leftLED 10
#define rightLED 9

const int threshold = 2900;                     // Light intensity threshold
const unsigned long leftLEDinterval = 125;      // LED blink variables declaration with millis to avoid delays
//const unsigned long rightLEDinterval = 125;   // Uncomment for different blink patterns
unsigned long currentTime = 0;
unsigned long previousTimeLeftLED = 0;
//unsigned long previousTimeRightLED = 0;

int leftLEDstate = LOW;
int rightLEDstate = LOW;

// Define a data structure
typedef struct struct_message {
  int a;
  float b;
} struct_message;

// Create a structured object
struct_message myData;


// Callback function executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.print("Data received: ");
  Serial.println(len);
  Serial.print("Raw Sensor Value: ");
  Serial.println(myData.a);
  Serial.print("Percentage: ");
  Serial.println(myData.b);
  Serial.println();
}

void setup() {
  
  pinMode(leftLED, OUTPUT);
  pinMode(rightLED, OUTPUT);

  // Set up Serial Monitor
  Serial.begin(115200);
  
  // Set ESP32 as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // Initilize ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Register callback function
  esp_now_register_recv_cb(OnDataRecv);
}
 
void loop() {

  // Blink on receiver site
  unsigned long currentTime = millis();
  if (myData.a > threshold)
  {
    // LED blink logic: LED1 ON && LED2 OFF same rhythm.
    if (currentTime - previousTimeLeftLED > leftLEDinterval)
    {
      previousTimeLeftLED = currentTime;
      if (leftLEDstate == LOW)
      {
        leftLEDstate = HIGH;
        rightLEDstate = LOW;
      }
      else
      {
        leftLEDstate = LOW;
        rightLEDstate = HIGH;
      }
        digitalWrite(leftLED, leftLEDstate);
        digitalWrite(rightLED, rightLEDstate);
    }    
  }
  else
  {
    leftLEDstate = LOW;
    rightLEDstate = LOW;
    
    digitalWrite(leftLED, leftLEDstate);  
    digitalWrite(rightLED, rightLEDstate);  
  }
}

Here is a demo-code that does a lot of serial printing for narrowing down if something is wrong.

The only thing you have to modify is using the MAC-adresses of your boards
The code does send and receive on both ways

// keep this variable on top to have an easy to remember place to look up
// which board shall have this code-version /a short name is easier to remember as
// a MAC-Adress
char BoardName[] = "Bonny"; 

unsigned long SendDataInterval;
int Summand;

// at the end of this file there is an explanation that uses an analogy with 
// sending / receiving postal letters to explain the several parts of ESP-NOW
// so if you would like to have an easy to understand overview read this
// explanation first.

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

// For sending / receiving ESP-NOW-data on both sides sender and receiver;
// a structured variable has to be defined with the EXACT SAME structure

// the information that shall be sended/received is transmitted bytewise
// the ESP-NOW-functions know nothing about what the bytes mean
// it just transfers a specified number of bytes
// If the structures do not match 100% the data gets MIS-interpreted on the receiver-side
// in this demo-code a structure with an Array Of Char and an integer is used
// it is defined as follows

// ESP-NOW data-structure-definition
typedef struct MyESP_NOW_Data_type {
  char MyESP_NOW_MsgStr[128];
  int  MyESP_NOW_Int;
} MyESP_NOW_Data_type;

// After defining the structure two variables 
// one for receiving one for sending data
// this demo wants to demonstrate send AND receive in both directions
MyESP_NOW_Data_type my_received_ESP_NOW_Data;      
MyESP_NOW_Data_type my_READYtoSEND_ESP_NOW_Data;   


//#############################################################################################
// list of MAC-Adresses of all receivers:

// important note: ESP-NOW sending is based on the RECEIVERS Mac-adress.
// this means for every ESP-modul that shall receive an ESP-NOW-Messages
// you have to execute register a peer in the Setup-function

// Mac-Adress must be stored in an array of uint8_t
//uint8_t ESP_NOW_MAC_adrOfRecv[] = {0x78, 0xE3, 0x6D, 0x17, 0x3A, 0x20 };
uint8_t ESP_NOW_MAC_adrOfRecv[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };


char MAC_adrOfRecv_as_AoC[18];
char Own_MacAdr_AoC[18];  //suffix _AoC for easier remembering variable-type is ArrayOfChar

char MySelfHeader[]   = "Myself: ";
char ReceivedHeader[] = "-------------->"; 
//##############################################################################################

//ESP_NOW_functions

// callback function that will be executed when data is received
// Parameters:
// mac:          mac-adress of sender
// incomingData: the bytes that are received
// NoOfBytesRcv: number of bytes received

//void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t NoOfBytesRcv) { 
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int NoOfBytesRcv) {
  //char MacAdr[18];
  Serial.print(ReceivedHeader);
  Serial.print("ESP-NOW-Data received from Board with MAC-Adress#");
  Serial.print( strupr(hex02str(mac[0])));
  Serial.print(":");
  Serial.print( strupr(hex02str(mac[1])));
  Serial.print(":");
  Serial.print( strupr(hex02str(mac[2])));
  Serial.print(":");
  Serial.print( strupr(hex02str(mac[3])));
  Serial.print(":");
  Serial.print( strupr(hex02str(mac[4])));
  Serial.print(":");
  Serial.print( strupr(hex02str(mac[5])));
  Serial.print(":");
  Serial.println("#");
  
  // copy data bytewise from variable incomingData to variable my_received_ESP_NOW_Data
  memcpy(&my_received_ESP_NOW_Data, incomingData, sizeof(my_received_ESP_NOW_Data));

  Serial.print(ReceivedHeader);
  Serial.print("No of Bytes received: ");
  Serial.println(NoOfBytesRcv);

  //these lines must match the variables inside the ESP_NOW-data-structure
  Serial.print(ReceivedHeader);
  Serial.print("Received Msg: #"); // leading "#"
  Serial.print(my_received_ESP_NOW_Data.MyESP_NOW_MsgStr);
  Serial.println("#"); // trailing "#" makes it easy to see which bytes where received
  
  Serial.print(ReceivedHeader);
  Serial.print("Int: ");
  Serial.println(my_received_ESP_NOW_Data.MyESP_NOW_Int);

  Serial.println();
}


// callback when data is sent. Gets executed when sending data has finished
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.println();
  Serial.println();
  Serial.print(MySelfHeader);
  Serial.print(" OnDataSent Send Status: ");
  if (status == ESP_NOW_SEND_SUCCESS) {    
    Serial.println("Success'");
    Serial.println();
  }
  else {
    Serial.println("Failed'");
    Serial.println();
  }  
}

// attention! for some unknown strange reasons the variable 
// for the peer-info has to be global otherwise you will 
// get the error "ESPNOW: Peer Interface is invalid"
esp_now_peer_info_t MyPeerInfo; 

void ESP_Now_setup() {
  WiFi.mode(WIFI_STA);
  Serial.println("WiFi.mode(WIFI_STA); done");
  WiFi.disconnect(); // for strange reasons WiFi.disconnect() makes ESP-NOW work
  Serial.println("WiFi.disconnect(); done");
  
  // Init ESP-NOW  
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }  
  Serial.println("esp_now_init() was successful");
    
  // register callback-function that will be executed each time 
  // function esp_now_send() has finished
  esp_now_register_send_cb(OnDataSent);
  Serial.println("esp_now_register_send_cb(OnDataSent); done");
  
  // register callback-function that will be executed each time
  // ESP-NOW-Data is received
  esp_now_register_recv_cb(OnDataRecv);  
  Serial.println("esp_now_register_recv_cb(OnDataRecv); done");

  // the ESP-NOW-Sender needs to "fill out" a list with informations about each receiver
  // this is called peer. Therefore you have to create a variable of type esp_now_peer_info_t
  //esp_now_peer_info_t MyPeerInfo;
  // then "fill out" peer-data-form
  memcpy(MyPeerInfo.peer_addr, ESP_NOW_MAC_adrOfRecv, 6);
  MyPeerInfo.channel = 0;  
  MyPeerInfo.encrypt = false;
  
  // after setting up peer-info, add peer        
  if (esp_now_add_peer(&MyPeerInfo) != ESP_OK){
    Serial.println("Failed to add peer");
    return;
  }
  Serial.println("esp_now_add_peer(&peerInfo) was successful");
  // this setup peer-info and add peer has to be repeated for each receiver 
  // that shall receive from this sender

  for (int i = 0;   i < 6;  i++) {
    strcat (MAC_adrOfRecv_as_AoC, hex02str(ESP_NOW_MAC_adrOfRecv[i])   );
    if (i < 6) {
      strcat (MAC_adrOfRecv_as_AoC, ":" );    
    }  
  }  
  MAC_adrOfRecv_as_AoC[17] = 0;
  strupr(MAC_adrOfRecv_as_AoC); // make letters UPPERCASE
  Serial.print("MAC-Adress of Receiver is ");
  Serial.println(MAC_adrOfRecv_as_AoC);
}


void ESP_NOW_SendData()
{
  char AoC[10];
  // Set values to send
  strcpy(my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_MsgStr, "HI I'M SENDING EVERY ");
  itoa(SendDataInterval,AoC,10);
  strcat (my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_MsgStr,AoC );
  strcat (my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_MsgStr, " Milli-SECONDS COUNTiNG UP ");
  itoa(Summand,AoC,10);
  strcat (my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_MsgStr,AoC );
  my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_Int = my_READYtoSEND_ESP_NOW_Data.MyESP_NOW_Int + Summand; 

  // Send message via ESP-NOW  
  esp_now_send(ESP_NOW_MAC_adrOfRecv, (uint8_t *) &my_READYtoSEND_ESP_NOW_Data, sizeof(my_READYtoSEND_ESP_NOW_Data));
  Serial.print(MySelfHeader);
  Serial.println("esp_now_send(ESP_NOW_MAC_adrOfRecv, (uint8_t *) &my_READYtoSEND_ESP_NOW_Data, sizeof(my_READYtoSEND_ESP_NOW_Data)); done");
  Serial.print(MySelfHeader);
  Serial.print("I am the board named '");
  Serial.print(BoardName);
  Serial.print("' with the MAC-Adress ");
  Serial.println(Own_MacAdr_AoC); 
  Serial.print(MySelfHeader);
  Serial.print("and I try to send my ESP-NOW-Data to the board with MAC-Adress #");
  Serial.print(MAC_adrOfRecv_as_AoC); 
  Serial.println("#"); 
  
  // if sending has finished function OnDataSent is called
}


/* nonblocking timing based on millis()
this function returns true each time the TimePeriod has expired and immediately 
starts a new TimePeriod. So this function
example-use:
unsigned long myTimer;

  if (TimePeriodIsOver( myTimer,2000) ) {
    //the code here gets executed only every 2000 Milliseconds
  }  
*/  
boolean TimePeriodIsOver (unsigned long &expireTime, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - expireTime >= TimePeriod )
  {
    expireTime = currentMillis; // set new expireTime
    return true;                // more time than TimePeriod) has elapsed since last time if-condition was true
  } 
  else return false;            // not expired
}

unsigned long SendDataTimer;


/*
everytime the compiler compiles the file new 
the macros named "__FILE__",  "__DATE__", "__TIME__"  
where replaced with what their names say  Filename with path
Date and time of the Computer the IDE is running on 
// so by simply starting the device the uploaded code yells filename date and time at the serial interface
*/
void PrintWiFiMacAdress()
{
  char HexByteDigits[3];
  
  for (uint8_t i = 0; i < 18; i = i + 1)
  { 
    Own_MacAdr_AoC[i] = WiFi.macAddress()[i];
  } 
  Own_MacAdr_AoC[17] = 0; // zero to terminate the string
  Serial.print("ESP32-Board's OWN MAC-Address is:  ");
  Serial.println(Own_MacAdr_AoC);
  
  Serial.println();
  Serial.println("copy the line below and replace the codeline");
  Serial.println("uint8_t ESP_NOW_MAC_adrOfRecv[] = { .... };");
  Serial.println("inside the code with the copied line from the serial monitor");
   
  Serial.println();
  Serial.print("uint8_t ESP_NOW_MAC_adrOfRecv[] = {");
  for (uint8_t i = 0; i < 16; i = i + 3)
  { 
    HexByteDigits[0] = Own_MacAdr_AoC[i];
    HexByteDigits[1] = Own_MacAdr_AoC[i+1];
    HexByteDigits[2] = 0; // zero for terminating the string
    Serial.print("0x");
    Serial.print(HexByteDigits);
    if (i < 14) Serial.print(", ");
  }  
  Serial.println(" };");
  Serial.println();      
}

char* hex02str(uint8_t b)  {
 static char str[]="FF"; // RAM für einen 2-Zeichen string reservieren.
  snprintf(str,sizeof(str),"%02x",b);
  return str;
}


void PrintFileNameDateTime()
{
  Serial.print("Code running comes from file ");
  Serial.println(__FILE__);
  Serial.print(" compiled ");
  Serial.print(__DATE__);
  Serial.print("  ");
  Serial.println(__TIME__);  
}

  
void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  Serial.println();  // a carriage return to make sure serial-output begins in colum 1 of a new line
  PrintFileNameDateTime();
  PrintWiFiMacAdress();  

  ESP_Now_setup();

}

void loop() {
  SendDataInterval = 5000;
  Summand = 6;
  // check if timer-intervall is over
  if (TimePeriodIsOver(SendDataTimer,SendDataInterval) )  
    {
     Serial.print(MySelfHeader); 
     Serial.println("SendData");
     ESP_NOW_SendData();
     Serial.print(MySelfHeader);
     Serial.println("SendData done");
    }
}

// explanation how ESP-NOW works:
// sending serial data is as easy as

// Serial.begin(baudrate);
// Serial.print("Hello World");

// This can be coded so easy because a lot of things are fixed
// IO-Pins used by Serial fixed
// Connection to other device: made of wire must not be programmed
// standard serial-connection does not care if receiver is connected
// send data and that's all

// with ESP-NOW more things are NOT fixed = are adjustable and MUST be adjusted
// the receiver is NOT defined by wire but through his MAC-Adress

// Data-transport can do only transporting one or multiple bytes
// That's not a real problem the user can define his own data-pattern (data-structure)

// ESP-NOW offers feedback if a datatransmission was successful or failed

// each ESP-modul can receive data from different senders 
// so an information from WHICH sender the data was sended is useful
// this is identified by the senders MAC-Adress

// Analogy sending / receiving postal letters:

// if you want to SEND out a letter to somebody you have to write 
// the receivers adress on the envelope. 
// similar thing with ESP-NOW: the data is NOT guided by a wire its sended "Up in the air" 
// with ESP-NOW this receiver-adress is the MAC-Adress of the receiver

// if the postman brings you a letter you don't have to be at home. He will put the letter
// into your letter-box and you can pick it out later.

// similar thing with ESP-NOW: there is some kind of "letter-box" the received data will be stored into
// the data-receiving into the "letter-box" runs in the backround similar to an interrupt
// The received data will be catched up and must be copied into some kind of "letterbox"

// any transporting service has some kind of procedure if you want to send a package or a letter
// fill out some kind of form (on paper or onnline) print out and glue a sticker 
// with the transporting informations on the package/envelope put the package / envelope into the
// "send out" box or bring it to a pickup store

// so there are some things to do:

// - build a special designed "package" with multiple special designed compartments
//   where all parts of the data has its own compartment 
//   defining a new variable type "structure"

// - build a "letter-box" designed expecially for the user-defined package 
//   and "mount it in front of your house" so it can be easily found by the postman

// - write a list with receiver-adresses and handover this list to ESP-NOW (the "letter-department" of your "company"

// - setup if data shall be encrypted or not

// - setup transmission channel that shall be used for sending the data wireless

// - design your "sending-form"

// these are the reasons why ESP-NOW needs a bit more than just
// Serial.begin(baudrate);
// Serial.print("My Data");

// Your mobile phone has a lot of functions. It took you some time to learn them all
// Same thing with ESP-NOW it will take some time to learn it

// if you want it fully automated without learning anything 
// use Alexa, Siri or google assistant instead

best regards Stefan

10 metres can be a problem - are there any walls etc between the transmitter and receiver and/or other WiFi devices or equipment which could be interfearing with the signals
I have used code from esp-now-esp32-arduino-ide without problems

Do you see multiple delivery failure messages before a successful transmission of the data ?

Yes there is one wall in between!

No, Serial.print shows no failures whatsoever.

what may be happening is the wall is attenuating the WiFi signal and ESP-NOW is taking some time for a reliable transmiision to get thru
have a look at esp_now documentation
upload printouts of transmitter and receiver (as text) with time displayed

1 Like

Rememeber 'walls' vary considerbly in construction.

From a couple of feet of granite to simple foil backed pasterboard, both of which can be very effective RF shields.

And there are lots of variations in between.

1 Like

Thanks for all the replies, I will have a look at documentation after work and post my status once I solve the issue!

using a pair of ESP32 Dev kits experimenting with following code
transmitter

// ESP-NOW transmit a structure

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
  
  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>

// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {0x24,0x62,0xAB,0xE0,0x64,0x54}; //{ 0x84, 0xCC, 0xA8, 0x7A, 0x56, 0x6C };  //{0x24,0x62,0xAB,0xE0,0x64,0x54};

esp_now_peer_info_t peerInfo;

// test structure
struct __attribute__((packed)) Data {
  int16_t seq;  // sequence number
  int32_t distance;
  float voltage;
  char text[50];
} data = { 0, 56, 3.14159, "hello test" };  // sample data

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("Last Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  Serial.println("ESP-NOW transmitting a structure");
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  Serial.print("ESP32 Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }
}

void loop() {
  // Send data structure via ESP-NOW
  Serial.printf("seq %d distaance %ld voltage %f text '%s'\n",
                (int)data.seq, (long)data.distance, data.voltage, data.text);
  esp_now_send(broadcastAddress, (uint8_t *)&data, sizeof(data));
  delay(1000);
  data.seq++;  // update data ready for next transmission
  data.distance += 10;
  data.voltage += 2.5;
  data.text[9]++;
}

receiver

// ESP-NOW receive a structure

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
  
  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>

// test structure
struct __attribute__((packed)) Data {
  int16_t seq;  // sequence number
  int32_t distance;
  float voltage;
  char text[50];
} data;

// callback function that will be executed when data is received
void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
  static int16_t seqExpected = 0, errors=0;
  Serial.printf("Bytes received: %d ", len);
  if (len == sizeof(data)) {
    memcpy((void *)&data, (void *)incomingData, len);
    Serial.printf("seq %d distaance %ld voltage %f text '%s' errors %d\n",
                  (int)data.seq, (long)data.distance, data.voltage, data.text, errors);
    if (data.seq != seqExpected)  // check sequence number received
      Serial.printf("Error! seq expected %d received %d errors %d\n", seqExpected, data.seq, ++errors);
    seqExpected = data.seq;  // set sequence number ready for next data
    seqExpected++;
  } else
    Serial.printf("ERROR! packek size expected %d receive %d errors %d\n", sizeof(data), len, ++errors);
}


void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  Serial.println("ESP-NOW receive a structure");
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  Serial.print("ESP32 Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

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

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
}

worked OK at 5 to 6 metres thru a foil backed plasterboard wall
failed at 6/7 metres thru two foil backed pasterbaord walls
e.g. receiver serial monitor output

Bytes received: 60 seq 8 distaance 136 voltage 23.141590 text 'hello tes|' errors 3
Bytes received: 60 seq 9 distaance 146 voltage 25.641590 text 'hello tes}' errors 3
Bytes received: 60 seq 10 distaance 156 voltage 28.141590 text 'hello tes~' errors 3
Bytes received: 60 seq 12 distaance 176 voltage 33.141590 text 'hello tes�' errors 3
Error! seq expected 11 received 12 errors 4
Bytes received: 60 seq 13 distaance 186 voltage 35.641590 text 'hello tes�' errors 4
Bytes received: 60 seq 14 distaance 196 voltage 38.141590 text 'hello tes�' errors 4
Bytes received: 60 seq 15 distaance 206 voltage 40.641590 text 'hello tes�' errors 4
Bytes received: 60 seq 16 distaance 216 voltage 43.141590 text 'hello tes�' errors 4

the errors were sequence number errors as I moved the transmitter about and the receiver resynchronises with the transmitter
the receiver does not report errors if the transmitter is out of range - the transmitter reports transmit failure

1 Like

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