Using ESPNOW in ESP32 and ESP8266 problems

Hello, i want to communicate using a ESP32 and ESP8266 to a esp8266 with ESP NOW. The information is something like this 360,100,180,1,0,0,1. the first 9 numbers are from a esp32, and the 1 and 0 are from a esp8266, this will be send to a 8266.
The codes i used are:

Tx esp8266

#include <ESP8266WiFi.h>
#include <espnow.h>

// Dirección MAC del receptor ESP8266
uint8_t receiverAddress[] = {0xE0, 0x97, 0x06, 0x99, 0xA2, 0x1C};

// Estructura para los datos del ESP8266
typedef struct struct_esp8266_data {
  int Up;
  int Rh;
  int Dn;
  int Lh;
} struct_esp8266_data;

struct_esp8266_data esp8266Data;

// Callback cuando se envían datos
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("Estado del último envío: ");
  Serial.println(sendStatus == 0 ? "Éxito" : "Fallo");
}

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

  if (esp_now_init() != 0) {
    Serial.println("Error al iniciar ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_register_send_cb(OnDataSent);

  esp_now_add_peer(receiverAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
}

void loop() {
  // Valores a enviar
  esp8266Data.Up = 1;
  esp8266Data.Rh = 0;
  esp8266Data.Dn = 0;
  esp8266Data.Lh = 1;

  esp_now_send(receiverAddress, (uint8_t *) &esp8266Data, sizeof(esp8266Data));
  delay(100); // Enviar cada 100 ms
}

Tx esp32

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

// Dirección MAC del receptor ESP8266
uint8_t broadcastAddress[] = {0xE0, 0x97, 0x06, 0x99, 0xA2, 0x1C};

// Estructura para enviar datos desde el ESP32
typedef struct struct_message {
  int grado;
  int distancia;
  int angulo;
} struct_message;

struct_message myData;

void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("Estado del envío: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Éxito" : "Fallido");
}

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }
  esp_now_register_send_cb(OnDataSent);

  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Error al añadir peer");
    return;
  }
}

void loop() {
  myData.grado = 360;
  myData.distancia = 100;
  myData.angulo = 180;

  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
  if (result == ESP_OK) {
    Serial.println("Datos enviados con éxito");
  } else {
    Serial.println("Error al enviar los datos");
  }
  delay(100);  // Envía cada 100 ms
}

Rx esp8266

#include <ESP8266WiFi.h>
#include <espnow.h>

typedef struct struct_message_esp32 {
  int grado;
  int distancia;
  int angulo;
} struct_message_esp32;

typedef struct struct_message_esp8266 {
  int Up;
  int Rh;
  int Dn;
  int Lh;
} struct_message_esp8266;

struct_message_esp32 dataESP32;
struct_message_esp8266 dataESP8266;

void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  if (len == sizeof(dataESP32)) {
    memcpy(&dataESP32, incomingData, sizeof(dataESP32));
  } else if (len == sizeof(dataESP8266)) {
    memcpy(&dataESP8266, incomingData, sizeof(dataESP8266));
  }
  
  Serial.print("Datos recibidos: ");
  Serial.print(dataESP32.grado); Serial.print(",");
  Serial.print(dataESP32.distancia); Serial.print(",");
  Serial.print(dataESP32.angulo); Serial.print(",");
  Serial.print(dataESP8266.Up); Serial.print(",");
  Serial.print(dataESP8266.Rh); Serial.print(",");
  Serial.print(dataESP8266.Dn); Serial.print(",");
  Serial.println(dataESP8266.Lh);
}

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

  if (esp_now_init() != 0) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  // Mantener el ESP8266 escuchando
}

I ask here if someone already do it and know what to do. I dont have any console error. The only i have problems is from the esp32, the two esp8266 transfer data with no problem.

PD: sorry if this the wrong channel, also its in spanish but i think there are quicker in english.

I am wondering whether the two can ESPNow to/with each other.

Evidently, ESP32 as sender and ESP8266 is not 'working'. Does it "fail to add Peer" or is there "error sending data"?

Have you tried ESP8266 as sender and ESP32 as receiver?

PE --
Adding link
Connecting ESP8266 and ESP32 Using ESP-NOW -

i should try, but the main reason esp32 is a sender is because it has more pins and 5v output for the componets i use. Thanks you so much for answering

Just something to try - more information.
And the link shows sketches where he is doing what you want to do.
Try his as a baseline test (again, it's more information).

(Maybe this is another example of version 3 (core library) incompatibility. You might dial back, revert, to version 2.x - if that's not your current status.)

I have tried this - without success.

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
E (83) ESPNOW: Peer interface is invalid
Peer Add fail
Send - fail
Send - fail

ESP32 sender ─

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

// Replace with the MAC address of your ESP8266
uint8_t receiverAddress[] = {0x3C, 0x71, 0xBF, 0x2A, 0x91, 0x00};
// Callback when data is sent

void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) 
{
  Serial.print("Last Pkt Send Status: ");
  if (status == ESP_NOW_SEND_SUCCESS) 
  {
    Serial.println("Delivery made");
  } 
  else  
  {
    Serial.println("Delivery fail");
  }
}

void setup() 
{
  Serial.begin(115200);
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  // Initialize ESP-NOW
  if (esp_now_init() != ESP_OK) 
  {
    Serial.println("Error ESP-NOW init");
    return;
  }
  // Register callback for sending data
  esp_now_register_send_cb(onDataSent);
  // Add receiver's MAC address
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, receiverAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  if (esp_now_add_peer(&peerInfo) != ESP_OK) 
  {
    Serial.println("Peer Add fail");
    return;
  }
}

void loop() 
{
  // Send data to the receiver
  uint8_t data[] = "Hello, ESP-NOW!";
  esp_err_t result = esp_now_send(receiverAddress, data, sizeof(data));
  if (result == ESP_OK) 
  {
    Serial.println("Send - success");
  } 
  else 
  {
    Serial.println("Send - fail");
  }
  delay(2000);
  
}

ESP8266 receiver ─

#include <ESP8266WiFi.h>
#include <espnow.h>

// Callback when data is received

void onDataReceived(uint8_t *senderMac, uint8_t *incomingData, uint8_t len) 
{
  Serial.print("Received: ");
  for (int i = 0; i < len; i++) 
  {
    Serial.print((char)incomingData[i]);
  }
  
  Serial.println();
}

void setup() 
{
  Serial.begin(115200);
  // Set device as a Wi-Fi Station
  delay(2000);
  Serial.println("\r\n\r\nrx ready");
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  // Print MAC address of the receiver
  Serial.print("Receiver MAC: ");
  for (int i = 0; i < 6; i++) 
  {
    Serial.print(WiFi.macAddress()[i], HEX);
    if (i < 5) 
    {
      Serial.print(":");
    }
  }
  Serial.println();
  // Initialize ESP-NOW
  if (esp_now_init() != 0) 
  {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Register callback for receiving data
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(onDataReceived);
}

void loop() 
{
  // Nothing to do here
}

The receiver prints out, once ─

rx ready
Receiver MAC: 33:43:3A:37:31:3A

which is different than the result I get when I run the 'find your mac' sketch.

I did some research on the failure to Add Peer and made this change to Sender setup()
[find memset] ─

void setup() 
{
  Serial.begin(115200);
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  // Initialize ESP-NOW
  if (esp_now_init() != ESP_OK) 
  {
    Serial.println("Error ESP-NOW init");
    return;
  }
  // Register callback for sending data
  esp_now_register_send_cb(onDataSent);
  // Add receiver's MAC address
  esp_now_peer_info_t peerInfo;
  //  -----    -----    -----    -----
  memset(&peerInfo, 0, sizeof(peerInfo));    // addendum - gets Peer added
                                             // Send Success, but Delivery Fails
  //  -----    -----    -----    -----                                             
  memcpy(peerInfo.peer_addr, receiverAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  if (esp_now_add_peer(&peerInfo) != ESP_OK) 
  {
    Serial.println("Peer Add fail");
    return;
  }
}

It now adds the Peer, however, it's still not right ─

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
Send - success
Last Pkt Send Status: Delivery fail
Send - success
Last Pkt Send Status: Delivery fail

Send success, but Delivery fail ??

i am now using the two esp8266 as an emmiter and the esp32 as a receiver. I havent tested out yet, i dont have much time to do it. Another question, can i add a sensor to the receber, and with that i use only two board.

Esp8266 emiter 1

#include <ESP8266WiFi.h>
#include <espnow.h>

typedef struct struct_message {
  int valor1;
  int valor2;
  int valor3;
} struct_message;

struct_message dataToSend;

uint8_t receptorAddress[] = {0x08, 0xD1, 0xF9, 0x3B, 0x33, 0xC0};

void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("Estado de envío: ");
  Serial.println(sendStatus == 0 ? "Envío exitoso" : "Error en el envío");
}

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

  if (esp_now_init() != 0) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_add_peer(receptorAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
  esp_now_register_send_cb(OnDataSent);
}

void loop() {
  dataToSend.valor1 = 180;
  dataToSend.valor2 = 100;
  dataToSend.valor3 = 180;

  esp_now_send(receptorAddress, (uint8_t *) &dataToSend, sizeof(dataToSend));
  delay(100);  // Enviar cada 100 ms
}

ESP8266 emmiter 2

#include <ESP8266WiFi.h>
#include <espnow.h>

typedef struct struct_message {
  int Up;
  int Rh;
  int Dn;
  int Lh;
} struct_message;

struct_message dataToSend;

uint8_t receptorAddress[] = {0x08, 0xD1, 0xF9, 0x3B, 0x33, 0xC0};

void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("Estado de envío: ");
  Serial.println(sendStatus == 0 ? "Envío exitoso" : "Error en el envío");
}

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

  if (esp_now_init() != 0) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_add_peer(receptorAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
  esp_now_register_send_cb(OnDataSent);
}

void loop() {
  dataToSend.Up = 1;
  dataToSend.Rh = 0;
  dataToSend.Dn = 0;
  dataToSend.Lh = 0;

  esp_now_send(receptorAddress, (uint8_t *) &dataToSend, sizeof(dataToSend));
  delay(100);  // Enviar cada 100 ms
}

ESP32 receiber

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

typedef struct struct_message_1 {
  int valor1;
  int valor2;
  int valor3;
} struct_message_1;

typedef struct struct_message_2 {
  int Up;
  int Rh;
  int Dn;
  int Lh;
} struct_message_2;

struct_message_1 incomingData1;
struct_message_2 incomingData2;

bool receivedData1 = false;
bool receivedData2 = false;

uint8_t macAddresses[2][6];
int numTransmitters = 0;

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  bool knownDevice = false;

  // Verificar si el dispositivo ya está registrado
  for (int i = 0; i < numTransmitters; i++) {
    if (memcmp(mac, macAddresses[i], 6) == 0) {
      knownDevice = true;
      if (i == 0) {
        memcpy(&incomingData1, incomingData, sizeof(incomingData1));
        receivedData1 = true;
      } else if (i == 1) {
        memcpy(&incomingData2, incomingData, sizeof(incomingData2));
        receivedData2 = true;
      }
      break;
    }
  }

  // Agregar dispositivo nuevo si no está registrado
  if (!knownDevice && numTransmitters < 2) {
    memcpy(macAddresses[numTransmitters], mac, 6);
    esp_now_peer_info_t peerInfo = {};
    memcpy(peerInfo.peer_addr, mac, 6);
    if (esp_now_add_peer(&peerInfo) == ESP_OK) {
      Serial.printf("Nuevo dispositivo añadido: %02X:%02X:%02X:%02X:%02X:%02X\n",
                    mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
      numTransmitters++;
    }
  }
}

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

  if (esp_now_init() != ESP_OK) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }
  
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  if (receivedData1 && receivedData2) {
    Serial.printf("%d,%d,%d,%d,%d,%d,%d\n",
      incomingData1.valor1, incomingData1.valor2, incomingData1.valor3,
      incomingData2.Up, incomingData2.Rh, incomingData2.Dn, incomingData2.Lh
    );
    receivedData1 = false;
    receivedData2 = false;
  }
  delay(100);  // Imprimir cada 100 ms
}

Thanks

I'm nobody's idea of an expert anything to do with WiFi.

in post 1 in ESP32 setup() you have defined

 esp_now_peer_info_t peerInfo;

as a local variable - unless you explicitly initialize a local variable the value is undefined (whatever is in memory at the time)
try initializing it

  esp_now_peer_info_t peerInfo={0};
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);

yes

if you are using ESP32 core 3.x you will need to change

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len)

to

void OnDataRecv(const esp_now_recv_info_t* mac, const unsigned char* incomingData, int len) {

@horace The OP's sketches , and mine, are of allegedly working examples.
My example, the Sender, wasn't finding any Peer till I made the following modification --

esp_now_register_send_cb(onDataSent);
// Add receiver's MAC address
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo)); // addendum

memcpy(peerInfo.peer_addr, receiverAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;

The Peer got added with that, but now it's -- Send Success, but Delivery Fails.

I am using 2.0.16 (or .17) - definitely not 3.x

(I've had more success with a non-ESPNow Server-Client arrangement, actually.)

@anon85221860 your code

esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo)); // addendum

has the same effect as mine initializing peerinfo to 0

  esp_now_peer_info_t peerInfo={0};

if I now run the transmitter ithe ESP32 displays

Datos enviados con éxito
Estado del envío: Éxito
Datos enviados con éxito
Estado del envío: Éxito
Datos enviados con éxito
Estado del envío: Éxito

in English

Data Successfully Submitted Shipment Status: Success
Data Successfully Submitted Shipment Status: Success 
Data Successfully Submitted Shipment Status: Success

and the ESP8266 receiver displays Data received

Datos recibidos: 360,100,180,0,0,0,0
Datos recibidos: 360,100,180,0,0,0,0
Datos recibidos: 360,100,180,0,0,0,0
Datos recibidos: 360,100,180,0,0,0,0

this is using ESP32 core V3.0.7 but gives identical output using 2.0.17

I tend to have the receiver poll when using multiple transmitters

@horace
Thanks for the Reply.
My Sender sketch is in Post No.5 with the setup() as modified in Post No.6

If I'm not mistaken - it's supposed to be sending
Hello, ESP-NOW!
(cf. Datos recibidos: 360,100,180,0,0,0,0)

the transmitter/receiver code I ran was from post 1 which transmits a structure

// Estructura para enviar datos desde el ESP32
typedef struct struct_message {
  int grado;
  int distancia;
  int angulo;
} struct_message;

......

void loop() {
  myData.grado = 360;
  myData.distancia = 100;
  myData.angulo = 180;

  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));

and the receiver displays

Data received: 360,100,180,0,0,0,0

360,100,180, from structure struct_message_esp32
the receiver also prints the structure struct_message_esp8266 which gives the 0,0,0

Can you show the codes again. Im dont know who you two are answering, realy sorry.

Evidently, the modification that horace posted in No.11, was intended for you - your Sender - and should clear everything up.

in post 1 in ESP32 setup() you have defined

 esp_now_peer_info_t peerInfo;

as a local variable - unless you explicitly initialize a local variable the value is undefined (whatever is in memory at the time - garbage!)
try initializing it to 0

  esp_now_peer_info_t peerInfo={0};
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);

the code of post 1 then works on my ESP32 and ESP8266

I based all my research on the link in Post No.2 (Sr. Tiago)
He has a webpage where it ostensibly works.

The Sender needed one mod - previously noted by me, and similarly @horace.

The Receiver sketch needed a modification, too, though.
After WiFi.mode(WIFI_STA);
he has WiFi.disconnect();
Sometimes this ESP stuff can be darned opaque and I was copying and pasting - as it purportedly "worked". Well - removing ('commenting out') that WiFi.disconnect(); made all the difference: The Sender makes deliveries and the Receiver gets the goods.

In closing, and without further ado, if anyone is interested -- here's how it is:

Sender


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

// Replace with the MAC address of your ESP8266
uint8_t receiverAddress[] = {0x3c, 0x71, 0xbf, 0x2a, 0x91, 0x00};
// Callback when data is sent

void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) 
{
  Serial.print("Last Pkt Send Status: ");
  if (status == ESP_NOW_SEND_SUCCESS) 
  {
    Serial.println("Delivery made");
  } 
  else  
  {
    Serial.println("Delivery fail");
  }
}

void setup() 
{
  Serial.begin(115200);
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  // Initialize ESP-NOW
  if (esp_now_init() != ESP_OK) 
  {
    Serial.println("Error ESP-NOW init");
    return;
  }
  // Register callback for sending data
  esp_now_register_send_cb(onDataSent);
  // Add receiver's MAC address
  esp_now_peer_info_t peerInfo;
  //  -----    -----    -----    -----
  memset(&peerInfo, 0, sizeof(peerInfo));    // addendum - gets Peer added
                                             // Send Success, but Delivery Fails
  //  -----    -----    -----    -----                                             
  memcpy(peerInfo.peer_addr, receiverAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  if (esp_now_add_peer(&peerInfo) != ESP_OK) 
  {
    Serial.println("Peer Add fail");
    return;
  }
}

void loop() 
{
  // Send data to the receiver
  uint8_t data[] = "Hello, ESP-NOW!";
  esp_err_t result = esp_now_send(receiverAddress, data, sizeof(data));
  if (result == ESP_OK) 
  {
    Serial.println("Send - success");
  } 
  else 
  {
    Serial.println("Send - fail");
  }
  delay(2000);
  
}

Receiver

#include <ESP8266WiFi.h>
#include <espnow.h>

// Callback when data is received

void onDataReceived(uint8_t *senderMac, uint8_t *incomingData, uint8_t len)
{
  Serial.print("Received: ");
  for (int i = 0; i < len; i++)
  {
    Serial.print((char)incomingData[i]);
  }

  Serial.println();
}

void setup()
{
  Serial.begin(115200);
  // Set device as a Wi-Fi Station
  delay(2000);
  Serial.println("\r\n\r\nrx ready");
  WiFi.mode(WIFI_STA);
  
  //  Why? →→ WiFi.disconnect();  // some mistake
  
  // Print MAC address of the receiver →
  Serial.print("Receiver MAC: ");
  for (int i = 0; i < 6; i++)
  {
    Serial.print(WiFi.macAddress()[i], HEX);
    if (i < 5)
    {
      Serial.print(":");
    }
  }
  Serial.println();
  // Initialize ESP-NOW
  if (esp_now_init() != 0)
  {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Register callback for receiving data
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(onDataReceived);
}

void loop()
{
  // Nothing to do here
}

Hello everyone. good news, i found the solution:

Tx ESP8266

#include <ESP8266WiFi.h>
#include <espnow.h>

uint8_t broadcastAddress[] = {0xE0, 0x98, 0x06, 0x99, 0xA2, 0x1C};
#define BOARD_ID 2

typedef struct struct_message {
    int id;
    int x;
    int y;
    int z;
    int w;
} struct_message;

struct_message myData;

void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("\r\nLast Packet Send Status: ");
  Serial.println(sendStatus == 0 ? "Delivery success" : "Delivery fail");
}
 
void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

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

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_register_send_cb(OnDataSent);
  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
}
 
void loop() {
  myData.id = BOARD_ID;
  myData.x = random(1, 50);
  myData.y = random(1, 50);
  myData.z = random(1, 50);
  myData.w = random(1, 50);

  esp_now_send(0, (uint8_t *) &myData, sizeof(myData));
  delay(100);
}

Tx ESP32

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

uint8_t broadcastAddress[] = {0xE0, 0x98, 0x06, 0x99, 0xA2, 0x1C};

typedef struct struct_message {
    int id;
    int x;
    int y;
    int z;
    int w;
} struct_message;

struct_message myData;
esp_now_peer_info_t peerInfo;

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() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);

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

  esp_now_register_send_cb(OnDataSent);
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;  
  peerInfo.encrypt = false;
  
  if (esp_now_add_peer(&peerInfo) != ESP_OK){
    Serial.println("Failed to add peer");
    return;
  }
}
 
void loop() {
  myData.id = 1;
  myData.x = random(0,50);
  myData.y = random(0,50);
  myData.z = random(0,50);
  myData.w = random(0,50);

  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));
   
  if (result == ESP_OK) {
    Serial.println("Sent with success");
  }
  else {
    Serial.println("Error sending the data");
  }
  delay(100);
}

Rx ESP826

//Se incluyen las librerias de wifi y ESP NOW
#include <ESP8266WiFi.h>
#include <espnow.h>

//Se crea la estructura del mensaje
typedef struct struct_message {
    int id;
    int x;
    int y;
    int z;
    int w;
} struct_message;

//Se usan la estructura del mensaje para los datos de la placa 1 y 2
struct_message myData;
struct_message board1;
struct_message board2;
struct_message boardsStruct[2] = {board1, board2};

//Aqui recibo los datos, creo
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) {
  memcpy(&myData, incomingData, sizeof(myData));
  boardsStruct[myData.id - 1].x = myData.x;
  boardsStruct[myData.id - 1].y = myData.y;
  boardsStruct[myData.id - 1].z = myData.z;
  boardsStruct[myData.id - 1].w = myData.w;
}

void setup() {
  //Inicio la consola y entro en modo wifi
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  //Verifico si inicio o no ESP NOW
  if (esp_now_init() != 0) {
    Serial.println("Error al inicializar ESP-NOW");
    return;
  }

  //Se activa como rol de esclavo, bien negro
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);
}

void loop(){
  //Se crea la estructura de los mensajes
  int board1X = boardsStruct[0].x;
  int board1Y = boardsStruct[0].y;
  int board1Z = boardsStruct[0].z;
  int board1W = boardsStruct[0].w;
  
  int board2X = boardsStruct[1].x;
  int board2Y = boardsStruct[1].y;
  int board2Z = boardsStruct[1].z;
  
  //Se imprime el mensaje
  Serial.print(board2X); Serial.print(",");
  Serial.print(board2Y); Serial.print(",");
  Serial.print(board2Z); Serial.print(",");

  Serial.print(board1X); Serial.print(",");
  Serial.print(board1Y); Serial.print(",");
  Serial.print(board1Z); Serial.print(",");
  Serial.println(board1W);
  

  delay(100);
}

This solves the problem when i need a esp8266 and a esp32 as emmiters and a esp8266 as a receptor.
Thanks for everyone help. But i didnt undestand you well.

WiFi.disconnect() was killing me - and it works for you.
OK fine.