49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
|
//
|
||
|
// Created by lukas on 06.12.20.
|
||
|
//
|
||
|
|
||
|
#include "GeneralInfoService.h"
|
||
|
#include "Pins.h"
|
||
|
|
||
|
GeneralInfoService::GeneralInfoService(AsyncWebServer *server, float *lasthum, float *lasttemp) :
|
||
|
hum(lasthum),
|
||
|
temp(lasttemp),
|
||
|
lastPumpTime(0),
|
||
|
lastWaterOutage(0),
|
||
|
lastPumpDuration(0) {
|
||
|
server->on(GENERALINFO_SERVICE_PATH, HTTP_GET, std::bind(&GeneralInfoService::reply, this, std::placeholders::_1));
|
||
|
}
|
||
|
|
||
|
void GeneralInfoService::reply(AsyncWebServerRequest *request) {
|
||
|
AsyncJsonResponse *response = new AsyncJsonResponse(false, MAX_FEATURES_SIZE);
|
||
|
JsonObject root = response->getRoot();
|
||
|
|
||
|
root["temp"] = *temp;
|
||
|
root["hum"] = *hum;
|
||
|
|
||
|
root["lastpumptime"] = lastPumpTime != 0 ? (millis() - lastPumpTime) / 1000 : 0;
|
||
|
root["lastWaterOutage"] = lastWaterOutage != 0 ? (millis() - lastWaterOutage) / 1000 : 0;
|
||
|
root["lastPumpDuration"] = lastPumpDuration != 0 ? lastPumpDuration / 1000 : 0;
|
||
|
root["runtime"] = millis() / 1000;
|
||
|
|
||
|
root["watersensor"] = digitalRead(WasserSensorPin) ? true : false;
|
||
|
root["pressuresensor"] = digitalRead(DruckSensorPin) ? true : false;
|
||
|
|
||
|
root["version"] = VERSION;
|
||
|
|
||
|
response->setLength();
|
||
|
request->send(response);
|
||
|
}
|
||
|
|
||
|
void GeneralInfoService::setlastPumpTime(unsigned long lastPumpTime) {
|
||
|
this->lastPumpTime = lastPumpTime;
|
||
|
}
|
||
|
|
||
|
void GeneralInfoService::setlastWaterOutage(unsigned long lastWaterOutage) {
|
||
|
this->lastWaterOutage = lastWaterOutage;
|
||
|
}
|
||
|
|
||
|
void GeneralInfoService::setPumpDuration(unsigned long lastPumpDuration) {
|
||
|
this->lastPumpDuration = lastPumpDuration;
|
||
|
}
|