Skip to content

Commit

Permalink
Merge branch 'doc/update_espnow_example_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
doc(WiFi/Vendor): Update the ESPNOW example for the recv callback function (backport v5.1)

See merge request espressif/esp-idf!26685
  • Loading branch information
jack0c committed Nov 14, 2023
2 parents 9c5b538 + 3a436b0 commit 5a128c1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/wifi/espnow/main/espnow_example_main.c
Expand Up @@ -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);
Expand Down

0 comments on commit 5a128c1

Please sign in to comment.