Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/AmsData/include/AmsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ class AmsData {
double getL3ActiveExportCounter();

double getActiveImportCounter();
double getActiveImportCounterTariff1();
double getActiveImportCounterTariff2();
double getReactiveImportCounter();
double getActiveExportCounter();
double getActiveExportCounterTariff1();
double getActiveExportCounterTariff2();
double getReactiveExportCounter();

bool isThreePhase();
Expand All @@ -89,6 +93,7 @@ class AmsData {
int8_t getLastError();
void setLastError(int8_t);


protected:
uint64_t lastUpdateMillis = 0;
uint64_t lastList2 = 0;
Expand All @@ -103,7 +108,7 @@ class AmsData {
double l1activeImportCounter = 0, l2activeImportCounter = 0, l3activeImportCounter = 0;
double l1activeExportCounter = 0, l2activeExportCounter = 0, l3activeExportCounter = 0;
float powerFactor = 0, l1PowerFactor = 0, l2PowerFactor = 0, l3PowerFactor = 0;
double activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
double activeImportCounter = 0, activeImportCounterTariff1 = 0, activeImportCounterTariff2 = 0, reactiveImportCounter = 0, activeExportCounter = 0, activeExportCounterTariff1 = 0, activeExportCounterTariff2 = 0, reactiveExportCounter = 0;
double lastKnownCounter = 0;
bool threePhase = false, twoPhase = false, counterEstimated = false, l2currentMissing = false;;

Expand Down
54 changes: 47 additions & 7 deletions lib/AmsData/src/AmsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@ void AmsData::apply(AmsData& other) {
double diff = activeImportCounter - activeExportCounter - lastKnownCounter;
if(diff < 1.0) { // In case a very low value have been calculated, use the new values
this->activeImportCounter = other.getActiveImportCounter();
this->activeImportCounterTariff1 = other.getActiveImportCounterTariff1();
this->activeImportCounterTariff2 = other.getActiveImportCounterTariff2();
this->activeExportCounter = other.getActiveExportCounter();
this->activeExportCounterTariff1 = other.getActiveExportCounterTariff1();
this->activeExportCounterTariff2 = other.getActiveExportCounterTariff2();
this->reactiveImportCounter = other.getReactiveImportCounter();
this->reactiveExportCounter = other.getReactiveExportCounter();
this->lastKnownCounter = activeImportCounter - activeExportCounter;
}
} else {
this->activeImportCounter = other.getActiveImportCounter();
this->activeImportCounterTariff1 = other.getActiveImportCounterTariff1();
this->activeImportCounterTariff2 = other.getActiveImportCounterTariff2();
this->activeExportCounter = other.getActiveExportCounter();
this->activeExportCounterTariff1 = other.getActiveExportCounterTariff1();
this->activeExportCounterTariff2 = other.getActiveExportCounterTariff2();
this->reactiveImportCounter = other.getReactiveImportCounter();
this->reactiveExportCounter = other.getReactiveExportCounter();
this->lastKnownCounter = activeImportCounter - activeExportCounter;
Expand Down Expand Up @@ -127,7 +135,7 @@ void AmsData::apply(OBIS_code_t obis, double value, uint64_t millis64) {
}
}
if(obis.tariff != 0) {
return;
// Tariff values are handled for accumulated counters below.
}
if(obis.gr == 7) { // Instant values
switch(obis.sensor) {
Expand Down Expand Up @@ -215,20 +223,36 @@ void AmsData::apply(OBIS_code_t obis, double value, uint64_t millis64) {
} else if(obis.gr == 8) { // Accumulated values
switch(obis.sensor) {
case 1:
activeImportCounter = value;
if(obis.tariff == 1) {
activeImportCounterTariff1 = value;
} else if(obis.tariff == 2) {
activeImportCounterTariff2 = value;
} else {
activeImportCounter = value;
}
listType = std::max(listType, (uint8_t) 3);
break;
case 2:
activeExportCounter = value;
if(obis.tariff == 1) {
activeExportCounterTariff1 = value;
} else if(obis.tariff == 2) {
activeExportCounterTariff2 = value;
} else {
activeExportCounter = value;
}
listType = std::max(listType, (uint8_t) 3);
break;
case 3:
reactiveImportCounter = value;
listType = std::max(listType, (uint8_t) 3);
if(obis.tariff == 0) {
reactiveImportCounter = value;
listType = std::max(listType, (uint8_t) 3);
}
break;
case 4:
reactiveExportCounter = value;
listType = std::max(listType, (uint8_t) 3);
if(obis.tariff == 0) {
reactiveExportCounter = value;
listType = std::max(listType, (uint8_t) 3);
}
break;
case 21:
l1activeImportCounter = value;
Expand Down Expand Up @@ -404,6 +428,14 @@ double AmsData::getActiveImportCounter() {
return this->activeImportCounter;
}

double AmsData::getActiveImportCounterTariff1() {
return this->activeImportCounterTariff1;
}

double AmsData::getActiveImportCounterTariff2() {
return this->activeImportCounterTariff2;
}

double AmsData::getReactiveImportCounter() {
return this->reactiveImportCounter;
}
Expand All @@ -412,6 +444,14 @@ double AmsData::getActiveExportCounter() {
return this->activeExportCounter;
}

double AmsData::getActiveExportCounterTariff1() {
return this->activeExportCounterTariff1;
}

double AmsData::getActiveExportCounterTariff2() {
return this->activeExportCounterTariff2;
}

double AmsData::getReactiveExportCounter() {
return this->reactiveExportCounter;
}
Expand Down
12 changes: 10 additions & 2 deletions lib/JsonMqttHandler/src/JsonMqttHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool JsonMqttHandler::publishList3(AmsData* data, EnergyAccounting* ea) {
if(mqttConfig.payloadFormat != 6) {
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"data\":{"));
}
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"lv\":\"%s\",\"meterId\":\"%s\",\"type\":\"%s\",\"P\":%d,\"Q\":%d,\"PO\":%d,\"QO\":%d,\"I1\":%.2f,\"I2\":%.2f,\"I3\":%.2f,\"U1\":%.2f,\"U2\":%.2f,\"U3\":%.2f,\"tPI\":%.3f,\"tPO\":%.3f,\"tQI\":%.3f,\"tQO\":%.3f,\"rtc\":%lu"),
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"lv\":\"%s\",\"meterId\":\"%s\",\"type\":\"%s\",\"P\":%d,\"Q\":%d,\"PO\":%d,\"QO\":%d,\"I1\":%.2f,\"I2\":%.2f,\"I3\":%.2f,\"U1\":%.2f,\"U2\":%.2f,\"U3\":%.2f,\"tPI\":%.3f,\"tPIT1\":%.3f,\"tPIT2\":%.3f,\"tPO\":%.3f,\"tPOT1\":%.3f,\"tPOT2\":%.3f,\"tQI\":%.3f,\"tQO\":%.3f,\"rtc\":%lu"),
data->getListId().c_str(),
data->getMeterId().c_str(),
getMeterModel(data).c_str(),
Expand All @@ -179,7 +179,11 @@ bool JsonMqttHandler::publishList3(AmsData* data, EnergyAccounting* ea) {
data->getL2Voltage(),
data->getL3Voltage(),
data->getActiveImportCounter(),
data->getActiveImportCounterTariff1(),
data->getActiveImportCounterTariff2(),
data->getActiveExportCounter(),
data->getActiveExportCounterTariff1(),
data->getActiveExportCounterTariff2(),
data->getReactiveImportCounter(),
data->getReactiveExportCounter(),
data->getMeterTimestamp()
Expand All @@ -201,7 +205,7 @@ bool JsonMqttHandler::publishList4(AmsData* data, EnergyAccounting* ea) {
if(mqttConfig.payloadFormat != 6) {
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"data\":{"));
}
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"lv\":\"%s\",\"meterId\":\"%s\",\"type\":\"%s\",\"P\":%d,\"P1\":%d,\"P2\":%d,\"P3\":%d,\"Q\":%d,\"PO\":%d,\"PO1\":%d,\"PO2\":%d,\"PO3\":%d,\"QO\":%d,\"I1\":%.2f,\"I2\":%.2f,\"I3\":%.2f,\"U1\":%.2f,\"U2\":%.2f,\"U3\":%.2f,\"PF\":%.2f,\"PF1\":%.2f,\"PF2\":%.2f,\"PF3\":%.2f,\"tPI\":%.3f,\"tPO\":%.3f,\"tQI\":%.3f,\"tQO\":%.3f,\"tPI1\":%.3f,\"tPI2\":%.3f,\"tPI3\":%.3f,\"tPO1\":%.3f,\"tPO2\":%.3f,\"tPO3\":%.3f,\"rtc\":%lu"),
pos += snprintf_P(json+pos, BufferSize-pos, PSTR("\"lv\":\"%s\",\"meterId\":\"%s\",\"type\":\"%s\",\"P\":%d,\"P1\":%d,\"P2\":%d,\"P3\":%d,\"Q\":%d,\"PO\":%d,\"PO1\":%d,\"PO2\":%d,\"PO3\":%d,\"QO\":%d,\"I1\":%.2f,\"I2\":%.2f,\"I3\":%.2f,\"U1\":%.2f,\"U2\":%.2f,\"U3\":%.2f,\"PF\":%.2f,\"PF1\":%.2f,\"PF2\":%.2f,\"PF3\":%.2f,\"tPI\":%.3f,\"tPIT1\":%.3f,\"tPIT2\":%.3f,\"tPO\":%.3f,\"tPOT1\":%.3f,\"tPOT2\":%.3f,\"tQI\":%.3f,\"tQO\":%.3f,\"tPI1\":%.3f,\"tPI2\":%.3f,\"tPI3\":%.3f,\"tPO1\":%.3f,\"tPO2\":%.3f,\"tPO3\":%.3f,\"rtc\":%lu"),
data->getListId().c_str(),
data->getMeterId().c_str(),
getMeterModel(data).c_str(),
Expand All @@ -226,7 +230,11 @@ bool JsonMqttHandler::publishList4(AmsData* data, EnergyAccounting* ea) {
data->getL2PowerFactor(),
data->getL3PowerFactor(),
data->getActiveImportCounter(),
data->getActiveImportCounterTariff1(),
data->getActiveImportCounterTariff2(),
data->getActiveExportCounter(),
data->getActiveExportCounterTariff1(),
data->getActiveExportCounterTariff2(),
data->getReactiveImportCounter(),
data->getReactiveExportCounter(),
data->getL1ActiveImportCounter(),
Expand Down
4 changes: 4 additions & 0 deletions lib/MeterCommunicators/include/IEC6205675.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class IEC6205675 : public AmsData {
uint8_t AMS_OBIS_VOLTAGE_L2[4] = { 52, 7, 0, 255 };
uint8_t AMS_OBIS_VOLTAGE_L3[4] = { 72, 7, 0, 255 };
uint8_t AMS_OBIS_ACTIVE_IMPORT_COUNT[4] = { 1, 8, 0, 255 };
uint8_t AMS_OBIS_ACTIVE_IMPORT_COUNT_T1[4] = { 1, 8, 1, 255 };
uint8_t AMS_OBIS_ACTIVE_IMPORT_COUNT_T2[4] = { 1, 8, 2, 255 };
uint8_t AMS_OBIS_ACTIVE_EXPORT_COUNT[4] = { 2, 8, 0, 255 };
uint8_t AMS_OBIS_ACTIVE_EXPORT_COUNT_T1[4] = { 2, 8, 1, 255 };
uint8_t AMS_OBIS_ACTIVE_EXPORT_COUNT_T2[4] = { 2, 8, 2, 255 };
uint8_t AMS_OBIS_REACTIVE_IMPORT_COUNT[4] = { 3, 8, 0, 255 };
uint8_t AMS_OBIS_REACTIVE_EXPORT_COUNT[4] = { 4, 8, 0, 255 };
uint8_t AMS_OBIS_POWER_FACTOR[4] = { 13, 7, 0, 255 };
Expand Down
4 changes: 4 additions & 0 deletions lib/MeterCommunicators/src/IEC6205675.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ IEC6205675::IEC6205675(const char* d, Timezone* tz, uint8_t useMeterType, MeterC
data = getCosemDataAt(idx++, ((char *) (d)));
double obis182 = ntohl(data->dlu.data) / 1000.0;

activeImportCounterTariff1 = obis181;
activeImportCounterTariff2 = obis182;
if(activeImportCounter < obis181 + obis182)
activeImportCounter = obis181 + obis182;

Expand All @@ -397,6 +399,8 @@ IEC6205675::IEC6205675(const char* d, Timezone* tz, uint8_t useMeterType, MeterC
data = getCosemDataAt(idx++, ((char *) (d)));
double obis282 = ntohl(data->dlu.data) / 1000.0;

activeExportCounterTariff1 = obis281;
activeExportCounterTariff2 = obis282;
if(activeExportCounter < obis281 + obis282)
activeExportCounter = obis281 + obis282;

Expand Down
4 changes: 4 additions & 0 deletions lib/MeterCommunicators/src/LNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ LNG::LNG(AmsData& meterState, const char* payload, uint8_t useMeterType, MeterCo
}

if(o181 > 0 || o182 > 0) {
activeImportCounterTariff1 = o181 / 1000.0;
activeImportCounterTariff2 = o182 / 1000.0;
activeImportCounter = (o181 + o182) / 1000.0;
}
if(o281 > 0 || o282 > 0) {
activeExportCounterTariff1 = o281 / 1000.0;
activeExportCounterTariff2 = o282 / 1000.0;
activeExportCounter = (o281 + o282) / 1000.0;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/RawMqttHandler/src/RawMqttHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ bool RawMqttHandler::publishList3(AmsData* data, AmsData* meterState) {
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/import/active/accumulated/tariff1", String(data->getActiveImportCounterTariff1(), 3), true, 0);
mqtt.publish(topic + "/meter/import/active/accumulated/tariff2", String(data->getActiveImportCounterTariff2(), 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);
mqtt.publish(topic + "/meter/export/active/accumulated/tariff1", String(data->getActiveExportCounterTariff1(), 3), true, 0);
mqtt.publish(topic + "/meter/export/active/accumulated/tariff2", String(data->getActiveExportCounterTariff2(), 3), true, 0);
return true;
}

Expand Down
18 changes: 17 additions & 1 deletion lib/SvelteUi/app/src/lib/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
export let translations = {};
export let tariffData = {};

let it,et,threePhase, l1e, l2e, l3e;
let it,et,it1,it2,et1,et2,threePhase, l1e, l2e, l3e;
$: {
it = formatUnit(data?.ic * 1000, "Wh");
et = formatUnit(data?.ec * 1000, "Wh");
it1 = formatUnit(data?.ict1 * 1000, "Wh");
it2 = formatUnit(data?.ict2 * 1000, "Wh");
et1 = formatUnit(data?.ect1 * 1000, "Wh");
et2 = formatUnit(data?.ect2 * 1000, "Wh");
if(data?.l1?.u == 0.0 && data?.l2?.u == 0.0 && data?.l3?.u == 0.0) {
l1e = l2e = l3e = threePhase = true;
} else {
Expand All @@ -46,6 +50,12 @@
</div>
<div>{data.mt ? metertype(data.mt) : '-'}</div>
<div class="text-right">{it[0]} {it[1]}</div>
{#if data?.ict1 > 0 || data?.ict2 > 0}
<div class="text-xs text-gray-500">Tariff 1</div>
<div class="text-right text-xs text-gray-500">{it1[0]} {it1[1]}</div>
<div class="text-xs text-gray-500">Tariff 2</div>
<div class="text-right text-xs text-gray-500">{it2[0]} {it2[1]}</div>
{/if}
</div>
</div>
{/if}
Expand All @@ -57,6 +67,12 @@
</div>
<div></div>
<div class="text-right">{et[0]} {et[1]}</div>
{#if data?.ect1 > 0 || data?.ect2 > 0}
<div class="text-xs text-gray-500">Tariff 1</div>
<div class="text-right text-xs text-gray-500">{et1[0]} {et1[1]}</div>
<div class="text-xs text-gray-500">Tariff 2</div>
<div class="text-right text-xs text-gray-500">{et2[0]} {et2[1]}</div>
{/if}
</div>
</div>
{/if}
Expand Down
4 changes: 4 additions & 0 deletions lib/SvelteUi/json/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"ri" : %lu,
"re" : %lu,
"ic" : %.3f,
"ict1" : %.3f,
"ict2" : %.3f,
"ec" : %.3f,
"ect1" : %.3f,
"ect2" : %.3f,
"ric" : %.3f,
"rec" : %.3f,
"f" : %.2f,
Expand Down
4 changes: 4 additions & 0 deletions lib/SvelteUi/src/AmsWebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ void AmsWebServer::dataJson() {
meterState->getReactiveImportPower(),
meterState->getReactiveExportPower(),
meterState->getActiveImportCounter(),
meterState->getActiveImportCounterTariff1(),
meterState->getActiveImportCounterTariff2(),
meterState->getActiveExportCounter(),
meterState->getActiveExportCounterTariff1(),
meterState->getActiveExportCounterTariff2(),
meterState->getReactiveImportCounter(),
meterState->getReactiveExportCounter(),
meterState->getPowerFactor(),
Expand Down
Loading