Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,20 @@ void db_send_to_all_udp_clients(const uint8_t *data, uint data_length) {
if (sent != data_length) {
int err = errno;
char *client_ip = inet_ntoa(((struct sockaddr_in *)&udp_conn_list->db_udp_clients[i].udp_client)->sin_addr);
ESP_LOGE(TAG, "UDP - Error sending (%i/%i) to %s because of %s", sent, data_length, client_ip, strerror(err));
udp_conn_list->db_udp_clients[i].send_fail_count++;
if (udp_conn_list->db_udp_clients[i].send_fail_count >= 5) {
ESP_LOGW(TAG, "UDP - Removing unreachable client %s after repeated send failures (last errno: %d)",
client_ip, err);
for (int j = i; j < udp_conn_list->size - 1; j++) {
udp_conn_list->db_udp_clients[j] = udp_conn_list->db_udp_clients[j + 1];
}
udp_conn_list->size--;
i--;
} else {
ESP_LOGE(TAG, "UDP - Error sending (%i/%i) to %s because of %s", sent, data_length, client_ip, strerror(err));
}
} else {
udp_conn_list->db_udp_clients[i].send_fail_count = 0;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions main/db_esp32_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
struct db_udp_client_t {
uint8_t mac[6]; // MAC address of connected client
struct sockaddr_in udp_client; // socket address (IP & PORT) of connected client
uint8_t send_fail_count; // consecutive send failures; client removed when exceeds threshold
};

typedef struct udp_conn_list_s {
Expand Down
Loading