Compare commits

..

11 Commits

Author SHA1 Message Date
Gunnar Skjold
05bdbaf1f5 Fixed error 2021-10-30 18:42:59 +02:00
Gunnar Skjold
6cca25788e Fixed copy/paste error 2021-10-23 10:45:57 +02:00
Gunnar Skjold
e929f87ea9 Fixed decimals in json 2021-10-23 10:38:53 +02:00
Gunnar Skjold
21a4102553 Changes for correct time conversion 2021-10-23 10:05:14 +02:00
Gunnar Skjold
768645fc0a Added more decimals in data.json 2021-10-23 10:04:52 +02:00
Gunnar Skjold
c670549dea Warning for BUS powered devices on firmware upgrade 2021-10-23 09:21:53 +02:00
Gunnar Skjold
147b2ca33e Fixed build error 2021-10-23 09:07:07 +02:00
Gunnar Skjold
c645b82ed3 Fixed voltage and amp meters 2021-10-23 09:04:00 +02:00
Gunnar Skjold
26bb8a0fea Support two phase power calculation 2021-10-23 08:59:16 +02:00
Gunnar Skjold
507ed13770 Added GPIO designation to UART in dropdown 2021-10-23 08:40:40 +02:00
Gunnar Skjold
a0f53a0c52 Partial fix of dead gauges 2021-10-21 21:17:03 +02:00
9 changed files with 113 additions and 90 deletions

View File

@@ -299,10 +299,10 @@ time_t HanReader::getTime(byte *buffer, int start, int length, bool respectTimez
tm.Second = second;
time_t time = makeTime(tm);
if(respectTimezone && tzMinutes != 0x8000) {
if(respectTimezone && (tzMinutes | 0x8000) != 0x8000 && tzMinutes <= 720 && tzMinutes >= -720) {
time -= tzMinutes * 60;
if(respectDsc && dsc)
time -= 3600;
time += 3600;
} else {
if(respectDsc && dsc)
time += 3600;

View File

@@ -16,15 +16,23 @@ AmsData::AmsData(uint8_t meterType, bool substituteMissing, HanReader& hanReader
extractFromKaifa(hanReader, listSize);
break;
case METER_TYPE_AIDON:
extractFromAidon(hanReader, listSize, substituteMissing);
extractFromAidon(hanReader, listSize);
break;
case METER_TYPE_KAMSTRUP:
extractFromKamstrup(hanReader, listSize, substituteMissing);
extractFromKamstrup(hanReader, listSize);
break;
case METER_TYPE_OMNIPOWER:
extractFromOmnipower(hanReader, listSize, substituteMissing);
extractFromOmnipower(hanReader, listSize);
break;
}
threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0;
twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0);
if(threePhase) {
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
}
}
void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
@@ -90,7 +98,7 @@ void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
}
}
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Aidon::List1:
listType = 1;
@@ -171,15 +179,12 @@ void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool subs
l1voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL1)) / 10;
l2voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL2)) / 10;
l3voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL3)) / 10;
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}
}
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Kamstrup::List3PhaseITShort:
case (uint8_t)Kamstrup::List3PhaseShort:
@@ -254,14 +259,11 @@ void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool s
l1voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL1);
l2voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL2);
l3voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL3);
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Kamstrup::List3PhaseITShort:
case (uint8_t)Kamstrup::List3PhaseShort:
@@ -269,7 +271,7 @@ void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool
case (uint8_t)Kamstrup::List3PhaseITLong:
case (uint8_t)Kamstrup::List3PhaseLong:
case (uint8_t)Kamstrup::List1PhaseLong:
extractFromKamstrup(hanReader, listSize, substituteMissing);
extractFromKamstrup(hanReader, listSize);
break;
case (uint8_t)Omnipower::DLMS:
meterTimestamp = hanReader.getTime( (uint8_t)Omnipower_DLMS::MeterClock, true, true);
@@ -340,6 +342,7 @@ void AmsData::apply(AmsData& other) {
this->l2voltage = other.getL2Voltage();
this->l3voltage = other.getL3Voltage();
this->threePhase = other.isThreePhase();
this->twoPhase = other.isTwoPhase();
case 1:
this->activeImportPower = other.getActiveImportPower();
}
@@ -432,3 +435,7 @@ float AmsData::getReactiveExportCounter() {
bool AmsData::isThreePhase() {
return this->threePhase;
}
bool AmsData::isTwoPhase() {
return this->twoPhase;
}

View File

@@ -48,6 +48,7 @@ public:
float getReactiveExportCounter();
bool isThreePhase();
bool isTwoPhase();
private:
unsigned long lastUpdateMillis = 0;
@@ -58,12 +59,12 @@ private:
uint16_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
float activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
bool threePhase = false, counterEstimated = false;
bool threePhase = false, twoPhase = false, counterEstimated = false;
void extractFromKaifa(HanReader& hanReader, uint8_t listSize);
void extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromAidon(HanReader& hanReader, uint8_t listSize);
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize);
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize);
};
#endif

View File

@@ -23,55 +23,47 @@ bool DomoticzMqttHandler::publish(AmsData* data, AmsData* previousState) {
return ret;
if (config.vl1idx > 0){
if (data->getL1Voltage() > 0.1){
char val[16];
snprintf(val, 16, "%.2f", data->getL1Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl1idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
char val[16];
snprintf(val, 16, "%.2f", data->getL1Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl1idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
if (config.vl2idx > 0){
if (data->getL2Voltage() > 0.1){
char val[16];
snprintf(val, 16, "%.2f", data->getL2Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl2idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
char val[16];
snprintf(val, 16, "%.2f", data->getL2Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl2idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
if (config.vl3idx > 0){
if (data->getL3Voltage() > 0.1){
char val[16];
snprintf(val, 16, "%.2f", data->getL3Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl3idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
char val[16];
snprintf(val, 16, "%.2f", data->getL3Voltage());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.vl3idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
if (config.cl1idx > 0){
if(data->getL1Current() > 0.0) {
char val[16];
snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.cl1idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
char val[16];
snprintf(val, 16, "%.1f;%.1f;%.1f", data->getL1Current(), data->getL2Current(), data->getL3Current());
char json[192];
snprintf_P(json, sizeof(json), DOMOTICZ_JSON,
config.cl1idx,
val
);
ret |= mqtt->publish("domoticz/in", json);
}
return ret;
}

View File

@@ -117,9 +117,11 @@ void AmsWebServer::loop() {
server.handleClient();
if(maxPwr == 0 && meterState->getListType() > 1 && meterConfig->mainFuse > 0 && meterConfig->distributionSystem > 0) {
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
if(meterState->isThreePhase()) {
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
maxPwr = meterConfig->mainFuse * sqrt(3) * voltage;
} else if(meterState->isTwoPhase()) {
maxPwr = meterConfig->mainFuse * voltage;
} else {
maxPwr = meterConfig->mainFuse * 230;
}
@@ -693,7 +695,7 @@ void AmsWebServer::dataJson() {
mqttStatus = 3;
}
char json[280];
char json[290];
snprintf_P(json, sizeof(json), DATA_JSON,
maxPwr == 0 ? meterState->isThreePhase() ? 20000 : 10000 : maxPwr,
meterConfig->productionCapacity,
@@ -1189,22 +1191,22 @@ void AmsWebServer::configDebugHtml() {
String AmsWebServer::getSerialSelectOptions(int selected) {
String gpioOptions;
if(selected == 3) {
gpioOptions += "<option value=\"3\" selected>UART0</option>";
gpioOptions += "<option value=\"3\" selected>UART0 (GPIO3)</option>";
} else {
gpioOptions += "<option value=\"3\">UART0</option>";
gpioOptions += "<option value=\"3\">UART0 (GPIO3)</option>";
}
#if defined(ESP32)
int numGpio = 24;
int gpios[] = {4,5,6,7,8,10,11,12,13,14,15,17,18,19,21,22,23,25,32,33,34,35,36,39};
if(selected == 9) {
gpioOptions += "<option value=\"9\" selected>UART1</option>";
gpioOptions += "<option value=\"9\" selected>UART1 (GPIO9)</option>";
} else {
gpioOptions += "<option value=\"9\">UART1</option>";
gpioOptions += "<option value=\"9\">UART1 (GPIO9)</option>";
}
if(selected == 16) {
gpioOptions += "<option value=\"16\" selected>UART2</option>";
gpioOptions += "<option value=\"16\" selected>UART2 (GPIO16)</option>";
} else {
gpioOptions += "<option value=\"16\">UART2</option>";
gpioOptions += "<option value=\"16\">UART2 (GPIO16)</option>";
}
#elif defined(ESP8266)
int numGpio = 9;

View File

@@ -147,6 +147,7 @@ $(function() {
case '/gpio':
case '/debugging':
case '/firmware':
$('#firmware-warn').show();
case '/reset':
$('#system-link').addClass('active');
break;
@@ -307,11 +308,22 @@ var fetch = function() {
});
}
if(vm && vm.gaugeMeter && json.u1) {
var v = parseFloat(json.u1);
if(json.u2) {
v = (v+parseFloat(json.u2)+parseFloat(json.u3)) / 3;
if(vm && vm.gaugeMeter) {
var c = 0;
var t = 0;
if(json.u1) {
t += parseFloat(json.u1);
c++;
}
if(json.u2) {
t += parseFloat(json.u2);
c++;
}
if(json.u3) {
t += parseFloat(json.u3);
c++;
}
v = t/c;
var pct = (Math.max(v-207, 1)*100/46);
vm.gaugeMeter({
percent: pct,
@@ -319,18 +331,21 @@ var fetch = function() {
});
}
if(am && am.gaugeMeter && json.i1 && json.mf) {
var v = parseFloat(json.i1);
if(am && am.gaugeMeter && json.mf) {
var a = 0;
if(json.i1) {
a = Math.max(a, parseFloat(json.i1));
}
if(json.i2) {
v = Math.max(v, parseFloat(json.i2));
a = Math.max(a, parseFloat(json.i2));
}
if(json.i3) {
v = Math.max(v, parseFloat(json.i3));
a = Math.max(a, parseFloat(json.i3));
}
var pct = (v*100)/parseInt(json.mf);
var pct = (a*100)/parseInt(json.mf);
am.gaugeMeter({
percent: pct,
text: v.toFixed(1)
text: a.toFixed(1)
});
}

View File

@@ -6,19 +6,19 @@
"e" : %d,
"ri" : %d,
"re" : %d,
"ic" : %.1f,
"ec" : %.1f,
"ric" : %.1f,
"rec" : %.1f,
"u1" : %.1f,
"u2" : %.1f,
"u3" : %.1f,
"ic" : %.2f,
"ec" : %.2f,
"ric" : %.2f,
"rec" : %.2f,
"u1" : %.2f,
"u2" : %.2f,
"u3" : %.2f,
"i1" : %.2f,
"i2" : %.2f,
"i3" : %.2f,
"v" : %.2f,
"v" : %.3f,
"r" : %d,
"t" : %.1f,
"t" : %.2f,
"u" : %lu,
"m" : %lu,
"em" : %d,

View File

@@ -20,10 +20,10 @@
"U1" : %.2f,
"U2" : %.2f,
"U3" : %.2f,
"tPI" : %.1f,
"tPO" : %.1f,
"tQI" : %.1f,
"tQO" : %.1f,
"tPI" : %.2f,
"tPO" : %.2f,
"tQI" : %.2f,
"tQO" : %.2f,
"rtc" : %lu
}
}

View File

@@ -13,6 +13,12 @@
</div>
</div>
</div>
<div id="firmware-warn" style="display: none;">
<br/>
<div class="alert alert-danger">
WARNING: Units powered over M-bus must be connected to an external power supply during firmware upload. Failure to do so may cause power-down during upload resulting in non-functioning unit.
</div>
</div>
</div>
<hr/>
<div class="row form-group">