// File: include/net_influx.h (oder wo dein Header liegt) #pragma once #include #include #include #include "freertos/FreeRTOS.h" #include "esp_err.h" typedef enum { NET_INFLUX_F_FLOAT, NET_INFLUX_F_INT, NET_INFLUX_F_UINT, NET_INFLUX_F_BOOL, NET_INFLUX_F_STRING, } net_influx_field_type_t; typedef struct { const char* key; // field key net_influx_field_type_t type; int precision; // nur für FLOAT (z.B. 1,3). sonst ignoriert union { double f; int64_t i; uint64_t u; bool b; const char* s; } v; } net_influx_field_t; typedef struct { const char* measurement; // z.B. "air" const char* tags; // z.B. "device=xyz,location=lab" (optional, kann NULL sein) uint64_t ts_ms; // 0 => acquisition time aligned to the server HTTP Date (async API) const net_influx_field_t* fields; size_t num_fields; } net_influx_point_t; typedef struct { // Task/Queue uint16_t queue_len; // Standard 32 uint32_t task_stack; // Standard 8192 UBaseType_t task_prio; // z.B. 5 // Init/Retry/Backoff uint32_t init_retry_ms; // z.B. 1000 uint32_t backoff_start_ms; // z.B. 2000 uint32_t backoff_max_ms; // z.B. 300000 uint8_t fails_before_reinit; // z.B. 5 // Influx init const char* ca_cert_pem_opt; // optional int http_timeout_ms; // z.B. 3000 } net_influx_runtime_cfg_t; // Bestehende Funktionen bleiben: typedef struct { const char* url_base; const char* org; const char* bucket; const char* token; bool use_tls; const char* ca_cert_pem; int http_timeout_ms; } net_influx_cfg_t; esp_err_t net_influx_init(const net_influx_cfg_t* cfg); esp_err_t net_influx_init_from_nvs(const char* ca_cert_pem_opt, int timeout_ms); // NEU: esp_err_t net_influx_start(const net_influx_runtime_cfg_t* rt); void net_influx_stop(void); // Asynchron: serialisiert den Punkt sofort in eine feste RAM-Warteschlange. // 1-Hz-Werte werden bis zu 10 Punkte / 10 s gesammelt, mit eigenen Zeitstempeln. // Ohne gültige Serverzeit werden sichere Einzelpunkt-Schreibvorgänge verwendet. // Rückgabe: // - ESP_OK: queued // - ESP_ERR_NO_MEM / ESP_ERR_INVALID_ARG / ESP_FAIL: sonst esp_err_t net_influx_submit_point(const net_influx_point_t* p); // Optional (falls du synchron brauchst, bleibt deine alte API nutzbar): esp_err_t net_influx_write_fields(const char* measurement, const char* tags, uint64_t ts_ms, const char* fields_fmt, ...);