diff --git a/src/AmsDataStorage.cpp b/src/AmsDataStorage.cpp index f6652496..e274ffb0 100644 --- a/src/AmsDataStorage.cpp +++ b/src/AmsDataStorage.cpp @@ -90,7 +90,7 @@ bool AmsDataStorage::update(AmsData* data) { return true; } - if(data->getListType() != 3) return false; + if(data->getListType() < 3) return false; else if(ltz.Minute > 1) return false; // Update day plot diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 8c741158..c77be649 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -865,7 +865,7 @@ bool readHanPort() { hw.ledBlink(LED_INTERNAL, 1); if(mqttEnabled && mqttHandler != NULL && mqtt != NULL) { if(mqttHandler->publish(&data, &meterState, &ea)) { - if(data.getListType() == 3 && eapi != NULL) { + if(data.getListType() >= 3 && eapi != NULL) { mqttHandler->publishPrices(eapi); } if(data.getListType() >= 2) { @@ -879,7 +879,7 @@ bool readHanPort() { } time_t now = time(nullptr); - if(now < EPOCH_2021_01_01 && data.getListType() == 3) { + if(now < EPOCH_2021_01_01 && data.getListType() >= 3) { if(data.getMeterTimestamp() > EPOCH_2021_01_01) { debugI("Using timestamp from meter"); now = data.getMeterTimestamp(); diff --git a/src/IEC6205675.cpp b/src/IEC6205675.cpp index 4cdee6ac..6eb8e177 100644 --- a/src/IEC6205675.cpp +++ b/src/IEC6205675.cpp @@ -272,18 +272,22 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, uint8_t distribution val = getNumber(AMS_OBIS_POWER_FACTOR, sizeof(AMS_OBIS_POWER_FACTOR), ((char *) (d))); if(val != NOVALUE) { + listType = 4; powerFactor = val; } val = getNumber(AMS_OBIS_POWER_FACTOR_L1, sizeof(AMS_OBIS_POWER_FACTOR_L1), ((char *) (d))); if(val != NOVALUE) { + listType = 4; l1PowerFactor = val; } val = getNumber(AMS_OBIS_POWER_FACTOR_L2, sizeof(AMS_OBIS_POWER_FACTOR_L2), ((char *) (d))); if(val != NOVALUE) { + listType = 4; l2PowerFactor = val; } val = getNumber(AMS_OBIS_POWER_FACTOR_L3, sizeof(AMS_OBIS_POWER_FACTOR_L3), ((char *) (d))); if(val != NOVALUE) { + listType = 4; l3PowerFactor = val; } diff --git a/src/mqtt/JsonMqttHandler.cpp b/src/mqtt/JsonMqttHandler.cpp index e2bf8989..53ca6562 100644 --- a/src/mqtt/JsonMqttHandler.cpp +++ b/src/mqtt/JsonMqttHandler.cpp @@ -4,7 +4,7 @@ #include "web/root/json1_json.h" #include "web/root/json2_json.h" #include "web/root/json3_json.h" -#include "web/root/json3pf_json.h" +#include "web/root/json4_json.h" #include "web/root/jsonsys_json.h" #include "web/root/jsonprices_json.h" @@ -55,75 +55,73 @@ bool JsonMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccou ); return mqtt->publish(topic, json); } else if(data->getListType() == 3) { - if(data->getPowerFactor() == 0) { - char json[512]; - snprintf_P(json, sizeof(json), JSON3_JSON, - WiFi.macAddress().c_str(), - clientId.c_str(), - (uint32_t) (millis64()/1000), - data->getPackageTimestamp(), - hw->getVcc(), - hw->getWifiRssi(), - hw->getTemperature(), - data->getListId().c_str(), - data->getMeterId().c_str(), - data->getMeterModel().c_str(), - data->getActiveImportPower(), - data->getReactiveImportPower(), - data->getActiveExportPower(), - data->getReactiveExportPower(), - data->getL1Current(), - data->getL2Current(), - data->getL3Current(), - data->getL1Voltage(), - data->getL2Voltage(), - data->getL3Voltage(), - data->getActiveImportCounter(), - data->getActiveExportCounter(), - data->getReactiveImportCounter(), - data->getReactiveExportCounter(), - data->getMeterTimestamp(), - ea->getUseThisHour(), - ea->getCurrentThreshold() - ); - return mqtt->publish(topic, json); - } else { - char json[768]; - snprintf_P(json, sizeof(json), JSON3PF_JSON, - WiFi.macAddress().c_str(), - clientId.c_str(), - (uint32_t) (millis64()/1000), - data->getPackageTimestamp(), - hw->getVcc(), - hw->getWifiRssi(), - hw->getTemperature(), - data->getListId().c_str(), - data->getMeterId().c_str(), - data->getMeterModel().c_str(), - data->getActiveImportPower(), - data->getReactiveImportPower(), - data->getActiveExportPower(), - data->getReactiveExportPower(), - data->getL1Current(), - data->getL2Current(), - data->getL3Current(), - data->getL1Voltage(), - data->getL2Voltage(), - data->getL3Voltage(), - data->getPowerFactor(), - data->getL1PowerFactor(), - data->getL2PowerFactor(), - data->getL3PowerFactor(), - data->getActiveImportCounter(), - data->getActiveExportCounter(), - data->getReactiveImportCounter(), - data->getReactiveExportCounter(), - data->getMeterTimestamp(), - ea->getUseThisHour(), - ea->getCurrentThreshold() - ); - return mqtt->publish(topic, json); - } + char json[512]; + snprintf_P(json, sizeof(json), JSON3_JSON, + WiFi.macAddress().c_str(), + clientId.c_str(), + (uint32_t) (millis64()/1000), + data->getPackageTimestamp(), + hw->getVcc(), + hw->getWifiRssi(), + hw->getTemperature(), + data->getListId().c_str(), + data->getMeterId().c_str(), + data->getMeterModel().c_str(), + data->getActiveImportPower(), + data->getReactiveImportPower(), + data->getActiveExportPower(), + data->getReactiveExportPower(), + data->getL1Current(), + data->getL2Current(), + data->getL3Current(), + data->getL1Voltage(), + data->getL2Voltage(), + data->getL3Voltage(), + data->getActiveImportCounter(), + data->getActiveExportCounter(), + data->getReactiveImportCounter(), + data->getReactiveExportCounter(), + data->getMeterTimestamp(), + ea->getUseThisHour(), + ea->getCurrentThreshold() + ); + return mqtt->publish(topic, json); + } else if(data->getListType() == 4) { + char json[768]; + snprintf_P(json, sizeof(json), JSON4_JSON, + WiFi.macAddress().c_str(), + clientId.c_str(), + (uint32_t) (millis64()/1000), + data->getPackageTimestamp(), + hw->getVcc(), + hw->getWifiRssi(), + hw->getTemperature(), + data->getListId().c_str(), + data->getMeterId().c_str(), + data->getMeterModel().c_str(), + data->getActiveImportPower(), + data->getReactiveImportPower(), + data->getActiveExportPower(), + data->getReactiveExportPower(), + data->getL1Current(), + data->getL2Current(), + data->getL3Current(), + data->getL1Voltage(), + data->getL2Voltage(), + data->getL3Voltage(), + data->getPowerFactor(), + data->getL1PowerFactor(), + data->getL2PowerFactor(), + data->getL3PowerFactor(), + data->getActiveImportCounter(), + data->getActiveExportCounter(), + data->getReactiveImportCounter(), + data->getReactiveExportCounter(), + data->getMeterTimestamp(), + ea->getUseThisHour(), + ea->getCurrentThreshold() + ); + return mqtt->publish(topic, json); } return false; } diff --git a/src/mqtt/RawMqttHandler.cpp b/src/mqtt/RawMqttHandler.cpp index f5da3516..0dd29156 100644 --- a/src/mqtt/RawMqttHandler.cpp +++ b/src/mqtt/RawMqttHandler.cpp @@ -10,15 +10,7 @@ bool RawMqttHandler::publish(AmsData* data, AmsData* meterState, EnergyAccountin mqtt->publish(topic + "/meter/dlms/timestamp", String(data->getPackageTimestamp())); } switch(data->getListType()) { - case 3: - // ID and type belongs to List 2, but I see no need to send that every 10s - mqtt->publish(topic + "/meter/id", data->getMeterId(), true, 0); - mqtt->publish(topic + "/meter/type", data->getMeterModel(), true, 0); - mqtt->publish(topic + "/meter/clock", String(data->getMeterTimestamp())); - mqtt->publish(topic + "/meter/import/reactive/accumulated", String(data->getReactiveImportCounter(), 3), true, 0); - mqtt->publish(topic + "/meter/import/active/accumulated", String(data->getActiveImportCounter(), 3), true, 0); - mqtt->publish(topic + "/meter/export/reactive/accumulated", String(data->getReactiveExportCounter(), 3), true, 0); - mqtt->publish(topic + "/meter/export/active/accumulated", String(data->getActiveExportCounter(), 3), true, 0); + case 4: if(full || meterState->getPowerFactor() != data->getPowerFactor()) { mqtt->publish(topic + "/meter/powerfactor", String(data->getPowerFactor(), 2)); } @@ -31,6 +23,15 @@ bool RawMqttHandler::publish(AmsData* data, AmsData* meterState, EnergyAccountin if(full || meterState->getL3PowerFactor() != data->getL3PowerFactor()) { mqtt->publish(topic + "/meter/l3/powerfactor", String(data->getL3PowerFactor(), 2)); } + case 3: + // ID and type belongs to List 2, but I see no need to send that every 10s + mqtt->publish(topic + "/meter/id", data->getMeterId(), true, 0); + mqtt->publish(topic + "/meter/type", data->getMeterModel(), true, 0); + mqtt->publish(topic + "/meter/clock", String(data->getMeterTimestamp())); + mqtt->publish(topic + "/meter/import/reactive/accumulated", String(data->getReactiveImportCounter(), 3), true, 0); + mqtt->publish(topic + "/meter/import/active/accumulated", String(data->getActiveImportCounter(), 3), true, 0); + mqtt->publish(topic + "/meter/export/reactive/accumulated", String(data->getReactiveExportCounter(), 3), true, 0); + mqtt->publish(topic + "/meter/export/active/accumulated", String(data->getActiveExportCounter(), 3), true, 0); case 2: // Only send data if changed. ID and Type is sent on the 10s interval only if changed if(full || meterState->getMeterId() != data->getMeterId()) { diff --git a/web/json3pf.json b/web/json4.json similarity index 100% rename from web/json3pf.json rename to web/json4.json