// Wi-Fi LED drivers (the cpp led-driver): found by mDNS (_http._tcp, TXT app=led-strip) and driven // through its JSON API over a WebSocket (/ws). A device's id is its hostname, 12 characters or fewer. #pragma once #include #include "cJSON.h" #define WIFI_DRV_ID_MAX 12 #define WIFI_DRV_PING_MAX 16 // most Wi-Fi drivers in one ping // Start the send queue and sender task. Safe to call more than once. void wifi_drv_init(void); // Board only: browse mDNS every 30 s and add each new led-strip driver as a wifi device. Needs mdns up. void wifi_drv_start_discovery(void); // True while the driver's WebSocket is open and its last request was answered bool wifi_drv_connected(const char *id); // Queue POST path with body (a JSON object, freed here) to the driver id. Never blocks; drops when full. void wifi_drv_post(const char *id, const char *path, cJSON *body); // A driver preset body (/api/pattern fields) from a stored or pushed preset; NULL if not an object cJSON *wifi_drv_preset_body(const cJSON *preset); // Identify a Wi-Fi driver: red blink at 10 Hz (brightness 128) for 2 s, then off void wifi_drv_identify(const char *id); // One Wi-Fi driver's answer to a ping: its id and round trip in ms (-1 when it did not answer) typedef struct { char id[WIFI_DRV_ID_MAX + 1]; int rtt_ms; } wifi_drv_ping_t; // Ping every Wi-Fi driver (GET /api/status over its link) and wait up to timeout_ms for the answers. // Copies up to max results into out and returns how many; returns 0 when there are no drivers. int wifi_drv_ping_all(int timeout_ms, wifi_drv_ping_t out[], int max);