From 1065381a7905d932c99ca38483adb3a3cbd18d5e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 21 Apr 2020 11:46:41 +0200 Subject: [PATCH] Fix MI_ESP32 MQTT voltage calculation --- tasmota/xsns_62_MI_ESP32.ino | 95 ++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/tasmota/xsns_62_MI_ESP32.ino b/tasmota/xsns_62_MI_ESP32.ino index 7c687402c..c9a5ba73a 100644 --- a/tasmota/xsns_62_MI_ESP32.ino +++ b/tasmota/xsns_62_MI_ESP32.ino @@ -1058,42 +1058,50 @@ 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]); - ResponseAppend_P(PSTR(",\"%s\":{"),slave); - 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 { - ResponseAppend_P(PSTR("}")); - continue; - } - if(MIBLEsensors[i].lux!=0x0ffffff){ // this is the error code -> no lux - ResponseAppend_P(PSTR(",\"" D_JSON_ILLUMINANCE "\":%u"), MIBLEsensors[i].lux); - } - if(!isnan(MIBLEsensors[i].moisture)){ - ResponseAppend_P(PSTR(",\"" D_JSON_MOISTURE "\":%d"), MIBLEsensors[i].moisture); - } - if(!isnan(MIBLEsensors[i].fertility)){ - ResponseAppend_P(PSTR(",\"Fertility\":%d"), MIBLEsensors[i].fertility); - } + 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 { + ResponseAppend_P(PSTR("}")); + continue; } - if (MIBLEsensors[i].type>FLORA){ - if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ - ResponseAppendTHD(MIBLEsensors[i].temp, MIBLEsensors[i].hum); - } + if (MIBLEsensors[i].lux!=0x0ffffff) { // this is the error code -> no lux + ResponseAppend_P(PSTR(",\"" D_JSON_ILLUMINANCE "\":%u"), MIBLEsensors[i].lux); } - 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 (!isnan(MIBLEsensors[i].moisture)) { + ResponseAppend_P(PSTR(",\"" D_JSON_MOISTURE "\":%d"), MIBLEsensors[i].moisture); } + if (!isnan(MIBLEsensors[i].fertility)) { + ResponseAppend_P(PSTR(",\"Fertility\":%d"), MIBLEsensors[i].fertility); } - ResponseAppend_P(PSTR("}")); + } + if (MIBLEsensors[i].type > FLORA){ + if (!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)) { + ResponseAppendTHD(MIBLEsensors[i].temp, MIBLEsensors[i].hum); + } + } + 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 { + char voltage[FLOATSZ]; + dtostrfd((MIBLEsensors[i].volt)/1000.0f, Settings.flag2.voltage_resolution, voltage); + ResponseAppend_P(PSTR(",\"" D_VOLTAGE "\":%s"), voltage); + } + } + ResponseAppend_P(PSTR("}")); } #ifdef USE_WEBSERVER } else { @@ -1114,32 +1122,33 @@ void MI32Show(bool json) for (i; i no valid value + if (MIBLEsensors[i].lux!=0x00ffffff) { // this is the error code -> no valid value WSContentSend_PD(HTTP_SNS_ILLUMINANCE, kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].lux); } - if(!isnan(MIBLEsensors[i].moisture)){ + if (!isnan(MIBLEsensors[i].moisture)) { WSContentSend_PD(HTTP_SNS_MOISTURE, kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].moisture); } - if(!isnan(MIBLEsensors[i].fertility)){ + if (!isnan(MIBLEsensors[i].fertility)) { WSContentSend_PD(HTTP_MI32_FLORA_DATA, kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].fertility); } } - if (MIBLEsensors[i].type>FLORA){ // everything "above" Flora - if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ + if (MIBLEsensors[i].type>FLORA) { // everything "above" Flora + if (!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)) { WSContentSend_THD(kMI32SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].temp, MIBLEsensors[i].hum); } } 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 } }