Fix error: httpd_txrx: httpd_sock_err: error in send : 104
Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
@@ -45,54 +45,42 @@ static void status_task(void *arg)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (xQueueReceive(status_queue, &msg, PING_INTERVAL)) {
|
if (xQueueReceive(status_queue, &msg, PING_INTERVAL)) {
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
|
||||||
int fd = client_fd;
|
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
|
|
||||||
if (fd <= 0) {
|
|
||||||
cJSON_Delete(msg.data);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *json_string = cJSON_Print(msg.data);
|
char *json_string = cJSON_Print(msg.data);
|
||||||
httpd_ws_frame_t ws_pkt;
|
|
||||||
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
|
|
||||||
ws_pkt.payload = (uint8_t *)json_string;
|
|
||||||
ws_pkt.len = strlen(json_string);
|
|
||||||
ws_pkt.type = HTTPD_WS_TYPE_TEXT;
|
|
||||||
esp_err_t err = httpd_ws_send_frame_async(server, fd, &ws_pkt);
|
|
||||||
free(json_string);
|
|
||||||
cJSON_Delete(msg.data);
|
cJSON_Delete(msg.data);
|
||||||
|
|
||||||
if (err != ESP_OK)
|
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
||||||
{
|
int fd = client_fd;
|
||||||
ESP_LOGW(TAG, "status_task: async send failed for fd %d, error: %s", fd, esp_err_to_name(err));
|
if (fd > 0) {
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
httpd_ws_frame_t ws_pkt;
|
||||||
if (client_fd == fd) {
|
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
|
||||||
|
ws_pkt.payload = (uint8_t *)json_string;
|
||||||
|
ws_pkt.len = strlen(json_string);
|
||||||
|
ws_pkt.type = HTTPD_WS_TYPE_TEXT;
|
||||||
|
esp_err_t err = httpd_ws_send_frame_async(server, fd, &ws_pkt);
|
||||||
|
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "status_task: async send failed for fd %d, error: %s", fd, esp_err_to_name(err));
|
||||||
client_fd = -1;
|
client_fd = -1;
|
||||||
}
|
}
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive(client_fd_mutex);
|
||||||
|
free(json_string);
|
||||||
} else {
|
} else {
|
||||||
// Queue receive timed out, send a PING to keep connection alive
|
// Queue receive timed out, send a PING to keep connection alive
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
||||||
int fd = client_fd;
|
int fd = client_fd;
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
|
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
httpd_ws_frame_t ping_pkt;
|
httpd_ws_frame_t ping_pkt;
|
||||||
memset(&ping_pkt, 0, sizeof(httpd_ws_frame_t));
|
memset(&ping_pkt, 0, sizeof(httpd_ws_frame_t));
|
||||||
ping_pkt.type = HTTPD_WS_TYPE_PING;
|
ping_pkt.type = HTTPD_WS_TYPE_PING;
|
||||||
ping_pkt.final = true;
|
ping_pkt.final = true;
|
||||||
if (httpd_ws_send_frame_async(server, fd, &ping_pkt) != ESP_OK) {
|
esp_err_t err = httpd_ws_send_frame_async(server, fd, &ping_pkt);
|
||||||
ESP_LOGW(TAG, "Failed to send PING frame, closing connection for fd %d", fd);
|
if (err != ESP_OK) {
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
ESP_LOGW(TAG, "Failed to send PING frame, closing connection for fd %d, error: %s", fd, esp_err_to_name(err));
|
||||||
if (client_fd == fd) {
|
client_fd = -1;
|
||||||
client_fd = -1;
|
|
||||||
}
|
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive(client_fd_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,8 +94,6 @@ static void ws_sender_task(void *arg)
|
|||||||
if (xQueueReceive(uart_to_ws_queue, &msg, portMAX_DELAY)) {
|
if (xQueueReceive(uart_to_ws_queue, &msg, portMAX_DELAY)) {
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
||||||
int fd = client_fd;
|
int fd = client_fd;
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
|
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
httpd_ws_frame_t ws_pkt = {0};
|
httpd_ws_frame_t ws_pkt = {0};
|
||||||
ws_pkt.payload = msg.data;
|
ws_pkt.payload = msg.data;
|
||||||
@@ -117,13 +103,10 @@ static void ws_sender_task(void *arg)
|
|||||||
esp_err_t err = httpd_ws_send_frame_async(server, fd, &ws_pkt);
|
esp_err_t err = httpd_ws_send_frame_async(server, fd, &ws_pkt);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGW(TAG, "ws_sender_task: async send failed for fd %d, error: %s", fd, esp_err_to_name(err));
|
ESP_LOGW(TAG, "ws_sender_task: async send failed for fd %d, error: %s", fd, esp_err_to_name(err));
|
||||||
xSemaphoreTake(client_fd_mutex, portMAX_DELAY);
|
client_fd = -1;
|
||||||
if (client_fd == fd) {
|
|
||||||
client_fd = -1;
|
|
||||||
}
|
|
||||||
xSemaphoreGive(client_fd_mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive(client_fd_mutex);
|
||||||
free(msg.data);
|
free(msg.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,4 +261,4 @@ void push_data_to_ws(cJSON *data)
|
|||||||
esp_err_t change_baud_rate(int baud_rate)
|
esp_err_t change_baud_rate(int baud_rate)
|
||||||
{
|
{
|
||||||
return uart_set_baudrate(UART_NUM, baud_rate);
|
return uart_set_baudrate(UART_NUM, baud_rate);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user