In this code I am trying to send data over the esp_now protocol, I faced problem in this my code, I have data size (arr) equal to 297, the problem is when I received the data more than 173 the data in receiver side are not correct values in addition to I could not receive all the 297 values I am just receiver 175 values. Why?
#include <esp_now.h>
#include <WiFi.h>
// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {X,X,X,X,X,X};
esp_now_peer_info_t peerInfo;
// 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");
}
int arr[]={
};
void setup() {
// Init Serial Monitor
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
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;
}
esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &arr[i], sizeof(int));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}}
}
void loop() {}
Sent with success
Sent with success
Sent with success
Sent with success
Sent with success
Sent with success
Sent with success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Sent with success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
Last Packet Send Status: Delivery Success
It appears to me that you have hardly begun to debug the process. Slow things down so that you can examine what happens, in both receiver and transmitter, at every step. Put in Serial.prints() to see values of interesting variables.
Have you successfully run one of the tutorial examples that is close to what you want in the end?
You have still not explained why you want to send the whole array to a second ESP32. What is the source of the data in the array after it has been initially defined ? What causes it to change ?