ESP-NOW project "Sending error"

#include <Arduino.h>
#include <TFT_eSPI.h>
#include "Wire.h"
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>

#define WIDTH  155
#define HEIGHT 180

esp_now_peer_info_t slave;
uint8_t  peer_addr[]= {0xC0, 0x49, 0xEF, 0xB4, 0x3F, 0xBC};//peer_addr目标MAC地址

#define CHANNEL 1

const int buttonUp = 13;
const int buttonDown = 12;
const int buttonLeft = 14;
const int buttonRight = 27;
const int buttonCenter = 26;
const int buttonSet = 25;
const int buttonRest = 33;

struct ControllerData {
String up;
String down;
String left;
String right;
String center;
String Set;
String Rest;
};


ControllerData controllerData;


esp_now_peer_info_t peerInfo;


TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft); 

  
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  memcpy(slave.peer_addr, peer_addr, sizeof(slave.peer_addr));

  Serial.print("\r\nLast Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

  

void setup() {
  Serial.begin(115200);
  Wire.begin();
  WiFi.mode(WIFI_STA);

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

  esp_now_register_send_cb(OnDataSent);
  
    // Register peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, peer_addr, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
  peerInfo.ifidx=WIFI_IF_AP;
  
    // Add peer        
  if (esp_now_add_peer(&peerInfo) != ESP_OK)
  {
    Serial.println("Failed to add peer");
    return;
  }
  else
  {
    Serial.println("Succes: Added peer");
  } 
  
  pinMode(buttonUp, INPUT_PULLUP);
  pinMode(buttonDown, INPUT_PULLUP);
  pinMode(buttonLeft, INPUT_PULLUP);
  pinMode(buttonRight, INPUT_PULLUP);
  pinMode(buttonCenter, INPUT_PULLUP);
  pinMode(buttonSet, INPUT_PULLUP);
  pinMode(buttonRest, INPUT_PULLUP);
  
  tft.init();
  tft.setRotation(5);
  spr.createSprite(WIDTH,HEIGHT); 
  spr.fillScreen(TFT_BLACK);
  spr.setTextFont(2);
  spr.setTextSize(1);
  spr.setTextColor(TFT_GREEN);

}

void loop() {
  controllerData.up = digitalRead(buttonUp);
  controllerData.down = digitalRead(buttonDown);
  controllerData.left = digitalRead(buttonLeft);
  controllerData.right = digitalRead(buttonRight);
  controllerData.center = digitalRead(buttonCenter);
  controllerData.Set = digitalRead(buttonSet);
  controllerData.Rest = digitalRead(buttonRest);
 
  esp_err_t result = esp_now_send(peer_addr, (uint8_t *) &controllerData, sizeof(controllerData));
  if (result == ESP_OK) {
    Serial.println("Sending confirmed");
  }
  else {
    Serial.println("Sending error");
  }
 
  

  spr.fillScreen(TFT_BLACK);
  spr.setCursor(0, 0);
  

  if (digitalRead(buttonUp) == LOW) {
    spr.drawString("UP: Pressed", 0, 0);
  }else{
    spr.drawString("UP: Released", 0, 0);
  }

  if (digitalRead(buttonDown) == LOW) {
    spr.drawString("DOWN: Pressed", 0, 20);
  }else{
    spr.drawString("DOWN: Released", 0, 20);
  } 

  if (digitalRead(buttonLeft) == LOW) {
    spr.drawString("LEFT: Pressed", 0, 40);
  }else{
    spr.drawString("LEFT: Released", 0, 40);
  } 

  if ( digitalRead(buttonRight)== LOW) {
    spr.drawString("RIGHT: Pressed", 0, 60);
  }else{
    spr.drawString("RIGHT: Released", 0, 60);
  } 

  if (digitalRead(buttonCenter) == LOW) {
    spr.drawString("CENTER: Pressed", 0, 80);
  }else{
    spr.drawString("CENTER: Released", 0,80);
  } 

  if (digitalRead(buttonSet) == LOW){
    spr.drawString("SET: Pressed", 0, 100);
  }else{
    spr.drawString("SET: Released", 0, 100);
  } 
  
  if (digitalRead(buttonRest) == LOW){
    spr.drawString("REST: Pressed", 0, 120);
  }else{
    spr.drawString("REST: Released", 0, 120);
  } 
  

  spr.pushSprite(0, 0);

  
  delay(10);
}

load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4
Sending error
Sending error
Sending error

hi all,The serial port window displays "Sending error", I don’t know what’s going on, please help, thank you.

what does OnDataSent() indicate "Delivery Success" or "Delivery Fail"
upload a copy of the serial monitor output (as text not screen image)
are you sure you have the correct MAC address for the receiver?

upadated code completed.

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