#include "sender_task.h" #include "sampler_task.h" #include "ringbuf.h" #include "protocol.h" #include #include #include "ws.h" extern "C" { #include "freertos/FreeRTOS.h" #include "freertos/task.h" } static uint32_t msg_id = 1; static void sender_task(void *arg) { int data[RINGBUF_SIZE]; while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); // 1 Гц char buf[512]; ringbuf_t *rb = sampler_get_buffer(); ringbuf_copy(rb, data); time_t now = time(NULL); int len = build_telemetry( buf, sizeof(buf), msg_id++, now, 1, // device_id (пока захардкожен) "v", // metric "adc35", // source "raw", // unit data, RINGBUF_SIZE ); if (len > 0) { if (ws_is_connected()) { ws_send(buf); } else { printf("%s\n", buf); // fallback } } else { printf("build_telemetry failed\n"); } } } void sender_task_start() { xTaskCreate( sender_task, "sender", 4096, NULL, 5, NULL ); }