diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 8a69198..47b517c 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -1065,6 +1065,8 @@ void loop() { // check if secondsToday is larger then secondsSunrise time AND if secondsToday is smaller then the sum of secondsSunrise + seconds of lightHours if( (secondsToday >= secondsSunrise) && (secondsToday <= ( secondsSunrise + (lightHours * 60 * 60) ) )){ // turn on light + + // TODO write a LED control function which takes also takes care of UseLEDrelais analogWrite(PINled, PINled_PWM); } else { @@ -1129,6 +1131,8 @@ void WebHandler() { // switching MOSFETs webserver.on("/switch", HTTP_POST, POSTswitchMOSFET); + // api stuff + webserver.on("/api/sensors", HTTP_GET, APIgetSensors); } @@ -1913,8 +1917,32 @@ void POSTswitchMOSFET() { } } + + +/* + * API section + * + */ + +// return as json all sensor readings +void APIgetSensors() { + JsonDocument jsonSensors; + JsonArray arraySoilmoisture = jsonSensors["soilmoisture"].to(); + arraySoilmoisture.add(getSoilmoisture(1)); + arraySoilmoisture.add(getSoilmoisture(2)); + JsonArray arrayTemperature = jsonSensors["temperature"].to(); + arrayTemperature.add(getTemperature(1)); + arrayTemperature.add(getTemperature(2)); + jsonSensors["humidity"] = getHumidity(); + jsonSensors["chirpLight"] = getLightchirp(); + + String body; + serializeJsonPretty(jsonSensors, body); + webserver.send(200, "text/json", body); + +}