Skip to content

Commit

Permalink
Show when I2 is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Dec 21, 2023
1 parent 859868c commit 378b67a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 52 deletions.
4 changes: 2 additions & 2 deletions lib/AmsData/include/AmsData.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AmsData {

bool isThreePhase();
bool isTwoPhase();
bool isL2currentEstimated();
bool isL2currentMissing();

int8_t getLastError();
void setLastError(int8_t);
Expand All @@ -86,7 +86,7 @@ class AmsData {
float l1activeExportPower = 0, l2activeExportPower = 0, l3activeExportPower = 0;
float powerFactor = 0, l1PowerFactor = 0, l2PowerFactor = 0, l3PowerFactor = 0;
double activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
bool threePhase = false, twoPhase = false, counterEstimated = false, l2currentEstimated = false;
bool threePhase = false, twoPhase = false, counterEstimated = false, l2currentMissing = false;;

int8_t lastError = 0x00;
uint8_t lastErrorCount = 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/AmsData/src/AmsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void AmsData::apply(AmsData& other) {
this->reactiveExportPower = other.getReactiveExportPower();
this->l1current = other.getL1Current();
this->l2current = other.getL2Current();
this->l2currentEstimated = other.isL2currentEstimated();
this->l2currentMissing = other.isL2currentMissing();
this->l3current = other.getL3Current();
this->l1voltage = other.getL1Voltage();
this->l2voltage = other.getL2Voltage();
Expand Down Expand Up @@ -219,8 +219,8 @@ bool AmsData::isTwoPhase() {
return this->twoPhase;
}

bool AmsData::isL2currentEstimated() {
return this->l2currentEstimated;
bool AmsData::isL2currentMissing() {
return this->l2currentMissing;
}

int8_t AmsData::getLastError() {
Expand Down
20 changes: 10 additions & 10 deletions lib/SvelteUi/app/dist/index.js

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions lib/SvelteUi/app/src/lib/AmpPlot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
let config = {};
function point(v,e) {
function point(v) {
return {
label: fmtnum(v) + 'A',
title: (e ? 'Estimated ' : '') + v.toFixed(1) + ' A',
title: v.toFixed(1) + ' A',
value: isNaN(v) ? 0 : v,
color: ampcol(v ? (v)/(max)*100 : 0, e)
color: ampcol(v ? (v)/(max)*100 : 0)
};
};
Expand All @@ -30,8 +30,19 @@
points.push(point(i1));
}
if(u2 > 0) {
xTicks.push({ label: 'L2' });
points.push(point(i2, i2e));
if(i2e) {
xTicks.push({ label: 'L2' });
points.push({
label: 'N/A',
labelAngle: 90,
title: 'The value is not reported by your meter',
value: 0,
color: '#7c3aedcc'
});
} else {
xTicks.push({ label: 'L2' });
points.push(point(i2));
}
}
if(u3 > 0) {
xTicks.push({ label: 'L3' });
Expand Down
4 changes: 2 additions & 2 deletions lib/SvelteUi/app/src/lib/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export function voltcol(volt) {
return '#d90000';
};

export function ampcol(pct, est) {
export function ampcol(pct) {
let col;
if(pct > 90) col = '#d90000';
else if(pct > 85) col = '#e32100';
else if(pct > 80) col = '#ffb800';
else if(pct > 75) col = '#dcd800';
else col = '#32d900';

return col+(est?'88':'');
return col;
};

export function exportcol(pct) {
Expand Down
30 changes: 15 additions & 15 deletions lib/SvelteUi/app/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/data.json": "http://192.168.233.244",
"/energyprice.json": "http://192.168.233.244",
"/dayplot.json": "http://192.168.233.244",
"/monthplot.json": "http://192.168.233.244",
"/temperature.json": "http://192.168.233.244",
"/sysinfo.json": "http://192.168.233.244",
"/configuration.json": "http://192.168.233.244",
"/tariff.json": "http://192.168.233.244",
"/save": "http://192.168.233.244",
"/reboot": "http://192.168.233.244",
"/configfile": "http://192.168.233.244",
"/upgrade": "http://192.168.233.244",
"/mqtt-ca": "http://192.168.233.244",
"/mqtt-cert": "http://192.168.233.244",
"/mqtt-key": "http://192.168.233.244",
"/data.json": "http://192.168.233.49",
"/energyprice.json": "http://192.168.233.49",
"/dayplot.json": "http://192.168.233.49",
"/monthplot.json": "http://192.168.233.49",
"/temperature.json": "http://192.168.233.49",
"/sysinfo.json": "http://192.168.233.49",
"/configuration.json": "http://192.168.233.49",
"/tariff.json": "http://192.168.233.49",
"/save": "http://192.168.233.49",
"/reboot": "http://192.168.233.49",
"/configfile": "http://192.168.233.49",
"/upgrade": "http://192.168.233.49",
"/mqtt-ca": "http://192.168.233.49",
"/mqtt-cert": "http://192.168.233.49",
"/mqtt-key": "http://192.168.233.49",
}
}
})
2 changes: 1 addition & 1 deletion lib/SvelteUi/src/AmsWebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void AmsWebServer::dataJson() {
meterState->getL3Voltage(),
meterState->getL1Current(),
meterState->getL2Current(),
meterState->isL2currentEstimated() ? "true" : "false",
meterState->isL2currentMissing() ? "true" : "false",
meterState->getL3Current(),
meterState->getPowerFactor(),
meterState->getL1PowerFactor(),
Expand Down
2 changes: 1 addition & 1 deletion src/AmsToMqttBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ bool readHanPort() {
data = new IEC6205675(payload, meterState.getMeterType(), &meterConfig, ctx, meterState);
}
} else if(ctx.type == DATA_TAG_DSMR) {
data = new IEC6205621(payload, tz);
data = new IEC6205621(payload, tz, &meterConfig);
}
len = 0;

Expand Down
17 changes: 4 additions & 13 deletions src/IEC6205675.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo

if(listType >= 2 && memcmp(meterModel.c_str(), "MA304T3", 7) == 0) {
l2voltage = sqrt(pow(l1voltage - l3voltage * cos(60 * (PI/180)), 2) + pow(l3voltage * sin(60 * (PI/180)),2));
if(l2voltage > 0) {
l2current = ((activeImportPower - activeExportPower) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
l2currentEstimated = true;
}
l2currentMissing = true;
}

if(listType == 3) {
Expand Down Expand Up @@ -297,6 +294,8 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
if(val != NOVALUE) {
listType = 2;
l2current = val;
} else if(listType == 2) {
l2currentMissing = true;
}
val = getNumber(AMS_OBIS_CURRENT_L3, sizeof(AMS_OBIS_CURRENT_L3), ((char *) (d)));
if(val != NOVALUE) {
Expand Down Expand Up @@ -487,15 +486,7 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo

// Special case for Norwegian IT/TT meters that does not report all values
if(meterConfig->distributionSystem == 1) {
if(threePhase) {
if(l2current == 0.0 && l1current > 0.0 && l3current > 0.0) {
l2current = ((activeImportPower - activeExportPower) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
if(activeExportPower == 0.0) {
l2current = max((float) 0.0, l2current);
}
l2currentEstimated = true;
}
} else if(twoPhase && l1current > 0.0 && l2current > 0.0 && l3current > 0.0) {
if(twoPhase && l1current > 0.0 && l2current > 0.0 && l3current > 0.0) {
l2voltage = sqrt(pow(l1voltage - l3voltage * cos(60.0 * (PI/180.0)), 2) + pow(l3voltage * sin(60.0 * (PI/180.0)),2));
threePhase = true;
}
Expand Down

0 comments on commit 378b67a

Please sign in to comment.