First implementation of energy accounting

This commit is contained in:
Gunnar Skjold
2022-01-21 17:37:23 +01:00
parent e4d4753181
commit a72f02a779
11 changed files with 336 additions and 14 deletions

View File

@@ -23,6 +23,7 @@ ADC_MODE(ADC_VCC);
#include "AmsToMqttBridge.h"
#include "AmsStorage.h"
#include "AmsDataStorage.h"
#include "EnergyAccounting.h"
#include <MQTT.h>
#include <DNSServer.h>
#include <lwip/apps/sntp.h>
@@ -80,6 +81,7 @@ AmsData meterState;
bool ntpEnabled = false;
AmsDataStorage ds(&Debug);
EnergyAccounting ea(&Debug);
uint8_t wifiReconnectCount = 0;
@@ -309,7 +311,8 @@ void setup() {
swapWifiMode();
}
ws.setup(&config, &gpioConfig, &meterConfig, &meterState, &ds);
ea.setup(&ds, eapi);
ws.setup(&config, &gpioConfig, &meterConfig, &meterState, &ds, &ea);
#if defined(ESP32)
esp_task_wdt_init(WDT_TIMEOUT, true);
@@ -872,6 +875,10 @@ bool readHanPort() {
debugI("Saving day plot");
ds.save();
}
if(ea.update(&data)) {
debugI("Saving energy accounting");
ea.save();
}
}
delay(1);
return true;