EasyManua.ls Logo

Espressif ESP32-S2 - Page 141

Espressif ESP32-S2
1695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2. API Reference
Send ESP-NOW Data Call esp_now_send() to send ESP-NOW data and
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 doesnt 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 Call esp_now_register_recv_cb to register receiving callback function. Call
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 cb)
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 130
Submit Document Feedback
Release v4.4

Table of Contents