Skip to content

Commit a8bd4f0

Browse files
fix(wifi): Return more information in the espnow send callback
1 parent d196147 commit a8bd4f0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

components/esp_wifi/include/esp_now.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ extern "C" {
5757
* @brief Status of sending ESPNOW data .
5858
*/
5959
typedef enum {
60-
ESP_NOW_SEND_SUCCESS = 0, /**< Send ESPNOW data successfully */
61-
ESP_NOW_SEND_FAIL, /**< Send ESPNOW data fail */
60+
ESP_NOW_SEND_SUCCESS = WIFI_SEND_SUCCESS, /**< Send ESPNOW data successfully */
61+
ESP_NOW_SEND_FAIL = WIFI_SEND_FAIL, /**< Send ESPNOW data fail */
6262
} esp_now_send_status_t;
6363

6464
/**
@@ -84,14 +84,19 @@ typedef struct esp_now_peer_num {
8484
} esp_now_peer_num_t;
8585

8686
/**
87-
* @brief ESPNOW packet information
87+
* @brief ESPNOW receive packet information
8888
*/
8989
typedef struct esp_now_recv_info {
9090
uint8_t * src_addr; /**< Source address of ESPNOW packet */
9191
uint8_t * des_addr; /**< Destination address of ESPNOW packet */
9292
wifi_pkt_rx_ctrl_t * rx_ctrl; /**< Rx control info of ESPNOW packet */
9393
} esp_now_recv_info_t;
9494

95+
/**
96+
* @brief ESPNOW sending packet information
97+
*/
98+
typedef wifi_tx_info_t esp_now_send_info_t;
99+
95100
/**
96101
* @brief ESPNOW rate config
97102
*/
@@ -108,10 +113,10 @@ typedef void (*esp_now_recv_cb_t)(const esp_now_recv_info_t * esp_now_info, cons
108113

109114
/**
110115
* @brief Callback function of sending ESPNOW data
111-
* @param mac_addr peer MAC address
112-
* @param status status of sending ESPNOW data (succeed or fail)
116+
* @param esp_now_send_info_t Sending information for ESPNOW data
117+
* @param status status of sending ESPNOW data (succeed or fail). This is will be removed later, since the tx_info->tx_status also works.
113118
*/
114-
typedef void (*esp_now_send_cb_t)(const uint8_t *mac_addr, esp_now_send_status_t status);
119+
typedef void (*esp_now_send_cb_t)(const esp_now_send_info_t *tx_info, esp_now_send_status_t status);
115120

116121
/**
117122
* @brief Initialize ESPNOW function

examples/wifi/espnow/main/espnow_example_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ static void example_wifi_init(void)
6161
/* ESPNOW sending or receiving callback function is called in WiFi task.
6262
* Users should not do lengthy operations from this task. Instead, post
6363
* necessary data to a queue and handle it from a lower priority task. */
64-
static void example_espnow_send_cb(const uint8_t *mac_addr, esp_now_send_status_t status)
64+
static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)
6565
{
6666
example_espnow_event_t evt;
6767
example_espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
6868

69-
if (mac_addr == NULL) {
69+
if (tx_info == NULL) {
7070
ESP_LOGE(TAG, "Send cb arg error");
7171
return;
7272
}
7373

7474
evt.id = EXAMPLE_ESPNOW_SEND_CB;
75-
memcpy(send_cb->mac_addr, mac_addr, ESP_NOW_ETH_ALEN);
75+
memcpy(send_cb->mac_addr, tx_info->des_addr, ESP_NOW_ETH_ALEN);
7676
send_cb->status = status;
7777
if (xQueueSend(s_example_espnow_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
7878
ESP_LOGW(TAG, "Send send queue fail");

0 commit comments

Comments
 (0)