Merge branch 'doc/update_espnow_example_v5.1' into 'release/v5.1'

doc(WiFi/Vendor): Update the ESPNOW example for the recv callback function (backport v5.1)

See merge request espressif/esp-idf!26685
This commit is contained in:
Jiang Jiang Jian 2023-11-14 15:35:37 +08:00
commit 5a128c169c

View File

@ -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);