From eea17822800b9c5e87de267f829c9e1de849f82f Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Tue, 2 May 2023 10:20:54 +0200 Subject: [PATCH] Fixed segfault when enabling verbose debug with fixed price --- lib/EnergyAccounting/include/EnergyAccounting.h | 3 ++- lib/EnergyAccounting/src/EnergyAccounting.cpp | 7 ++++--- src/AmsToMqttBridge.ino | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/EnergyAccounting/include/EnergyAccounting.h b/lib/EnergyAccounting/include/EnergyAccounting.h index 98e40316..eb810352 100644 --- a/lib/EnergyAccounting/include/EnergyAccounting.h +++ b/lib/EnergyAccounting/include/EnergyAccounting.h @@ -81,7 +81,7 @@ public: EnergyAccountingData getData(); void setData(EnergyAccountingData&); - void setFixedPrice(float price); + void setFixedPrice(float price, String currency); float getPriceForHour(uint8_t h); private: @@ -97,6 +97,7 @@ private: float produce = 0, incomeHour = 0, incomeDay = 0; EnergyAccountingData data = { 0, 0, 0, 0, 0, 0 }; float fixedPrice = 0; + String currency = ""; void calcDayCost(); bool updateMax(uint16_t val, uint8_t day); diff --git a/lib/EnergyAccounting/src/EnergyAccounting.cpp b/lib/EnergyAccounting/src/EnergyAccounting.cpp index 072fece2..3088bc97 100644 --- a/lib/EnergyAccounting/src/EnergyAccounting.cpp +++ b/lib/EnergyAccounting/src/EnergyAccounting.cpp @@ -132,7 +132,7 @@ bool EnergyAccounting::update(AmsData* amsData) { use += kwhi; if(price != ENTSOE_NO_VALUE) { float cost = price * kwhi; - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf_P(PSTR("(EnergyAccounting) and %.4f %s\n"), cost / 100.0, eapi->getCurrency()); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf_P(PSTR("(EnergyAccounting) and %.4f %s\n"), cost / 100.0, currency.c_str()); costHour += cost; costDay += cost; } @@ -142,7 +142,7 @@ bool EnergyAccounting::update(AmsData* amsData) { produce += kwhe; if(price != ENTSOE_NO_VALUE) { float income = price * kwhe; - if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf_P(PSTR("(EnergyAccounting) and %.4f %s\n"), income / 100.0, eapi->getCurrency()); + if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf_P(PSTR("(EnergyAccounting) and %.4f %s\n"), income / 100.0, currency.c_str()); incomeHour += income; incomeDay += income; } @@ -499,8 +499,9 @@ bool EnergyAccounting::updateMax(uint16_t val, uint8_t day) { return false; } -void EnergyAccounting::setFixedPrice(float price) { +void EnergyAccounting::setFixedPrice(float price, String currency) { this->fixedPrice = price; + this->currency = currency; } float EnergyAccounting::getPriceForHour(uint8_t h) { diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 8fa8e396..1f352e93 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -186,7 +186,7 @@ void setup() { ws.setEntsoeApi(eapi); } ws.setPriceSettings(entsoe.area, entsoe.currency); - ea.setFixedPrice(entsoe.fixedPrice / 1000.0); + ea.setFixedPrice(entsoe.fixedPrice / 1000.0, entsoe.currency); bool shared = false; config.getMeterConfig(meterConfig); Serial.flush(); @@ -655,7 +655,7 @@ void handlePriceApi(unsigned long now) { } ws.setPriceSettings(entsoe.area, entsoe.currency); config.ackEntsoeChange(); - ea.setFixedPrice(entsoe.fixedPrice / 1000.0); + ea.setFixedPrice(entsoe.fixedPrice / 1000.0, entsoe.currency); } }