diff options
Diffstat (limited to 'main/cvm_server.c')
| -rw-r--r-- | main/cvm_server.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/main/cvm_server.c b/main/cvm_server.c index 10af956..f3a5ab8 100644 --- a/main/cvm_server.c +++ b/main/cvm_server.c | |||
| @@ -31,6 +31,7 @@ static void publish_announcements_via_ws(esp_tls_t *tls); | |||
| 31 | #define CVM_WS_BUF_SIZE 8192 | 31 | #define CVM_WS_BUF_SIZE 8192 |
| 32 | #define CVM_MAX_RESPONSE_SIZE 4096 | 32 | #define CVM_MAX_RESPONSE_SIZE 4096 |
| 33 | #define CVM_RECONNECT_DELAY_MS 5000 | 33 | #define CVM_RECONNECT_DELAY_MS 5000 |
| 34 | #define CVM_WS_PING_INTERVAL_S 30 | ||
| 34 | 35 | ||
| 35 | static char *parse_ws_text_frame(const uint8_t *buf, int len) | 36 | static char *parse_ws_text_frame(const uint8_t *buf, int len) |
| 36 | { | 37 | { |
| @@ -554,6 +555,7 @@ static void cvm_relay_task(void *arg) | |||
| 554 | return; | 555 | return; |
| 555 | } | 556 | } |
| 556 | 557 | ||
| 558 | int64_t last_ping_time = (int64_t)(xTaskGetTickCount() * portTICK_PERIOD_MS) / 1000; | ||
| 557 | int consecutive_timeouts = 0; | 559 | int consecutive_timeouts = 0; |
| 558 | while (g_running) { | 560 | while (g_running) { |
| 559 | int rlen = esp_tls_conn_read(tls, buf, CVM_WS_BUF_SIZE - 1); | 561 | int rlen = esp_tls_conn_read(tls, buf, CVM_WS_BUF_SIZE - 1); |
| @@ -583,6 +585,13 @@ static void cvm_relay_task(void *arg) | |||
| 583 | } | 585 | } |
| 584 | } | 586 | } |
| 585 | 587 | ||
| 588 | int64_t now = (int64_t)(xTaskGetTickCount() * portTICK_PERIOD_MS) / 1000; | ||
| 589 | if (now - last_ping_time >= CVM_WS_PING_INTERVAL_S) { | ||
| 590 | uint8_t ping[2] = {0x89, 0x00}; | ||
| 591 | esp_tls_conn_write(tls, ping, 2); | ||
| 592 | last_ping_time = now; | ||
| 593 | ESP_LOGD(TAG, "Sent WS keepalive ping"); | ||
| 594 | } | ||
| 586 | } | 595 | } |
| 587 | 596 | ||
| 588 | free(buf); | 597 | free(buf); |