Compare commits

...

8 Commits

Author SHA1 Message Date
Gunnar Skjold
8ee8eee6c4 Fixed laout error on realtime data 2023-04-10 14:14:20 +02:00
Gunnar Skjold
28e13b73e6 Fixed missing HA sensors 2023-04-10 14:08:41 +02:00
Gunnar Skjold
088e5645c7 Increased RX serial buff 2023-04-07 09:00:53 +02:00
Gunnar Skjold
3e3d61912d Serial debugging 2023-04-07 08:39:36 +02:00
Gunnar Skjold
b7854baa6d Some HAN serial port debugging 2023-04-07 08:36:42 +02:00
Gunnar Skjold
68bbfd6527 Load data before restoring from config file 2023-04-05 07:54:59 +02:00
Gunnar Skjold
c1ca3d0c65 Fixed month number in clock 2023-04-03 07:07:44 +02:00
Gunnar Skjold
71cac46470 Config restore loads username into password field 2023-04-03 07:06:18 +02:00
9 changed files with 87 additions and 22 deletions

View File

@@ -219,7 +219,7 @@ bool AmsData::isTwoPhase() {
}
int8_t AmsData::getLastError() {
return lastErrorCount > 3 ? lastError : 0;
return lastErrorCount > 2 ? lastError : 0;
}
void AmsData::setLastError(int8_t lastError) {

View File

@@ -68,7 +68,8 @@ bool EnergyAccounting::update(AmsData* amsData) {
init = true;
}
if(!initPrice && eapi != NULL && getPriceForHour(0) != ENTSOE_NO_VALUE) {
float price = getPriceForHour(0);
if(!initPrice && eapi != NULL && price != ENTSOE_NO_VALUE) {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf("(EnergyAccounting) Initializing prices at %lu\n", (int32_t) now);
calcDayCost();
}
@@ -129,8 +130,7 @@ bool EnergyAccounting::update(AmsData* amsData) {
if(kwhi > 0) {
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(EnergyAccounting) Adding %.4f kWh import\n", kwhi);
use += kwhi;
if(getPriceForHour(0) != ENTSOE_NO_VALUE) {
float price = getPriceForHour(0);
if(price != ENTSOE_NO_VALUE) {
float cost = price * kwhi;
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(EnergyAccounting) and %.4f %s\n", cost / 100.0, eapi->getCurrency());
costHour += cost;
@@ -140,8 +140,7 @@ bool EnergyAccounting::update(AmsData* amsData) {
if(kwhe > 0) {
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(EnergyAccounting) Adding %.4f kWh export\n", kwhe);
produce += kwhe;
if(getPriceForHour(0) != ENTSOE_NO_VALUE) {
float price = getPriceForHour(0);
if(price != ENTSOE_NO_VALUE) {
float income = price * kwhe;
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(EnergyAccounting) and %.4f %s\n", income / 100.0, eapi->getCurrency());
incomeHour += income;

View File

@@ -352,6 +352,7 @@ void HomeAssistantMqttHandler::publishList1Sensors() {
}
void HomeAssistantMqttHandler::publishList2Sensors() {
publishList1Sensors();
if(l2Init) return;
for(uint8_t i = 0; i < List2SensorCount; i++) {
publishSensor(List2Sensors[i]);
@@ -368,6 +369,7 @@ void HomeAssistantMqttHandler::publishList2ExportSensors() {
}
void HomeAssistantMqttHandler::publishList3Sensors() {
publishList2Sensors();
if(l3Init) return;
for(uint8_t i = 0; i < List3SensorCount; i++) {
publishSensor(List3Sensors[i]);
@@ -376,6 +378,7 @@ void HomeAssistantMqttHandler::publishList3Sensors() {
}
void HomeAssistantMqttHandler::publishList3ExportSensors() {
publishList2ExportSensors();
if(l3eInit) return;
for(uint8_t i = 0; i < List3ExportSensorCount; i++) {
publishSensor(List3ExportSensors[i]);
@@ -384,6 +387,7 @@ void HomeAssistantMqttHandler::publishList3ExportSensors() {
}
void HomeAssistantMqttHandler::publishList4Sensors() {
publishList3Sensors();
if(l4Init) return;
for(uint8_t i = 0; i < List4SensorCount; i++) {
publishSensor(List4Sensors[i]);
@@ -392,6 +396,7 @@ void HomeAssistantMqttHandler::publishList4Sensors() {
}
void HomeAssistantMqttHandler::publishList4ExportSensors() {
publishList3ExportSensors();
if(l4eInit) return;
for(uint8_t i = 0; i < List4ExportSensorCount; i++) {
publishSensor(List4ExportSensors[i]);

File diff suppressed because one or more lines are too long

View File

@@ -9,8 +9,8 @@
let hasCost = false;
let cols = 3
$: {
cols = currency ? 3 : 2;
hasCost = data && data.h && (data.h.c || data.d.c || data.m.c || data.h.i || data.d.i || data.m.i);
cols = hasCost ? 3 : 2;
}
</script>

View File

@@ -8,5 +8,5 @@
{#if Math.abs(new Date().getTime()-timestamp.getTime()) < 300000 }
{`${zeropad(timestamp.getDate())}. ${monthnames[timestamp.getMonth()]} ${zeropad(timestamp.getHours())}:${zeropad(timestamp.getMinutes())}`}
{:else}
<span class="{fullTimeColor}">{`${zeropad(timestamp.getDate())}.${zeropad(timestamp.getMonth())}.${timestamp.getFullYear()} ${zeropad(timestamp.getHours())}:${zeropad(timestamp.getMinutes())}`}</span>
<span class="{fullTimeColor}">{`${zeropad(timestamp.getDate())}.${zeropad(timestamp.getMonth()+1)}.${timestamp.getFullYear()} ${zeropad(timestamp.getHours())}:${zeropad(timestamp.getMinutes())}`}</span>
{/if}

View File

@@ -117,6 +117,12 @@ export function hanError(err) {
case -52: return "Decryption failed";
case -53: return "Encryption key invalid";
case 90: return "No HAN data received last 30s";
case 91: return "Serial break";
case 92: return "Serial buffer full";
case 93: return "Serial FIFO overflow";
case 94: return "Serial frame error";
case 95: return "Serial parity error";
case 96: return "RX error";
case 98: return "Exception in code, debugging necessary";
case 99: return "Autodetection failed";
}

View File

@@ -12,6 +12,16 @@
#define METER_SOURCE_MQTT 2
#define METER_SOURCE_ESPNOW 3
#define METER_ERROR_NO_DATA 90
#define METER_ERROR_BREAK 91
#define METER_ERROR_BUFFER 92
#define METER_ERROR_FIFO 93
#define METER_ERROR_FRAME 94
#define METER_ERROR_PARITY 95
#define METER_ERROR_RX 96
#define METER_ERROR_EXCEPTION 98
#define METER_ERROR_AUTODETECT 99
#include <SoftwareSerial.h>
#if defined(ESP8266)

View File

@@ -99,6 +99,7 @@ AmsMqttHandler* mqttHandler = NULL;
Stream *hanSerial;
SoftwareSerial *swSerial = NULL;
HardwareSerial *hwSerial = NULL;
GpioConfig gpioConfig;
MeterConfig meterConfig;
@@ -410,6 +411,21 @@ void loop() {
errorBlink();
}
if(hwSerial != NULL) {
#if defined ESP8266
if(hwSerial->hasRxError()) {
meterState.setLastError(METER_ERROR_RX);
}
if(hwSerial->hasOverrun()) {
meterState.setLastError(METER_ERROR_BUFFER);
}
#endif
} else if(swSerial != NULL) {
if(swSerial->overflow()) {
meterState.setLastError(METER_ERROR_BUFFER);
}
}
// Only do normal stuff if we're not booted as AP
if (WiFi.getMode() != WIFI_AP) {
if (WiFi.status() != WL_CONNECTED) {
@@ -600,7 +616,7 @@ void loop() {
}
} catch(const std::exception& e) {
debugE("Exception in readHanPort (%s)", e.what());
meterState.setLastError(98);
meterState.setLastError(METER_ERROR_EXCEPTION);
}
try {
if(meterState.getListType() == 0) {
@@ -623,7 +639,7 @@ void loop() {
}
} catch(const std::exception& e) {
debugE("Exception in meter autodetect (%s)", e.what());
meterState.setLastError(99);
meterState.setLastError(METER_ERROR_AUTODETECT);
}
delay(1); // Needed for auto modem sleep
@@ -634,6 +650,28 @@ void loop() {
#endif
}
void rxerr(int err) {
if(err == 0) return;
switch(err) {
case 1:
debugE("Serial break error");
break;
case 2:
debugE("Serial buffer full");
break;
case 3:
debugE("Serial FIFO overflow");
break;
case 4:
debugE("Serial frame error");
break;
case 5:
debugE("Serial parity error");
break;
}
meterState.setLastError(90+err);
}
void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal, bool invert) {
uint8_t pin = gpioConfig.hanPin;
@@ -656,7 +694,6 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
break;
}
HardwareSerial *hwSerial = NULL;
if(pin == 3 || pin == 113) {
hwSerial = &Serial;
}
@@ -721,7 +758,12 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
}
#endif
hwSerial->setRxBufferSize(768);
#if defined(ESP32)
hwSerial->onReceiveError(rxerr);
#endif
hanSerial = hwSerial;
swSerial = NULL;
} else {
debugD("Software serial");
Serial.flush();
@@ -753,6 +795,7 @@ void setupHanPort(GpioConfig& gpioConfig, uint32_t baud, uint8_t parityOrdinal,
Serial.end();
Serial.begin(115200);
hwSerial = NULL;
}
// The library automatically sets the pullup in Serial.begin()
@@ -776,7 +819,7 @@ void errorBlink() {
if(lastErrorBlink - meterState.getLastUpdateMillis() > 30000) {
debugW("No HAN data received last 30s, single blink");
hw.ledBlink(LED_RED, 1); // If no message received from AMS in 30 sec, blink once
if(meterState.getLastError() == 0) meterState.setLastError(90);
if(meterState.getLastError() == 0) meterState.setLastError(METER_ERROR_NO_DATA);
return;
}
break;
@@ -1521,6 +1564,8 @@ void configFileParse() {
bool sEa = false;
bool sDs = false;
ds.load();
SystemConfig sys;
WiFiConfig wifi;
MqttConfig mqtt;
@@ -1607,7 +1652,7 @@ void configFileParse() {
strcpy(web.username, buf+12);
} else if(strncmp_P(buf, PSTR("webPassword "), 12) == 0) {
if(!lWeb) { config.getWebConfig(web); lWeb = true; };
strcpy(web.username, buf+12);
strcpy(web.password, buf+12);
} else if(strncmp_P(buf, PSTR("meterBaud "), 10) == 0) {
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
meter.baud = String(buf+10).toInt();