2020-12-08 15:12:15 +00:00
|
|
|
//
|
|
|
|
// Created by lukas on 06.12.20.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "GeneralInfoService.h"
|
|
|
|
#include "Pins.h"
|
2020-12-09 19:53:59 +01:00
|
|
|
#include "Timer.h"
|
2020-12-08 15:12:15 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-12-09 19:53:59 +01:00
|
|
|
const uint32_t systime = Timer::getSystemSeconds();
|
|
|
|
|
|
|
|
root["lastpumptime"] = lastPumpTime != 0 ? systime - lastPumpTime : 0;
|
|
|
|
root["lastWaterOutage"] = lastWaterOutage != 0 ? systime - lastWaterOutage : 0;
|
|
|
|
root["lastPumpDuration"] = lastPumpDuration != 0 ? lastPumpDuration : 0;
|
|
|
|
root["runtime"] = systime;
|
2020-12-08 15:12:15 +00:00
|
|
|
|
|
|
|
root["watersensor"] = digitalRead(WasserSensorPin) ? true : false;
|
|
|
|
root["pressuresensor"] = digitalRead(DruckSensorPin) ? true : false;
|
|
|
|
|
|
|
|
root["version"] = VERSION;
|
|
|
|
|
|
|
|
response->setLength();
|
|
|
|
request->send(response);
|
|
|
|
}
|
|
|
|
|
2020-12-09 19:53:59 +01:00
|
|
|
void GeneralInfoService::setlastPumpTime(uint32_t lastPumpTime) {
|
2020-12-08 15:12:15 +00:00
|
|
|
this->lastPumpTime = lastPumpTime;
|
|
|
|
}
|
|
|
|
|
2020-12-09 19:53:59 +01:00
|
|
|
void GeneralInfoService::setlastWaterOutage(uint32_t lastWaterOutage) {
|
2020-12-08 15:12:15 +00:00
|
|
|
this->lastWaterOutage = lastWaterOutage;
|
|
|
|
}
|
|
|
|
|
2020-12-09 19:53:59 +01:00
|
|
|
void GeneralInfoService::setPumpDuration(uint32_t lastPumpDuration) {
|
2020-12-08 15:12:15 +00:00
|
|
|
this->lastPumpDuration = lastPumpDuration;
|
|
|
|
}
|