diff --git a/src/AmsDataStorage.cpp b/src/AmsDataStorage.cpp index a7f988a9..3ed6dd8b 100644 --- a/src/AmsDataStorage.cpp +++ b/src/AmsDataStorage.cpp @@ -70,9 +70,9 @@ bool AmsDataStorage::update(AmsData* data) { } for(int i = last.Day; i < tm.Day; i++) { - //if(debugger->isActive(RemoteDebug::DEBUG)) { + if(debugger->isActive(RemoteDebug::DEBUG)) { debugger->printf("(AmsDataStorage) Clearing day: %d\n", i); - //} + } setDay(i, 0); } } @@ -97,9 +97,9 @@ bool AmsDataStorage::update(AmsData* data) { int16_t val = (((data->getActiveImportCounter() * 1000) - day.activeImport) - ((data->getActiveExportCounter() * 1000) - day.activeExport)); setHour(tm.Hour, val); - //if(debugger->isActive(RemoteDebug::INFO)) { + if(debugger->isActive(RemoteDebug::INFO)) { debugger->printf("(AmsDataStorage) Usage for hour %d: %d\n", tm.Hour, val); - //} + } day.activeImport = data->getActiveImportCounter() * 1000; day.activeExport = data->getActiveExportCounter() * 1000; @@ -111,9 +111,9 @@ bool AmsDataStorage::update(AmsData* data) { float ipm = im / mins; float epm = ex / mins; - //if(debugger->isActive(RemoteDebug::DEBUG)) { + if(debugger->isActive(RemoteDebug::DEBUG)) { debugger->printf("(AmsDataStorage) Since last day update, minutes: %.1f, import: %d (%.2f/min), export: %d (%.2f/min)\n", mins, im, ipm, ex, epm); - //} + } breakTime(day.lastMeterReadTime, tm); day.lastMeterReadTime = day.lastMeterReadTime - (tm.Minute * 60) - tm.Second; @@ -128,9 +128,9 @@ bool AmsDataStorage::update(AmsData* data) { float val = ((ipm * minutes) - (epm * minutes)); setHour(last.Hour, val); - //if(debugger->isActive(RemoteDebug::INFO)) { + if(debugger->isActive(RemoteDebug::INFO)) { debugger->printf("(AmsDataStorage) Estimated usage for hour %u: %.1f (%lu)\n", last.Hour, val, cur); - //} + } day.activeImport += ipm * minutes; day.activeExport += epm * minutes; @@ -159,9 +159,9 @@ bool AmsDataStorage::update(AmsData* data) { } else if(now - month.lastMeterReadTime < 87000) { int32_t val = (month.activeImport == 0 ? 0 : ((data->getActiveImportCounter() * 1000) - month.activeImport) - ((data->getActiveExportCounter() * 1000) - month.activeExport)); - //if(debugger->isActive(RemoteDebug::INFO)) { + if(debugger->isActive(RemoteDebug::INFO)) { debugger->printf("(AmsDataStorage) Usage for day %d: %d\n", tm.Day, val); - //} + } time_t yesterday = now - 3600; breakTime(yesterday, tm); @@ -177,9 +177,9 @@ bool AmsDataStorage::update(AmsData* data) { float iph = im / hrs; float eph = ex / hrs; - //if(debugger->isActive(RemoteDebug::DEBUG)) { + if(debugger->isActive(RemoteDebug::DEBUG)) { debugger->printf("(AmsDataStorage) Since last month update, hours: %.1f, import: %d (%.2f/hr), export: %d (%.2f/hr)\n", hrs, im, iph, ex, eph); - //} + } if(tz != NULL) { breakTime(tz->toLocal(month.lastMeterReadTime), tm); @@ -207,9 +207,9 @@ bool AmsDataStorage::update(AmsData* data) { float val = ((iph * hours) - (eph * hours)); setDay(last.Day, val); - //if(debugger->isActive(RemoteDebug::INFO)) { + if(debugger->isActive(RemoteDebug::INFO)) { debugger->printf("(AmsDataStorage) Estimated usage for day %u: %.1f (%lu)\n", last.Day, val, cur); - //} + } month.activeImport += iph * hours; month.activeExport += eph * hours; diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index c6447a8c..2cdb04a8 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -456,7 +456,6 @@ void loop() { config.ackEntsoeChange(); } ws.loop(); - readHanPort(); // TODO: Move to bottom } if(mqtt != NULL) { // Run loop regardless, to let MQTT do its work. mqtt->loop(); @@ -483,6 +482,7 @@ void loop() { hc = NULL; } + readHanPort(); delay(1); // Needed for auto modem sleep }