Skip to content

esp_now_is_peer_exist is allways set to 1 #8863

@nopnop2002

Description

@nopnop2002

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 3.1.1
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 mini clone
  • Flash Mode: DOUT(compatible)
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600

esp_now

Problem Description

esp_now_is_peer_exist always returns 1, even when the ESP8266 with the target MAC address does not exist.

MCVE Sketch

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

// REPLACE WITH RECEIVER MAC Address
uint8_t broadcastAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

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

// Create a struct_message called myData
struct_message myData;

unsigned long lastTime = 0;  
unsigned long timerDelay = 2000;  // send readings timer

// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("Last Packet Send Status: ");
  if (sendStatus == 0){
    Serial.println("Delivery success");
  }
  else{
    Serial.println("Delivery fail");
  }
}
 
void setup() {
  // Init Serial Monitor
  delay(2000);
  Serial.begin(115200);
 
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  uint8_t wifi_chnnel = wifi_get_channel();
  Serial.print("wifi_chnnel=");
  Serial.println(wifi_chnnel);
  
  // Init ESP-NOW
  if (esp_now_init() != 0) {
    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_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_register_send_cb(OnDataSent);
  
  // Register peer
  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
  //esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 2, NULL, 0);
  //esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 10, NULL, 0);

  int is_peer_exist = esp_now_is_peer_exist(broadcastAddress);
  Serial.print("is_peer_exist=");
  Serial.println(is_peer_exist);

  int peer_role = esp_now_get_peer_role(broadcastAddress);
  Serial.print("peer_role=");
  Serial.println(peer_role);
    
  int espnow_chnnel = esp_now_get_peer_channel(broadcastAddress);
  Serial.print("espnow_chnnel=");
  Serial.println(espnow_chnnel);
}
 
void loop() {
  if ((millis() - lastTime) > timerDelay) {

    Serial.println();
    int is_peer_exist = esp_now_is_peer_exist(broadcastAddress);
    Serial.print("is_peer_exist=");
    Serial.println(is_peer_exist);
  
    int peer_role = esp_now_get_peer_role(broadcastAddress);
    Serial.print("peer_role=");
    Serial.println(peer_role);
      
    int espnow_chnnel = esp_now_get_peer_channel(broadcastAddress);
    Serial.print("espnow_chnnel=");
    Serial.println(espnow_chnnel);

    Serial.print(ESP.getFullVersion());
    Serial.println();
  
    // Set values to send
    strcpy(myData.a, "THIS IS A CHAR");
    myData.b = random(1,20);
    myData.c = 1.2;
    myData.d = "Hello";
    myData.e = false;

    // Send message via ESP-NOW
    esp_now_send(broadcastAddress, (uint8_t *) &myData, sizeof(myData));

    lastTime = millis();
  }
}

Debug Messages

is_peer_exist=1
peer_role=2
espnow_chnnel=1
SDK:2.2.2-dev(38a443e)/Core:3.1.1=30101000/lwIP:STABLE-2_1_3_RELEASE/glue:1.2-65-g06164fb/BearSSL:b024386
Last Packet Send Status: Delivery fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions