Fixed decimals in json

This commit is contained in:
Gunnar Skjold 2021-10-23 10:38:53 +02:00
parent 21a4102553
commit e929f87ea9
4 changed files with 42 additions and 50 deletions

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

@ -695,7 +695,7 @@ void AmsWebServer::dataJson() {
mqttStatus = 3;
}
char json[284];
char json[290];
snprintf_P(json, sizeof(json), DATA_JSON,
maxPwr == 0 ? meterState->isThreePhase() ? 20000 : 10000 : maxPwr,
meterConfig->productionCapacity,

View File

@ -6,10 +6,10 @@
"e" : %d,
"ri" : %d,
"re" : %d,
"ic" : %.1f,
"ec" : %.1f,
"ric" : %.1f,
"rec" : %.1f,
"ic" : %.2f,
"ec" : %.2f,
"ric" : %.2f,
"rec" : %.2f,
"u1" : %.2f,
"u2" : %.2f,
"u3" : %.2f,
@ -18,7 +18,7 @@
"i3" : %.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
}
}