From 3a436b0eb2aaeb7e850b455bdf158287f8744b8a Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Thu, 7 Sep 2023 16:04:50 +0800 Subject: [PATCH] doc(WiFi/Vendor): Update the ESPNOW example for the recv callback function --- examples/wifi/espnow/main/espnow_example_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/wifi/espnow/main/espnow_example_main.c b/examples/wifi/espnow/main/espnow_example_main.c index 7ecc90dd0486..bb747c77265d 100644 --- a/examples/wifi/espnow/main/espnow_example_main.c +++ b/examples/wifi/espnow/main/espnow_example_main.c @@ -84,12 +84,23 @@ static void example_espnow_recv_cb(const esp_now_recv_info_t *recv_info, const u example_espnow_event_t evt; example_espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb; uint8_t * mac_addr = recv_info->src_addr; + uint8_t * des_addr = recv_info->des_addr; if (mac_addr == NULL || data == NULL || len <= 0) { ESP_LOGE(TAG, "Receive cb arg error"); return; } + if (IS_BROADCAST_ADDR(des_addr)) { + /* If added a peer with encryption before, the receive packets may be + * encrypted as peer-to-peer message or unencrypted over the broadcast channel. + * Users can check the destination address to distinguish it. + */ + ESP_LOGD(TAG, "Receive broadcast ESPNOW data"); + } else { + ESP_LOGD(TAG, "Receive unicast ESPNOW data"); + } + evt.id = EXAMPLE_ESPNOW_RECV_CB; memcpy(recv_cb->mac_addr, mac_addr, ESP_NOW_ETH_ALEN); recv_cb->data = malloc(len);