Arduino
Arduino copied to clipboard
ESPNow stops working with wifi_promiscuous_enable(true)
Platform
- Hardware: [ESP8266 device]
- Core Version: [latest git hash or date]
- Development Env: [Arduino IDE]
- Operating System: [Fedora latest]
Settings in IDE
- Module: [Generic ESP8266 Module]
Problem Description
With wifi_promiscuous_enable(true) the esp_now_register_recv_cb(OnDataRecv) callback is never reached. With the ESP32 this is no problem, only see this with the ESP8266
MCVE Sketch
#include <ESP8266WiFi.h>
#include <espnow.h>
bool myData = 0;
int32_t rssi = 0;
typedef struct {
signed rssi: 8;
unsigned rate: 4;
unsigned is_group: 1;
unsigned: 1;
unsigned sig_mode: 2;
unsigned legacy_length: 12;
unsigned damatch0: 1;
unsigned damatch1: 1;
unsigned bssidmatch0: 1;
unsigned bssidmatch1: 1;
unsigned MCS: 7;
unsigned CWB: 1;
unsigned HT_length: 16;
unsigned Smoothing: 1;
unsigned Not_Sounding: 1;
unsigned: 1;
unsigned Aggregation: 1;
unsigned STBC: 2;
unsigned FEC_CODING: 1;
unsigned SGI: 1;
unsigned rxend_state: 8;
unsigned ampdu_cnt: 8;
unsigned channel: 4;
unsigned: 12;
} wifi_pkt_rx_ctrl_t;
typedef struct {
wifi_pkt_rx_ctrl_t rx_ctrl;
uint8_t payload[0]; /* ieee80211 packet buff */
} wifi_promiscuous_pkt_t;
typedef struct {
unsigned frame_ctrl: 16;
unsigned duration_id: 16;
uint8_t addr1[6]; /* receiver address */
uint8_t addr2[6]; /* sender address */
uint8_t addr3[6]; /* filtering address */
unsigned sequence_ctrl: 16;
uint8_t addr4[6]; /* optional */
} wifi_ieee80211_mac_hdr_t;
typedef struct {
wifi_ieee80211_mac_hdr_t hdr;
uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */
} wifi_ieee80211_packet_t;
void
promisc_cb(uint8_t *buff, uint16_t len)
{
const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
rssi = (int32_t)ppkt->rx_ctrl.rssi;
}
// 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("Bool: ");
Serial.println(myData);
Serial.print("rssi: ");
Serial.println(rssi);
Serial.println();
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
Serial.println("ESP-NOW");
// 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);
wifi_promiscuous_enable(true); // enable promiscuous mode
wifi_set_promiscuous_rx_cb(promisc_cb);
}
void loop() {
}
I have exactly the same behaviour with a D1 mini. Reception of ESPNow messages is not working. But transmission of ESPNow messages from the ESP8266 is working, i.e. ESPNow is partially working. And I confirm also that there is no issue with ESP32. Have you been able to find a work around ?