From 20704ab700746148b2abaf33a7f9743a3279c25f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:26:00 +0100 Subject: [PATCH] Refactor dtostrfd --- tasmota/i18n.h | 1 + tasmota/support_command.ino | 4 +--- tasmota/xdrv_01_webserver.ino | 8 ++++++-- tasmota/xdrv_16_tuyamcu.ino | 2 +- tasmota/xnrg_12_solaxX1.ino | 10 ++++------ tasmota/xnrg_14_bl0940.ino | 10 ++++------ tasmota/xsns_02_analog.ino | 9 +++------ tasmota/xsns_05_ds18x20.ino | 10 ++++------ tasmota/xsns_05_ds18x20_esp32.ino | 10 ++++------ tasmota/xsns_09_bmp.ino | 12 +++++------- tasmota/xsns_15_mhz19.ino | 9 ++++----- tasmota/xsns_26_lm75ad.ino | 8 +++----- tasmota/xsns_32_mpu6050.ino | 14 ++++++-------- tasmota/xsns_37_rfsensor.ino | 11 +++++------ tasmota/xsns_39_max31855.ino | 16 +++++++--------- 15 files changed, 58 insertions(+), 76 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index ff2a2fcbc..fadebd6fb 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -746,6 +746,7 @@ const char S_JSON_DRIVER_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_DRIVE const char S_JSON_SVALUE_ACTION_SVALUE[] PROGMEM = "{\"%s\":{\"Action\":\"%s\"}}"; +const char JSON_SNS_F_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f}"; const char JSON_SNS_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"; const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"; diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index b5389b00b..0c0797d5e 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -83,9 +83,7 @@ void ResponseCmndNumber(int value) void ResponseCmndFloat(float value, uint32_t decimals) { - char stemp1[TOPSZ]; - dtostrfd(value, decimals, stemp1); - Response_P(S_JSON_COMMAND_XVALUE, XdrvMailbox.command, stemp1); // Return float value without quotes + Response_P(PSTR("{\"%s\":%*_f}"), XdrvMailbox.command, decimals, &value); // Return float value without quotes } void ResponseCmndIdxNumber(int value) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 5e8a487a0..0f7a14476 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -783,11 +783,15 @@ void WSContentSpaceButton(uint32_t title_index) WSContentButton(title_index); } +void WSContentSend_Temp(const char *types, float f_temperature) { + WSContentSend_PD(HTTP_SNS_F_TEMP, types, Settings.flag2.temperature_resolution, &f_temperature, TempUnit()); +} + void WSContentSend_THD(const char *types, float f_temperature, float f_humidity) { + WSContentSend_Temp(types, f_temperature); + char parameter[FLOATSZ]; - dtostrfd(f_temperature, Settings.flag2.temperature_resolution, parameter); - WSContentSend_PD(HTTP_SNS_TEMP, types, parameter, TempUnit()); dtostrfd(f_humidity, Settings.flag2.humidity_resolution, parameter); WSContentSend_PD(HTTP_SNS_HUM, types, parameter); dtostrfd(CalcTempHumToDew(f_temperature, f_humidity), Settings.flag2.temperature_resolution, parameter); diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 8dcddb380..1f8da77e1 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -1303,7 +1303,7 @@ void TuyaSensorsShow(bool json) if (TuyaGetDpId(sensor) != 0) { switch (sensor) { case 71: - WSContentSend_PD(HTTP_SNS_TEMP, "", dtostrfd(Tuya.Sensors[0], Settings.flag2.temperature_resolution, tempval), TempUnit()); + WSContentSend_Temp("", Tuya.Sensors[0]); break; case 72: WSContentSend_PD(PSTR("{s}" D_TEMPERATURE " Set{m}%s " D_UNIT_DEGREE "%c{e}"), diff --git a/tasmota/xnrg_12_solaxX1.ino b/tasmota/xnrg_12_solaxX1.ino index c6af1f770..76b699b03 100644 --- a/tasmota/xnrg_12_solaxX1.ino +++ b/tasmota/xnrg_12_solaxX1.ino @@ -435,8 +435,6 @@ void solaxX1Show(bool json) char pv2_power[33]; dtostrfd(solaxX1.dc2_power, Settings.flag2.wattage_resolution, pv2_power); #endif - char temperature[33]; - dtostrfd(solaxX1.temperature, Settings.flag2.temperature_resolution, temperature); char runtime[33]; dtostrfd(solaxX1.runtime_total, 0, runtime); char status[33]; @@ -450,12 +448,12 @@ void solaxX1Show(bool json) ResponseAppend_P(PSTR(",\"" D_JSON_PV2_VOLTAGE "\":%s,\"" D_JSON_PV2_CURRENT "\":%s,\"" D_JSON_PV2_POWER "\":%s"), pv2_voltage, pv2_current, pv2_power); #endif - ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_RUNTIME "\":%s,\"" D_JSON_STATUS "\":\"%s\",\"" D_JSON_ERROR "\":%d"), - temperature, runtime, status, solaxX1.errorCode); + ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE "\":%*_f,\"" D_JSON_RUNTIME "\":%s,\"" D_JSON_STATUS "\":\"%s\",\"" D_JSON_ERROR "\":%d"), + Settings.flag2.temperature_resolution, &solaxX1.temperature, runtime, status, solaxX1.errorCode); #ifdef USE_DOMOTICZ // Avoid bad temperature report at beginning of the day (spikes of 1200 celsius degrees) - if (0 == TasmotaGlobal.tele_period && solaxX1.temperature < 100) { DomoticzSensor(DZ_TEMP, temperature); } + if (0 == TasmotaGlobal.tele_period && solaxX1.temperature < 100) { DomoticzFloatSensor(DZ_TEMP, solaxX1.temperature); } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER @@ -464,7 +462,7 @@ void solaxX1Show(bool json) #ifdef SOLAXX1_PV2 WSContentSend_PD(HTTP_SNS_solaxX1_DATA2, pv2_voltage, pv2_current, pv2_power); #endif - WSContentSend_PD(HTTP_SNS_TEMP, D_SOLAX_X1, temperature, TempUnit()); + WSContentSend_Temp(D_SOLAX_X1, solaxX1.temperature); char errorCodeString[33]; WSContentSend_PD(HTTP_SNS_solaxX1_DATA3, runtime, status, GetTextIndexed(errorCodeString, sizeof(errorCodeString), solaxX1_ParseErrorCode(solaxX1.errorCode), kSolaxError)); diff --git a/tasmota/xnrg_14_bl0940.ino b/tasmota/xnrg_14_bl0940.ino index 20df87f1a..81a9d4791 100644 --- a/tasmota/xnrg_14_bl0940.ino +++ b/tasmota/xnrg_14_bl0940.ino @@ -268,14 +268,11 @@ bool Bl0940Command(void) { } void Bl0940Show(bool json) { - char temperature[33]; - dtostrfd(Bl0940.temperature, Settings.flag2.temperature_resolution, temperature); - if (json) { - ResponseAppend_P(JSON_SNS_TEMP, "BL0940", temperature); + ResponseAppend_P(JSON_SNS_F_TEMP, "BL0940", Settings.flag2.temperature_resolution, &Bl0940.temperature); if (0 == TasmotaGlobal.tele_period) { #ifdef USE_DOMOTICZ - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, Bl0940.temperature); #endif // USE_DOMOTICZ #ifdef USE_KNX KnxSensor(KNX_TEMPERATURE, Bl0940.temperature); @@ -283,8 +280,9 @@ void Bl0940Show(bool json) { } #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, "", temperature, TempUnit()); + WSContentSend_Temp("", Bl0940.temperature); #endif // USE_WEBSERVER + } } diff --git a/tasmota/xsns_02_analog.ino b/tasmota/xsns_02_analog.ino index c0db2c1e5..2c8c4a4fa 100644 --- a/tasmota/xsns_02_analog.ino +++ b/tasmota/xsns_02_analog.ino @@ -457,15 +457,12 @@ void AdcShow(bool json) { break; } case ADC_TEMP: { - char temperature[33]; - dtostrfd(Adc[idx].temperature, Settings.flag2.temperature_resolution, temperature); - if (json) { AdcShowContinuation(&jsonflg); - ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "%s\":%s"), adc_idx, temperature); + ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "%s\":%*_f"), adc_idx, Settings.flag2.temperature_resolution, &Adc[idx].temperature); if ((0 == TasmotaGlobal.tele_period) && (!domo_flag[ADC_TEMP])) { #ifdef USE_DOMOTICZ - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, Adc[idx].temperature); domo_flag[ADC_TEMP] = true; #endif // USE_DOMOTICZ #ifdef USE_KNX @@ -474,7 +471,7 @@ void AdcShow(bool json) { } #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, adc_name, temperature, TempUnit()); + WSContentSend_Temp(adc_name, Adc[idx].temperature); #endif // USE_WEBSERVER } break; diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index 876d328be..f5cd6a3f9 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -499,9 +499,6 @@ void Ds18x20Show(bool json) uint8_t index = ds18x20_sensor[i].index; if (ds18x20_sensor[index].valid) { // Check for valid temperature - char temperature[33]; - dtostrfd(ds18x20_sensor[index].temperature, Settings.flag2.temperature_resolution, temperature); - Ds18x20Name(i); if (json) { @@ -509,10 +506,11 @@ void Ds18x20Show(bool json) for (uint32_t j = 0; j < 6; j++) { sprintf(address+2*j, "%02X", ds18x20_sensor[index].address[6-j]); // Skip sensor type and crc } - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, address, temperature); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%*_f}"), + ds18x20_types, address, Settings.flag2.temperature_resolution, &ds18x20_sensor[index].temperature); #ifdef USE_DOMOTICZ if ((0 == TasmotaGlobal.tele_period) && (0 == i)) { - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, ds18x20_sensor[index].temperature); } #endif // USE_DOMOTICZ #ifdef USE_KNX @@ -522,7 +520,7 @@ void Ds18x20Show(bool json) #endif // USE_KNX #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, ds18x20_types, temperature, TempUnit()); + WSContentSend_Temp(ds18x20_types, ds18x20_sensor[index].temperature); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_05_ds18x20_esp32.ino b/tasmota/xsns_05_ds18x20_esp32.ino index 8e2b20504..4f591b36a 100644 --- a/tasmota/xsns_05_ds18x20_esp32.ino +++ b/tasmota/xsns_05_ds18x20_esp32.ino @@ -200,9 +200,6 @@ void Ds18x20Show(bool json) uint8_t dsxflg = 0; for (uint32_t i = 0; i < ds18x20_sensors; i++) { if (Ds18x20Read(i, t)) { // Check if read failed - char temperature[33]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - Ds18x20Name(i); if (json) { @@ -210,11 +207,12 @@ void Ds18x20Show(bool json) for (uint32_t j = 0; j < 6; j++) { sprintf(address+2*j, "%02X", ds18x20_address[ds18x20_index[i]][6-j]); // Skip sensor type and crc } - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, address, temperature); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%*_f}"), + ds18x20_types, address, Settings.flag2.temperature_resolution, &t); dsxflg++; #ifdef USE_DOMOTICZ if ((0 == TasmotaGlobal.tele_period) && (1 == dsxflg)) { - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, t); } #endif // USE_DOMOTICZ #ifdef USE_KNX @@ -224,7 +222,7 @@ void Ds18x20Show(bool json) #endif // USE_KNX #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, ds18x20_types, temperature, TempUnit()); + WSContentSend_Temp(ds18x20_types, t); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_09_bmp.ino b/tasmota/xsns_09_bmp.ino index b30615107..3b472dceb 100644 --- a/tasmota/xsns_09_bmp.ino +++ b/tasmota/xsns_09_bmp.ino @@ -527,8 +527,6 @@ void BmpShow(bool json) snprintf_P(name, sizeof(name), PSTR("%s%c%02X"), name, IndexSeparator(), bmp_sensors[bmp_idx].bmp_address); // BMXXXX-XX } - char temperature[33]; - dtostrfd(bmp_temperature, Settings.flag2.temperature_resolution, temperature); char pressure[33]; dtostrfd(bmp_pressure, Settings.flag2.pressure_resolution, pressure); char sea_pressure[33]; @@ -554,16 +552,16 @@ void BmpShow(bool json) char json_gas[40]; snprintf_P(json_gas, sizeof(json_gas), PSTR(",\"" D_JSON_GAS "\":%s"), gas_resistance); - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s,\"" D_JSON_PRESSURE "\":%s%s%s}"), + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f%s,\"" D_JSON_PRESSURE "\":%s%s%s}"), name, - temperature, + Settings.flag2.temperature_resolution, &bmp_temperature, (bmp_sensors[bmp_idx].bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : "", (bmp_sensors[bmp_idx].bmp_model >= 3) ? json_gas : ""); #else - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s,\"" D_JSON_PRESSURE "\":%s%s}"), - name, temperature, (bmp_sensors[bmp_idx].bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : ""); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f%s,\"" D_JSON_PRESSURE "\":%s%s}"), + name, Settings.flag2.temperature_resolution, &bmp_temperature, (bmp_sensors[bmp_idx].bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : ""); #endif // USE_BME680 #ifdef USE_DOMOTICZ @@ -584,7 +582,7 @@ void BmpShow(bool json) #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, name, temperature, TempUnit()); + WSContentSend_Temp(name, bmp_temperature); if (bmp_sensors[bmp_idx].bmp_model >= 2) { WSContentSend_PD(HTTP_SNS_HUM, name, humidity); WSContentSend_PD(HTTP_SNS_DEW, name, dewpoint, TempUnit()); diff --git a/tasmota/xsns_15_mhz19.ino b/tasmota/xsns_15_mhz19.ino index bfde603a1..1536fbd25 100644 --- a/tasmota/xsns_15_mhz19.ino +++ b/tasmota/xsns_15_mhz19.ino @@ -338,23 +338,22 @@ void MhzInit(void) void MhzShow(bool json) { char types[7] = "MHZ19B"; // MHZ19B for legacy reasons. Prefered is MHZ19 - char temperature[33]; - dtostrfd(mhz_temperature, Settings.flag2.temperature_resolution, temperature); char model[3]; GetTextIndexed(model, sizeof(model), mhz_type -1, kMhzModels); if (json) { - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_MODEL "\":\"%s\",\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s}"), types, model, mhz_last_ppm, temperature); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_MODEL "\":\"%s\",\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%*_f}"), + types, model, mhz_last_ppm, Settings.flag2.temperature_resolution, &mhz_temperature); #ifdef USE_DOMOTICZ if (0 == TasmotaGlobal.tele_period) { DomoticzSensor(DZ_AIRQUALITY, mhz_last_ppm); - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, mhz_temperature); } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_CO2, types, mhz_last_ppm); - WSContentSend_PD(HTTP_SNS_TEMP, types, temperature, TempUnit()); + WSContentSend_Temp(types, mhz_temperature); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_26_lm75ad.ino b/tasmota/xsns_26_lm75ad.ino index 4f65f3d51..73c6140cc 100644 --- a/tasmota/xsns_26_lm75ad.ino +++ b/tasmota/xsns_26_lm75ad.ino @@ -85,17 +85,15 @@ float LM75ADGetTemp(void) void LM75ADShow(bool json) { float t = LM75ADGetTemp(); - char temperature[33]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); if (json) { - ResponseAppend_P(JSON_SNS_TEMP, "LM75AD", temperature); + ResponseAppend_P(JSON_SNS_F_TEMP, "LM75AD", Settings.flag2.temperature_resolution, &t); #ifdef USE_DOMOTICZ - if (0 == TasmotaGlobal.tele_period) DomoticzSensor(DZ_TEMP, temperature); + if (0 == TasmotaGlobal.tele_period) DomoticzFloatSensor(DZ_TEMP, t); #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, "LM75AD", temperature, TempUnit()); + WSContentSend_Temp("LM75AD", t); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_32_mpu6050.ino b/tasmota/xsns_32_mpu6050.ino index b8d4c4d62..e0e738417 100644 --- a/tasmota/xsns_32_mpu6050.ino +++ b/tasmota/xsns_32_mpu6050.ino @@ -182,8 +182,6 @@ void MPU_6050Show(bool json) MPU_6050PerformReading(); float tempConv = ConvertTemp(MPU_6050_temperature / 340.0 + 35.53); - char temperature[33]; - dtostrfd(tempConv, Settings.flag2.temperature_resolution, temperature); char axis_ax[33]; dtostrfd(MPU_6050_ax, Settings.flag2.axis_resolution, axis_ax); char axis_ay[33]; @@ -225,19 +223,19 @@ void MPU_6050Show(bool json) snprintf_P(json_ypr_p, sizeof(json_ypr_p), PSTR(",\"" D_JSON_PITCH "\":%s"), axis_pitch); char json_ypr_r[25]; snprintf_P(json_ypr_r, sizeof(json_ypr_r), PSTR(",\"" D_JSON_ROLL "\":%s"), axis_roll); - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s%s%s%s%s%s%s%s%s}"), - D_SENSOR_MPU6050, temperature, json_axis_ax, json_axis_ay, json_axis_az, json_axis_gx, json_axis_gy, json_axis_gz, + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f%s%s%s%s%s%s%s%s%s}"), + D_SENSOR_MPU6050, Settings.flag2.temperature_resolution, &tempConv, json_axis_ax, json_axis_ay, json_axis_az, json_axis_gx, json_axis_gy, json_axis_gz, json_ypr_y, json_ypr_p, json_ypr_r); #else - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s%s%s%s%s%s}"), - D_SENSOR_MPU6050, temperature, json_axis_ax, json_axis_ay, json_axis_az, json_axis_gx, json_axis_gy, json_axis_gz); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f%s%s%s%s%s%s}"), + D_SENSOR_MPU6050, Settings.flag2.temperature_resolution, &tempConv, json_axis_ax, json_axis_ay, json_axis_az, json_axis_gx, json_axis_gy, json_axis_gz); #endif // USE_MPU6050_DMP #ifdef USE_DOMOTICZ - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, tempConv); #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, D_SENSOR_MPU6050, temperature, TempUnit()); + WSContentSend_Temp(D_SENSOR_MPU6050, tempConv); WSContentSend_PD(HTTP_SNS_AXIS, axis_ax, axis_ay, axis_az, axis_gx, axis_gy, axis_gz); #ifdef USE_MPU6050_DMP WSContentSend_PD(HTTP_SNS_YPR, axis_yaw, axis_pitch, axis_roll); diff --git a/tasmota/xsns_37_rfsensor.ino b/tasmota/xsns_37_rfsensor.ino index 66dcf17d4..424928a4a 100644 --- a/tasmota/xsns_37_rfsensor.ino +++ b/tasmota/xsns_37_rfsensor.ino @@ -272,22 +272,21 @@ void RfSnsTheoV2Show(bool json) sensor, GetDT(rfsns_theo_v2_t1[i].time).c_str(), voltage); } } else { - char temperature[33]; - dtostrfd(ConvertTemp((float)rfsns_theo_v2_t1[i].temp / 100), Settings.flag2.temperature_resolution, temperature); + float temp = ConvertTemp((float)rfsns_theo_v2_t1[i].temp / 100) if (json) { - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_ILLUMINANCE "\":%d,\"" D_JSON_VOLTAGE "\":%s}"), - sensor, temperature, rfsns_theo_v2_t1[i].lux, voltage); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f,\"" D_JSON_ILLUMINANCE "\":%d,\"" D_JSON_VOLTAGE "\":%s}"), + sensor, Settings.flag2.temperature_resolution, &temp, rfsns_theo_v2_t1[i].lux, voltage); #ifdef USE_DOMOTICZ if ((0 == TasmotaGlobal.tele_period) && !sensor_once) { - DomoticzSensor(DZ_TEMP, temperature); + DomoticzFloatSensor(DZ_TEMP, temp); DomoticzSensor(DZ_ILLUMINANCE, rfsns_theo_v2_t1[i].lux); sensor_once = true; } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, sensor, temperature, TempUnit()); + WSContentSend_Temp(sensor, temp); WSContentSend_PD(HTTP_SNS_ILLUMINANCE, sensor, rfsns_theo_v2_t1[i].lux); #endif // USE_WEBSERVER } diff --git a/tasmota/xsns_39_max31855.ino b/tasmota/xsns_39_max31855.ino index 2a6304ce1..fafa9f0de 100644 --- a/tasmota/xsns_39_max31855.ino +++ b/tasmota/xsns_39_max31855.ino @@ -139,20 +139,18 @@ void MAX31855_GetResult(void) { } void MAX31855_Show(bool Json) { - char probetemp[33]; - char referencetemp[33]; - dtostrfd(MAX31855_Result.ProbeTemperature, Settings.flag2.temperature_resolution, probetemp); - dtostrfd(MAX31855_Result.ReferenceTemperature, Settings.flag2.temperature_resolution, referencetemp); - char sensor_name[10]; GetTextIndexed(sensor_name, sizeof(sensor_name), Settings.flag4.max6675, kMax31855Types); if (Json) { - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_PROBETEMPERATURE "\":%s,\"" D_JSON_REFERENCETEMPERATURE "\":%s,\"" D_JSON_ERROR "\":%d}"), \ - sensor_name, probetemp, referencetemp, MAX31855_Result.ErrorCode); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_PROBETEMPERATURE "\":%*_f,\"" D_JSON_REFERENCETEMPERATURE "\":%*_f,\"" D_JSON_ERROR "\":%d}"), \ + sensor_name, + Settings.flag2.temperature_resolution, &MAX31855_Result.ProbeTemperature, + Settings.flag2.temperature_resolution, &MAX31855_Result.ReferenceTemperature, + MAX31855_Result.ErrorCode); #ifdef USE_DOMOTICZ if (0 == TasmotaGlobal.tele_period) { - DomoticzSensor(DZ_TEMP, probetemp); + DomoticzFloatSensor(DZ_TEMP, MAX31855_Result.ProbeTemperature); } #endif // USE_DOMOTICZ #ifdef USE_KNX @@ -162,7 +160,7 @@ void MAX31855_Show(bool Json) { #endif // USE_KNX #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, sensor_name, probetemp, TempUnit()); + WSContentSend_Temp(sensor_name, MAX31855_Result.ProbeTemperature); #endif // USE_WEBSERVER } }