mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-02-27 01:10:31 +00:00
Fixed NPE
This commit is contained in:
@@ -577,6 +577,11 @@ bool AmsDataStorage::isHappy() {
|
||||
}
|
||||
|
||||
bool AmsDataStorage::isDayHappy() {
|
||||
if(tz == NULL) {
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf_P(PSTR("(AmsDataStorage) Timezone is missing\n"));
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t now = time(nullptr);
|
||||
if(now < FirmwareVersion::BuildEpoch) return false;
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
void EnergyAccounting::calcDayCost() {
|
||||
time_t now = time(nullptr);
|
||||
tmElements_t local, utc;
|
||||
if(tz == NULL) return;
|
||||
breakTime(tz->toLocal(now), local);
|
||||
|
||||
if(getPriceForHour(0) != ENTSOE_NO_VALUE) {
|
||||
@@ -205,10 +206,10 @@ float EnergyAccounting::getUseThisHour() {
|
||||
}
|
||||
|
||||
float EnergyAccounting::getUseToday() {
|
||||
if(tz == NULL) return 0.0;
|
||||
float ret = 0.0;
|
||||
time_t now = time(nullptr);
|
||||
if(now < FirmwareVersion::BuildEpoch) return 0.0;
|
||||
if(tz == NULL) return 0.0;
|
||||
tmElements_t utc, local;
|
||||
breakTime(tz->toLocal(now), local);
|
||||
for(uint8_t i = 0; i < currentHour; i++) {
|
||||
@@ -237,6 +238,7 @@ float EnergyAccounting::getProducedThisHour() {
|
||||
}
|
||||
|
||||
float EnergyAccounting::getProducedToday() {
|
||||
if(tz == NULL) return 0.0;
|
||||
float ret = 0.0;
|
||||
time_t now = time(nullptr);
|
||||
if(now < FirmwareVersion::BuildEpoch) return 0.0;
|
||||
|
||||
@@ -387,15 +387,7 @@ void setup() {
|
||||
if(config.hasConfig()) {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) config.print(&Debug);
|
||||
WiFi_connect();
|
||||
|
||||
NtpConfig ntp;
|
||||
if(config.getNtpConfig(ntp)) {
|
||||
tz = resolveTimezone(ntp.timezone);
|
||||
ws.setTimezone(tz);
|
||||
ds.setTimezone(tz);
|
||||
ea.setTimezone(tz);
|
||||
}
|
||||
|
||||
handleNtpChange();
|
||||
ds.load();
|
||||
} else {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
@@ -414,7 +406,6 @@ void setup() {
|
||||
ea.load();
|
||||
ea.setEapi(eapi);
|
||||
ws.setup(&config, &gpioConfig, &meterConfig, &meterState, &ds, &ea);
|
||||
handleNtpChange();
|
||||
|
||||
#if defined(ESP32)
|
||||
esp_task_wdt_init(WDT_TIMEOUT, true);
|
||||
|
||||
Reference in New Issue
Block a user