Version 1.0.2
Added multiple attempts to send a message.
This commit is contained in:
parent
fa94b7a39e
commit
98efc65a52
@ -31,7 +31,8 @@
|
|||||||
.stack_size = 2048, \
|
.stack_size = 2048, \
|
||||||
.queue_size = 32, \
|
.queue_size = 32, \
|
||||||
.wifi_interface = WIFI_IF_STA, \
|
.wifi_interface = WIFI_IF_STA, \
|
||||||
.wifi_channel = 1 \
|
.wifi_channel = 1, \
|
||||||
|
.attempts = 3 \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -53,6 +54,7 @@ extern "C"
|
|||||||
uint8_t queue_size; ///< Queue size for task for the ESP-NOW messages processing. @note The size depends on the number of messages to be processed. It is not recommended to set the value less than 16.
|
uint8_t queue_size; ///< Queue size for task for the ESP-NOW messages processing. @note The size depends on the number of messages to be processed. It is not recommended to set the value less than 16.
|
||||||
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.
|
||||||
} zh_espnow_init_config_t;
|
} zh_espnow_init_config_t;
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
|
@ -1 +1 @@
|
|||||||
1.0.1
|
1.0.2
|
@ -27,6 +27,7 @@ static QueueHandle_t _queue_handle = {0};
|
|||||||
static TaskHandle_t _processing_task_handle = {0};
|
static TaskHandle_t _processing_task_handle = {0};
|
||||||
static zh_espnow_init_config_t _init_config = {0};
|
static zh_espnow_init_config_t _init_config = {0};
|
||||||
static bool _is_initialized = false;
|
static bool _is_initialized = false;
|
||||||
|
static uint8_t _attempts = 0;
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -277,6 +278,8 @@ static void _processing(void *pvParameter)
|
|||||||
}
|
}
|
||||||
memset(on_send, 0, sizeof(zh_espnow_event_on_send_t));
|
memset(on_send, 0, sizeof(zh_espnow_event_on_send_t));
|
||||||
memcpy(on_send->mac_addr, queue.data.mac_addr, 6);
|
memcpy(on_send->mac_addr, queue.data.mac_addr, 6);
|
||||||
|
SEND:
|
||||||
|
++_attempts;
|
||||||
err = esp_now_send(queue.data.mac_addr, queue.data.payload, queue.data.payload_len);
|
err = esp_now_send(queue.data.mac_addr, queue.data.payload, queue.data.payload_len);
|
||||||
if (err == ESP_ERR_ESPNOW_NO_MEM)
|
if (err == ESP_ERR_ESPNOW_NO_MEM)
|
||||||
{
|
{
|
||||||
@ -305,11 +308,17 @@ static void _processing(void *pvParameter)
|
|||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Confirmation message received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.mac_addr));
|
ESP_LOGI(TAG, "Confirmation message received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent success.", MAC2STR(queue.data.mac_addr));
|
||||||
on_send->status = ZH_ESPNOW_SEND_SUCCESS;
|
on_send->status = ZH_ESPNOW_SEND_SUCCESS;
|
||||||
|
_attempts = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (_attempts < _init_config.attempts)
|
||||||
|
{
|
||||||
|
goto SEND;
|
||||||
|
}
|
||||||
ESP_LOGE(TAG, "Confirmation message not received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent fail.", MAC2STR(queue.data.mac_addr));
|
ESP_LOGE(TAG, "Confirmation message not received. ESP-NOW message to MAC %02X:%02X:%02X:%02X:%02X:%02X sent fail.", MAC2STR(queue.data.mac_addr));
|
||||||
on_send->status = ZH_ESPNOW_SEND_FAIL;
|
on_send->status = ZH_ESPNOW_SEND_FAIL;
|
||||||
|
_attempts = 0;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.mac_addr));
|
ESP_LOGI(TAG, "Outgoing ESP-NOW data to MAC %02X:%02X:%02X:%02X:%02X:%02X processed success.", MAC2STR(queue.data.mac_addr));
|
||||||
if (esp_event_post(ZH_ESPNOW, ZH_ESPNOW_ON_SEND_EVENT, on_send, sizeof(zh_espnow_event_on_send_t), portTICK_PERIOD_MS) != ESP_OK)
|
if (esp_event_post(ZH_ESPNOW, ZH_ESPNOW_ON_SEND_EVENT, on_send, sizeof(zh_espnow_event_on_send_t), portTICK_PERIOD_MS) != ESP_OK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user