// // Created by lukas on 19.12.20. // #include #include "HeatingInfoService.h" #include "Timer.h" HeatingInfoService::HeatingInfoService(AsyncWebServer *server) : hum(-1), temp(-1), lastheating(0), lastheatend(0) { server->on(HEATINGINFO_SERVICE_PATH, HTTP_GET, std::bind(&HeatingInfoService::reply, this, std::placeholders::_1)); } void HeatingInfoService::reply(AsyncWebServerRequest *request) { AsyncJsonResponse *response = new AsyncJsonResponse(false, MAX_FEATURES_SIZE); JsonObject root = response->getRoot(); root["temp"] = temp; root["hum"] = hum; const uint32_t systime = Timer::getSystemSeconds(); root["lastheating"] = lastheating != 0 ? systime - lastheating : 0; // if lastheating == 0 => there was no cycle upon now // if lastheatend == 0 => heating is currently active root["lastheatduration"] = lastheating == 0 ? 0 : lastheatend == 0 ? -1 : lastheatend - lastheating; response->setLength(); request->send(response); } void HeatingInfoService::setSensorData(float hum, float temp) { this->hum = hum; this->temp = temp; } void HeatingInfoService::setLastHeatingStarttime(unsigned long time) { this->lastheating = time; } void HeatingInfoService::setLastHetingEndtime(unsigned long time) { this->lastheatend = time; }