mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-05-05 15:44:18 +00:00
Merge branch 'master' into dev-v2.1.0
This commit is contained in:
@@ -451,6 +451,9 @@ bool AmsConfiguration::getEntsoeConfig(EntsoeConfig& config) {
|
|||||||
EEPROM.begin(EEPROM_SIZE);
|
EEPROM.begin(EEPROM_SIZE);
|
||||||
EEPROM.get(CONFIG_ENTSOE_START, config);
|
EEPROM.get(CONFIG_ENTSOE_START, config);
|
||||||
EEPROM.end();
|
EEPROM.end();
|
||||||
|
if(strlen(config.token) != 0 && strlen(config.token) != 36) {
|
||||||
|
clearEntsoe(config);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ ADC_MODE(ADC_VCC);
|
|||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
#endif
|
#endif
|
||||||
#define WDT_TIMEOUT 10
|
#define WDT_TIMEOUT 30
|
||||||
|
|
||||||
#include "AmsToMqttBridge.h"
|
#include "AmsToMqttBridge.h"
|
||||||
#include "AmsStorage.h"
|
#include "AmsStorage.h"
|
||||||
@@ -139,12 +139,14 @@ void setup() {
|
|||||||
hw.ledBlink(LED_GREEN, 1);
|
hw.ledBlink(LED_GREEN, 1);
|
||||||
hw.ledBlink(LED_BLUE, 1);
|
hw.ledBlink(LED_BLUE, 1);
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
EntsoeConfig entsoe;
|
EntsoeConfig entsoe;
|
||||||
if(config.getEntsoeConfig(entsoe) && strlen(entsoe.token) > 0) {
|
if(config.getEntsoeConfig(entsoe) && strlen(entsoe.token) > 0) {
|
||||||
eapi = new EntsoeApi(&Debug);
|
eapi = new EntsoeApi(&Debug);
|
||||||
eapi->setup(entsoe);
|
eapi->setup(entsoe);
|
||||||
ws.setEntsoeApi(eapi);
|
ws.setEntsoeApi(eapi);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool shared = false;
|
bool shared = false;
|
||||||
config.getMeterConfig(meterConfig);
|
config.getMeterConfig(meterConfig);
|
||||||
@@ -439,6 +441,7 @@ void loop() {
|
|||||||
mqtt->disconnect();
|
mqtt->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
if(eapi != NULL && ntpEnabled) {
|
if(eapi != NULL && ntpEnabled) {
|
||||||
if(eapi->loop() && mqtt != NULL && mqttHandler != NULL && mqtt->connected()) {
|
if(eapi->loop() && mqtt != NULL && mqttHandler != NULL && mqtt->connected()) {
|
||||||
mqttHandler->publishPrices(eapi);
|
mqttHandler->publishPrices(eapi);
|
||||||
@@ -456,10 +459,11 @@ void loop() {
|
|||||||
} else if(eapi != NULL) {
|
} else if(eapi != NULL) {
|
||||||
delete eapi;
|
delete eapi;
|
||||||
eapi = NULL;
|
eapi = NULL;
|
||||||
ws.setEntsoeApi(eapi);
|
ws.setEntsoeApi(NULL);
|
||||||
}
|
}
|
||||||
config.ackEntsoeChange();
|
config.ackEntsoeChange();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ws.loop();
|
ws.loop();
|
||||||
}
|
}
|
||||||
if(mqtt != NULL) { // Run loop regardless, to let MQTT do its work.
|
if(mqtt != NULL) { // Run loop regardless, to let MQTT do its work.
|
||||||
|
|||||||
@@ -471,9 +471,8 @@ double IEC6205675::getNumber(CosemData* item) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CosemTypeLongSigned: {
|
case CosemTypeLongSigned: {
|
||||||
uint16_t u16 = ntohs(item->lu.data); // ntohs only works for uint16 ?
|
int16_t i16 = ntohs(item->ls.data);
|
||||||
int16_t i16 = u16; // Cast to int16 before use?
|
ret = i16;
|
||||||
ret = i16; // Who knows, got to try it all...
|
|
||||||
pos += 3;
|
pos += 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ size_t DnbCurrParser::write(const uint8_t *buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t DnbCurrParser::write(uint8_t byte) {
|
size_t DnbCurrParser::write(uint8_t byte) {
|
||||||
|
if(pos >= 64) pos = 0;
|
||||||
if(pos == 0) {
|
if(pos == 0) {
|
||||||
if(byte == '<') {
|
if(byte == '<') {
|
||||||
buf[pos++] = byte;
|
buf[pos++] = byte;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ char* EntsoeA44Parser::getMeasurementUnit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float EntsoeA44Parser::getPoint(uint8_t position) {
|
float EntsoeA44Parser::getPoint(uint8_t position) {
|
||||||
|
if(position >= 24) return ENTSOE_NO_VALUE;
|
||||||
return points[position];
|
return points[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ size_t EntsoeA44Parser::write(const uint8_t *buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t EntsoeA44Parser::write(uint8_t byte) {
|
size_t EntsoeA44Parser::write(uint8_t byte) {
|
||||||
|
if(pos >= 64) pos = 0;
|
||||||
if(docPos == DOCPOS_CURRENCY) {
|
if(docPos == DOCPOS_CURRENCY) {
|
||||||
buf[pos++] = byte;
|
buf[pos++] = byte;
|
||||||
if(pos == 3) {
|
if(pos == 3) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ EntsoeApi::EntsoeApi(RemoteDebug* Debug) {
|
|||||||
|
|
||||||
client.setInsecure();
|
client.setInsecure();
|
||||||
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||||
|
https.setTimeout(5000);
|
||||||
|
|
||||||
// Entso-E uses CET/CEST
|
// Entso-E uses CET/CEST
|
||||||
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120};
|
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120};
|
||||||
@@ -63,8 +64,10 @@ float EntsoeApi::getValueForHour(time_t cur, int8_t hour) {
|
|||||||
} else {
|
} else {
|
||||||
return ENTSOE_NO_VALUE;
|
return ENTSOE_NO_VALUE;
|
||||||
}
|
}
|
||||||
multiplier *= getCurrencyMultiplier(tomorrow->getCurrency(), config->currency);
|
float mult = getCurrencyMultiplier(tomorrow->getCurrency(), config->currency);
|
||||||
} else if(pos > 0) {
|
if(mult == 0) return ENTSOE_NO_VALUE;
|
||||||
|
multiplier *= mult;
|
||||||
|
} else if(pos >= 0) {
|
||||||
if(today == NULL)
|
if(today == NULL)
|
||||||
return ENTSOE_NO_VALUE;
|
return ENTSOE_NO_VALUE;
|
||||||
value = today->getPoint(pos);
|
value = today->getPoint(pos);
|
||||||
@@ -73,7 +76,9 @@ float EntsoeApi::getValueForHour(time_t cur, int8_t hour) {
|
|||||||
} else {
|
} else {
|
||||||
return ENTSOE_NO_VALUE;
|
return ENTSOE_NO_VALUE;
|
||||||
}
|
}
|
||||||
multiplier *= getCurrencyMultiplier(today->getCurrency(), config->currency);
|
float mult = getCurrencyMultiplier(today->getCurrency(), config->currency);
|
||||||
|
if(mult == 0) return ENTSOE_NO_VALUE;
|
||||||
|
multiplier *= mult;
|
||||||
}
|
}
|
||||||
return value * multiplier;
|
return value * multiplier;
|
||||||
}
|
}
|
||||||
@@ -288,8 +293,12 @@ float EntsoeApi::getCurrencyMultiplier(const char* from, const char* to) {
|
|||||||
if(retrieve(url, &p)) {
|
if(retrieve(url, &p)) {
|
||||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EntsoeApi) got exchange rate %.4f\n", p.getValue());
|
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EntsoeApi) got exchange rate %.4f\n", p.getValue());
|
||||||
currencyMultiplier /= p.getValue();
|
currencyMultiplier /= p.getValue();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EntsoeApi) Resulting currency multiplier: %.4f\n", currencyMultiplier);
|
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EntsoeApi) Resulting currency multiplier: %.4f\n", currencyMultiplier);
|
||||||
lastCurrencyFetch = midnightMillis;
|
lastCurrencyFetch = midnightMillis;
|
||||||
|
|||||||
@@ -791,7 +791,6 @@ void AmsWebServer::dataJson() {
|
|||||||
mqttStatus,
|
mqttStatus,
|
||||||
mqtt == NULL ? 0 : (int) mqtt->lastError(),
|
mqtt == NULL ? 0 : (int) mqtt->lastError(),
|
||||||
price == ENTSOE_NO_VALUE ? "null" : String(price, 2).c_str(),
|
price == ENTSOE_NO_VALUE ? "null" : String(price, 2).c_str(),
|
||||||
time(nullptr),
|
|
||||||
meterState->getMeterType(),
|
meterState->getMeterType(),
|
||||||
meterConfig->distributionSystem,
|
meterConfig->distributionSystem,
|
||||||
ea->getMonthMax(),
|
ea->getMonthMax(),
|
||||||
@@ -801,7 +800,8 @@ void AmsWebServer::dataJson() {
|
|||||||
ea->getUseToday(),
|
ea->getUseToday(),
|
||||||
ea->getCostToday(),
|
ea->getCostToday(),
|
||||||
ea->getUseThisMonth(),
|
ea->getUseThisMonth(),
|
||||||
ea->getCostThisMonth()
|
ea->getCostThisMonth(),
|
||||||
|
(uint32_t) time(nullptr)
|
||||||
);
|
);
|
||||||
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
@@ -1048,7 +1048,6 @@ void AmsWebServer::handleSetup() {
|
|||||||
break;
|
break;
|
||||||
case 200: // ESP32
|
case 200: // ESP32
|
||||||
gpioConfig->hanPin = 16;
|
gpioConfig->hanPin = 16;
|
||||||
gpioConfig->apPin = 4;
|
|
||||||
gpioConfig->ledPin = 2;
|
gpioConfig->ledPin = 2;
|
||||||
gpioConfig->ledInverted = false;
|
gpioConfig->ledInverted = false;
|
||||||
break;
|
break;
|
||||||
@@ -1287,7 +1286,6 @@ void AmsWebServer::handleSave() {
|
|||||||
strcpy(entsoe.currency, server.arg("ecu").c_str());
|
strcpy(entsoe.currency, server.arg("ecu").c_str());
|
||||||
entsoe.multiplier = server.arg("em").toFloat() * 1000;
|
entsoe.multiplier = server.arg("em").toFloat() * 1000;
|
||||||
config->setEntsoeConfig(entsoe);
|
config->setEntsoeConfig(entsoe);
|
||||||
eapi->setup(entsoe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printI("Saving configuration now...");
|
printI("Saving configuration now...");
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
"mm" : %d,
|
"mm" : %d,
|
||||||
"me" : %d,
|
"me" : %d,
|
||||||
"p" : %s,
|
"p" : %s,
|
||||||
"c" : %lu,
|
|
||||||
"mt" : %d,
|
"mt" : %d,
|
||||||
"ds" : %d,
|
"ds" : %d,
|
||||||
"ea" : {
|
"ea" : {
|
||||||
@@ -49,5 +48,6 @@
|
|||||||
"u" : %.2f,
|
"u" : %.2f,
|
||||||
"c" : %.2f
|
"c" : %.2f
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"c" : %lu
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user