Added multiple attempts to send a message
This commit is contained in:
@ -52,7 +52,8 @@
|
|||||||
.id_vector_size = 100, \
|
.id_vector_size = 100, \
|
||||||
.route_vector_size = 100, \
|
.route_vector_size = 100, \
|
||||||
.wifi_interface = WIFI_IF_STA, \
|
.wifi_interface = WIFI_IF_STA, \
|
||||||
.wifi_channel = 1 \
|
.wifi_channel = 1, \
|
||||||
|
.attempts = 3 \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -78,6 +79,7 @@ extern "C"
|
|||||||
uint16_t route_vector_size; ///< The maximum size of the routing table. @note If the size is exceeded, the first route will be deleted. Minimum recommended value: number of planned nodes in the network + 10%.
|
uint16_t route_vector_size; ///< The maximum size of the routing table. @note If the size is exceeded, the first route will be deleted. Minimum recommended value: number of planned nodes in the network + 10%.
|
||||||
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 ESPNOW data. @note Values from 1 to 14.
|
uint8_t wifi_channel; ///< Wi-Fi channel uses to send/receive ESPNOW 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_network_init_config_t;
|
} zh_network_init_config_t;
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
|
@ -32,6 +32,7 @@ static zh_vector_t _response_vector = {0};
|
|||||||
static uint8_t _self_mac[6] = {0};
|
static uint8_t _self_mac[6] = {0};
|
||||||
static const uint8_t _broadcast_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
static const uint8_t _broadcast_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
static bool _is_initialized = false;
|
static bool _is_initialized = false;
|
||||||
|
static uint8_t _attempts = 0;
|
||||||
|
|
||||||
/// \cond
|
/// \cond
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -401,6 +402,8 @@ static void _processing(void *pvParameter)
|
|||||||
}
|
}
|
||||||
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
memset(on_send, 0, sizeof(zh_network_event_on_send_t));
|
||||||
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
memcpy(on_send->mac_addr, queue.data.original_target_mac, 6);
|
||||||
|
SEND:
|
||||||
|
++_attempts;
|
||||||
if (esp_now_send((uint8_t *)peer->peer_addr, (uint8_t *)&queue.data, sizeof(_queue_t) - 12) != ESP_OK)
|
if (esp_now_send((uint8_t *)peer->peer_addr, (uint8_t *)&queue.data, sizeof(_queue_t) - 12) != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
ESP_LOGE(TAG, "ESP-NOW message processing task internal error at line %d.", __LINE__);
|
||||||
@ -411,6 +414,7 @@ static void _processing(void *pvParameter)
|
|||||||
EventBits_t bit = xEventGroupWaitBits(_event_group_handle, DATA_SEND_SUCCESS | DATA_SEND_FAIL, pdTRUE, pdFALSE, 50 / portTICK_PERIOD_MS);
|
EventBits_t bit = xEventGroupWaitBits(_event_group_handle, DATA_SEND_SUCCESS | DATA_SEND_FAIL, pdTRUE, pdFALSE, 50 / portTICK_PERIOD_MS);
|
||||||
if ((bit & DATA_SEND_SUCCESS) != 0)
|
if ((bit & DATA_SEND_SUCCESS) != 0)
|
||||||
{
|
{
|
||||||
|
_attempts = 0;
|
||||||
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
if (memcmp(queue.data.original_sender_mac, _self_mac, 6) == 0)
|
||||||
{
|
{
|
||||||
if (queue.data.message_type == BROADCAST)
|
if (queue.data.message_type == BROADCAST)
|
||||||
@ -482,6 +486,11 @@ static void _processing(void *pvParameter)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (_attempts < _init_config.attempts)
|
||||||
|
{
|
||||||
|
goto SEND;
|
||||||
|
}
|
||||||
|
_attempts = 0;
|
||||||
if (memcmp(queue.data.original_target_mac, _broadcast_mac, 6) != 0)
|
if (memcmp(queue.data.original_target_mac, _broadcast_mac, 6) != 0)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Routing to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X is incorrect.", MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
ESP_LOGI(TAG, "Routing to MAC %02X:%02X:%02X:%02X:%02X:%02X via MAC %02X:%02X:%02X:%02X:%02X:%02X is incorrect.", MAC2STR(queue.data.original_target_mac), MAC2STR(peer->peer_addr));
|
||||||
|
Reference in New Issue
Block a user