Version 1.3.0

Added support for the node's battery operation mode.
This commit is contained in:
Alexey Zholtikov 2025-01-20 17:28:21 +03:00
parent 7608ba0abf
commit f4ecd08e45
3 changed files with 23 additions and 7 deletions

View File

@ -16,7 +16,8 @@
.queue_size = 64, \ .queue_size = 64, \
.wifi_interface = WIFI_IF_STA, \ .wifi_interface = WIFI_IF_STA, \
.wifi_channel = 1, \ .wifi_channel = 1, \
.attempts = 3} .attempts = 3, \
.battery_mode = false}
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -31,6 +32,7 @@ extern "C"
wifi_interface_t wifi_interface; // WiFi interface (STA or AP) used for ESP-NOW operation. @note The MAC address of the device depends on the selected WiFi interface. wifi_interface_t wifi_interface; // WiFi interface (STA or AP) used for ESP-NOW operation. @note The MAC address of the device depends on the selected WiFi interface.
uint8_t wifi_channel; // Wi-Fi channel uses to send/receive ESP-NOW data. @note Values from 1 to 14. uint8_t wifi_channel; // Wi-Fi channel uses to send/receive ESP-NOW data. @note Values from 1 to 14.
uint8_t attempts; // Maximum number of attempts to send a message. @note It is not recommended to set a value greater than 5. uint8_t attempts; // Maximum number of attempts to send a message. @note It is not recommended to set a value greater than 5.
bool battery_mode; // Battery operation mode. If true, the node does not receive messages.
} zh_espnow_init_config_t; } zh_espnow_init_config_t;
ESP_EVENT_DECLARE_BASE(ZH_ESPNOW); ESP_EVENT_DECLARE_BASE(ZH_ESPNOW);
@ -106,7 +108,7 @@ extern "C"
/** /**
* @brief Get ESP-NOW version. * @brief Get ESP-NOW version.
* *
* @return * @return
* - ESP-NOW version * - ESP-NOW version
*/ */

View File

@ -1 +1 @@
1.2.0 1.3.0

View File

@ -76,10 +76,21 @@ esp_err_t zh_espnow_init(const zh_espnow_init_config_t *config)
esp_wifi_set_protocol(_init_config.wifi_interface, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_LR); esp_wifi_set_protocol(_init_config.wifi_interface, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_LR);
_event_group_handle = xEventGroupCreate(); _event_group_handle = xEventGroupCreate();
_queue_handle = xQueueCreate(_init_config.queue_size, sizeof(_queue_t)); _queue_handle = xQueueCreate(_init_config.queue_size, sizeof(_queue_t));
if (esp_now_init() != ESP_OK || esp_now_register_send_cb(_send_cb) != ESP_OK || esp_now_register_recv_cb(_recv_cb) != ESP_OK) if (_init_config.battery_mode == false)
{ {
ESP_LOGE(TAG, "ESP-NOW initialization fail. Internal error at line %d.", __LINE__); if (esp_now_init() != ESP_OK || esp_now_register_send_cb(_send_cb) != ESP_OK || esp_now_register_recv_cb(_recv_cb) != ESP_OK)
return ESP_FAIL; {
ESP_LOGE(TAG, "ESP-NOW initialization fail. Internal error at line %d.", __LINE__);
return ESP_FAIL;
}
}
else
{
if (esp_now_init() != ESP_OK || esp_now_register_send_cb(_send_cb) != ESP_OK)
{
ESP_LOGE(TAG, "ESP-NOW initialization fail. Internal error at line %d.", __LINE__);
return ESP_FAIL;
}
} }
if (xTaskCreatePinnedToCore(&_processing, "zh_espnow_processing", _init_config.stack_size, NULL, _init_config.task_priority, &_processing_task_handle, tskNO_AFFINITY) != pdPASS) if (xTaskCreatePinnedToCore(&_processing, "zh_espnow_processing", _init_config.stack_size, NULL, _init_config.task_priority, &_processing_task_handle, tskNO_AFFINITY) != pdPASS)
{ {
@ -102,7 +113,10 @@ esp_err_t zh_espnow_deinit(void)
vEventGroupDelete(_event_group_handle); vEventGroupDelete(_event_group_handle);
vQueueDelete(_queue_handle); vQueueDelete(_queue_handle);
esp_now_unregister_send_cb(); esp_now_unregister_send_cb();
esp_now_unregister_recv_cb(); if (_init_config.battery_mode == false)
{
esp_now_unregister_recv_cb();
}
esp_now_deinit(); esp_now_deinit();
vTaskDelete(_processing_task_handle); vTaskDelete(_processing_task_handle);
_is_initialized = false; _is_initialized = false;