WeMos D1 mini not receiving ESP NOW Data

I hope I'm in the right forum.

Im trying to transmit a message via ESP NOW protocol from a DoIT ESP 32 to a WeMos D1Mini. (ESP32 to ESP 8266)

I used the code from randomnerdtutorials.com.

Code for sender as follows:


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

// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t broadcastAddress[] = {0xE8, 0x9F, 0x6D, 0x8F, 0xDF, 0x56};

// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
  char a[32];
  int b;
  float c;
  bool d;
} struct_message;

// Create a struct_message called myData
struct_message myData;

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");
}
 
void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
 
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // 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() {
  // Set values to send
  strcpy(myData.a, "THIS IS A CHAR");
  myData.b = random(1,20);
  myData.c = 1.2;
  myData.d = false;
  
  // Send message via ESP-NOW
  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(2000);
}

Code for receiver as follows:

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

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    char a[32];
    int b;
    float c;
    bool d;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// Callback function that will be executed when data is received
void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Char: ");
  Serial.println(myData.a);
  Serial.print("Int: ");
  Serial.println(myData.b);
  Serial.print("Float: ");
  Serial.println(myData.c);
  Serial.print("Bool: ");
  Serial.println(myData.d);
  Serial.println();
}
 
void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    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_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  
}

With this code, I do not get any error when compiling or uploading the program.

Serial monitor of ESP 32 shows Data sent successfully but Delivery failed.

Serial monitor of WeMos is empty.

I tried adding this code under Init ESP-NOW

else if (esp_now_init() ==0){
Serial.println("Initialization successful");
}

This returns "Error initializing ESP-NOW" on the serial monitor.

However, on changing the code to

else
{
Serial.println("Initialization succesful");
}

It returns "Initialization successful" on the serial monitor.

Other than this, I have also tried

WiFi.disconnect(true);

and

ESP.eraseConfig();

both of which change absolutely nothing.

I am confused whether my ESP_now_init is active or not or whether something else is wrong.

However, on changing the roles (ie. WeMos as transmitter and ESP32 as receiver, ESP NOW works properly. (Code obtained from randomnerdtutorials.com)

I am on SDK2.2.1 with the latest arduino core.

I do not have any other ESP boards to try out, so that is not an option either.

Thanks for the help.

the problem may be in the MAC address, offhand I don’t remember which bit in the address is responsible for multicast

But i dont want multicast. Unicast is what I'm trying to achieve.
Multicast/broadcast is via 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF.

On trying this, i get the output "Successfully sent Delivery Successful" on the serial monitor of the ESP32. However, this is because Broadcast doesnt confirm the receive call back function.

Broadcasting the signal also doesnt result in any output on the WeMos serial monitor.

I have also tried the example sketches for ESP NOW under ESP32 (after modifying headers for ESP8266). The example sketch uses an AP called slave to find the receiver. This sketch doesnt require any MAC address to be added into code.
With this example sketch also I do not receive any data.

Thank you for the reply.

Check if these bits are different in MAC addresses?
MULTIKAST

Apologies but I do not understand.
My receiver MAC address is E8:9F:6D:8F:DF:56.
None of these have the 0 or 1 bit.
I'm confused.

1110 1000 = E8 Multicast is NO!

What about the MAC address of the transmitter?

Transmitter's MAC is C8:F0:9E:53:33:F8.

Could you explain how youre confirming multicast?
I'm new to this and can't understand.
Thank you.
Edit: Understood how you're confirming Unicast vs Multicast.
It is by converting the first bit into hexadecimal and looking at the output. (0 = unicast; 1 = multicast)

I encountered strange behavior for a long time, about 15 years ago, the problem was precisely that the UNICAST bit was set in the MAC address, I see this is not your case, it was decided by generating the MAC address through the calculator

Any other pointers to check for?
Thank you once again.

unfortunately I did not use the NOW protocol

However, the ESP8266 can only do either ESP-NOW or WiFi/WLAN

The ESP32 can only use ESP-NOW and WiFi if both are operated on the same channel.

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