Espressif ESP32-S2 Programming Manual page 141

Table of Contents

Advertisement

Chapter 2. API Reference
Send
ESP-NOW
esp_now_register_send_cb to register sending callback function. It will return ESP_NOW_SEND_SUCCESS
in sending callback function if the data is received successfully on the MAC layer. Otherwise, it will return
ESP_NOW_SEND_FAIL. Several reasons can lead to ESP-NOW fails to send data. For example, the destination
device doesn't exist; the channels of the devices are not the same; the action frame is lost when transmitting on
the air, etc. It is not guaranteed that application layer can receive the data. If necessary, send back ack data when
receiving ESP-NOW data. If receiving ack data timeouts, retransmit the ESP-NOW data. A sequence number can
also be assigned to ESP-NOW data to drop the duplicate data.
If there is a lot of ESP-NOW data to send, call esp_now_send() to send less than or equal to 250 bytes of
data once a time. Note that too short interval between sending two ESP-NOW data may lead to disorder of sending
callback function. So, it is recommended that sending the next ESP-NOW data after the sending callback function
of the previous sending has returned. The sending callback function runs from a high-priority Wi-Fi task. So, do not
do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle it from a lower
priority task.
Receiving ESP-NOW Data
the receiving callback function when receiving ESP-NOW. The receiving callback function also runs from the Wi-Fi
task. So, do not do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle
it from a lower priority task.
API Reference
Header File
components/esp_wifi/include/esp_now.h
Functions
esp_err_t
esp_now_init(void)
Initialize ESPNOW function.
Return
• ESP_OK : succeed
• ESP_ERR_ESPNOW_INTERNAL : Internal error
esp_err_t
esp_now_deinit(void)
De-initialize ESPNOW function.
Return
• ESP_OK : succeed
esp_err_t
esp_now_get_version(uint32_t *version)
Get the version of ESPNOW.
Return
• ESP_OK : succeed
• ESP_ERR_ESPNOW_ARG : invalid argument
Parameters
• version: ESPNOW version
esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t
Register callback function of receiving ESPNOW data.
Return
• ESP_OK : succeed
• ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized
• ESP_ERR_ESPNOW_INTERNAL : internal error
Parameters
• cb: callback function of receiving ESPNOW data
Espressif Systems
Data
Call
esp_now_send()
Call esp_now_register_recv_cb to register receiving callback function. Call
Submit Document Feedback
to
send
cb)
130
ESP-NOW
data
and
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF