基于ESP-IDF4.1
#include <stdio.h> #include "esp_wifi.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" #include "protocol_examples_common.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/event_groups.h" #include "esp_log.h" #include "esp_websocket_client.h" #include "esp_event.h" #define NO_DATA_TIMEOUT_SEC 10 static const char *TAG = "WEBSOCKET"; static TimerHandle_t shutdown_signal_timer; static SemaphoreHandle_t shutdown_sema; static void shutdown_signaler(TimerHandle_t xTimer) { ESP_LOGI(TAG, "No data received for %d seconds, signaling shutdown", NO_DATA_TIMEOUT_SEC); //释放信号量 xSemaphoreGive(shutdown_sema); } #if CONFIG_WEBSOCKET_URI_FROM_STDIN static void get_string(char *line, size_t size) { int count = 0; while (count < size) { int c = fgetc(stdin); if (c == ' ') { line[count] = '