Fix MI_ESP32 MQTT voltage calculation

This commit is contained in:
Theo Arends 2020-04-21 11:46:41 +02:00
parent b9f8d0b104
commit 1065381a79

View File

@ -1058,16 +1058,22 @@ void MI32Show(bool json)
{
if (json) {
for (uint32_t i = 0; i < MIBLEsensors.size(); i++) {
/*
char slave[33];
sprintf_P(slave,"%s-%02x%02x%02x",kMI32SlaveType[MIBLEsensors[i].type-1],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]);
snprintf_P(slave, sizeof(slave), PSTR("%s-%02x%02x%02x"),
kMI32SlaveType[MIBLEsensors[i].type-1],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]);
ResponseAppend_P(PSTR(",\"%s\":{"), slave);
*/
ResponseAppend_P(PSTR(",\"%s-%02x%02x%02x\":{"),
kMI32SlaveType[MIBLEsensors[i].type-1],
MIBLEsensors[i].serial[3], MIBLEsensors[i].serial[4], MIBLEsensors[i].serial[5]);
if (MIBLEsensors[i].type == FLORA) {
if (!isnan(MIBLEsensors[i].temp)) { // this is the error code -> no temperature
char temperature[FLOATSZ]; // all sensors have temperature
dtostrfd(MIBLEsensors[i].temp, Settings.flag2.temperature_resolution, temperature);
ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%s"), temperature);
}
else {
} else {
ResponseAppend_P(PSTR("}"));
continue;
}
@ -1087,10 +1093,12 @@ void MI32Show(bool json)
}
}
if (MIBLEsensors[i].bat != 0x00) { // this is the error code -> no battery
if (MIBLEsensors[i].type != LYWSD03MMC) ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors[i].bat);
else {
dtostrfd((MIBLEsensors[i].volt)/100.0f, Settings.flag2.temperature_resolution, slave); // reuse slave, borrow temperature resolution
ResponseAppend_P(PSTR(",\"" D_VOLTAGE "\":%s"), slave);
if (MIBLEsensors[i].type != LYWSD03MMC) {
ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors[i].bat);
} else {
char voltage[FLOATSZ];
dtostrfd((MIBLEsensors[i].volt)/1000.0f, Settings.flag2.voltage_resolution, voltage);
ResponseAppend_P(PSTR(",\"" D_VOLTAGE "\":%s"), voltage);
}
}
ResponseAppend_P(PSTR("}"));
@ -1136,10 +1144,11 @@ void MI32Show(bool json)
}
}
if(MIBLEsensors[i].bat!=0x00){
if (MIBLEsensors[i].type != LYWSD03MMC) WSContentSend_PD(HTTP_BATTERY, kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].bat);
else {
if (MIBLEsensors[i].type != LYWSD03MMC) {
WSContentSend_PD(HTTP_BATTERY, kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].bat);
} else {
char voltage[FLOATSZ];
dtostrfd((MIBLEsensors[i].volt)/1000.0f, 2, voltage); // borrow temperature resolution
dtostrfd((MIBLEsensors[i].volt)/1000.0f, Settings.flag2.voltage_resolution, voltage);
WSContentSend_PD(HTTP_VOLTAGE, kMI32SlaveType[MIBLEsensors[i].type-1], voltage);
}
}
@ -1149,8 +1158,8 @@ void MI32Show(bool json)
_page++;
_counter=0;
}
if(MIBLEsensors.size()%MI32.perPage==0 && _page==MIBLEsensors.size()/MI32.perPage) _page=0;
if(_page>MIBLEsensors.size()/MI32.perPage) _page=0;
if (MIBLEsensors.size()%MI32.perPage==0 && _page==MIBLEsensors.size()/MI32.perPage) { _page = 0; }
if (_page>MIBLEsensors.size()/MI32.perPage) { _page = 0; }
#endif // USE_WEBSERVER
}
}