inventory.cpp
1 #include "routes.h" 2 #include <manager.h> 3 4 #include <ESPAsyncWebServer.h> 5 #include <AsyncJson.h> 6 #include <ArduinoJson.h> 7 8 namespace { 9 10 void handle_get(AsyncWebServerRequest *request) { 11 SensorInventorySnapshot snapshot = {}; 12 sensors::manager::accessInventory(&snapshot); 13 14 AsyncJsonResponse *response = new AsyncJsonResponse(); 15 JsonObject root = response->getRoot().to<JsonObject>(); 16 root["ok"] = true; 17 18 JsonObject data = root["data"].to<JsonObject>(); 19 data["temperature_humidity_count"] = snapshot.temperature_humidity_count; 20 data["soil_probe_count"] = snapshot.soil_probe_count; 21 data["voltage_available"] = snapshot.voltage_available; 22 data["current_available"] = snapshot.current_available; 23 data["co2_available"] = snapshot.carbon_dioxide_available; 24 data["wind_speed_available"] = snapshot.wind_speed_available; 25 data["wind_direction_available"] = snapshot.wind_direction_available; 26 data["solar_radiation_available"] = snapshot.solar_radiation_available; 27 data["barometric_pressure_available"] = snapshot.barometric_pressure_available; 28 29 response->setLength(); 30 request->send(response); 31 } 32 33 } 34 35 void services::http::api::sensors::inventory::registerRoutes(AsyncWebServer &server) { 36 server.on("/api/sensors/inventory", HTTP_GET, handle_get); 37 }