firmware wip - add simple json /api/debug which returns all values from eeprom and sensors

This commit is contained in:
Marcus 2024-05-10 23:15:12 +02:00
parent b08900a394
commit 7a939205a8

View file

@ -967,7 +967,75 @@ void APIgetSensors() {
} }
void APIgetDebug() {
JsonDocument jsonDebug;
// WiFi
JsonObject objWiFi = jsonDebug.add<JsonObject>();
objWiFi["ssid"] = WIFIssid;
objWiFi["dhcp"] = WIFIuseDHCP;
objWiFi["ip"] = WiFi.localIP().toString();
objWiFi["netmask"] = WiFi.subnetMask().toString();
objWiFi["gateway"] = WiFi.gatewayIP().toString();
objWiFi["dns"] = WiFi.dnsIP().toString();
// System
JsonObject objSystem = jsonDebug.add<JsonObject>();
objSystem["UseFan"] = UseFan;
objSystem["UsePump"] = UsePump;
objSystem["UseLEDrelais"] = UseLEDrelais;
objSystem["UseFANrelais"] = UseFANrelais;
objSystem["PumpOnTime"] = PumpOnTime;
objSystem["MoistureSensor_Type"] = MoistureSensor_Type;
objSystem["SoilmoistureLow"] = SoilmoistureLow;
objSystem["TemperatureSensor_Type"] = TemperatureSensor_Type;
objSystem["NtpOffset"] = NtpOffset;
objSystem["MaintenanceDuration"] = MaintenanceDuration;
// Grow
JsonObject objGrow = jsonDebug.add<JsonObject>();
objSystem["GrowName"] = GrowName;
objSystem["GrowStart"] = GrowStart;
objSystem["GrowStartDate"] = returnStrDateFromEpoch(GrowStart);
objSystem["DaysVeg"] = DaysVeg;
objSystem["DaysBloom"] = DaysBloom;
objSystem["LighthoursVeg"] = LighthoursVeg;
objSystem["LighthoursBloom"] = LighthoursBloom;
objSystem["SunriseHour"] = SunriseHour;
objSystem["SunriseMinute"] = SunriseMinute;
objSystem["SunFade"] = SunFade;
objSystem["SunFadeDuration"] = SunFadeDuration;
objSystem["PinLEDPWM"] = PinLEDPWM;
objSystem["PinFANPWM"] = PinFANPWM;
objSystem["DayOfGrow"] = DayOfGrow;
// Sensors
JsonObject objSensors = jsonDebug["sensors"].add<JsonObject>();
// Chirp
JsonObject objSensorsChirp = jsonDebug["sensors"]["chirp"].add<JsonObject>();
objSensorsChirp["temperature"] = getTemperature(2);
objSensorsChirp["soilmoisture"] = getSoilmoisture(2);
objSensorsChirp["light"] = getLightchirp();
// DHT11/22
JsonObject objSensorsDht = jsonDebug["sensors"]["dht"].add<JsonObject>();
objSensorsDht["temperature"] = getTemperature(1);
objSensorsDht["humidity"] = getHumidity();
// Analog
JsonObject objSensorsAnalog = jsonDebug["sensors"]["analog"].add<JsonObject>();
objSensorsAnalog["soilmoisture"] = getSoilmoisture(1);
objSensorsAnalog["waterlevel"] = getWaterlevel();
String body;
serializeJsonPretty(jsonDebug, body);
webserver.send(200, "text/json", body);
}
/* /*
@ -1024,7 +1092,7 @@ void WebHandler() {
// api stuff // api stuff
webserver.on("/api/sensors", HTTP_GET, APIgetSensors); webserver.on("/api/sensors", HTTP_GET, APIgetSensors);
webserver.on("/api/debug", HTTP_GET, APIgetDebug);
// gauge meter stuff // gauge meter stuff
webserver.on("/gauge.css", HTTP_GET, WEBgaugeCss); webserver.on("/gauge.css", HTTP_GET, WEBgaugeCss);