6.4.0.2 Fix possible dtostrf bos

6.4.0.2 20181221
 * Fix possible dtostrf buffer overflows by increasing buffers
This commit is contained in:
Theo Arends 2018-12-21 16:17:06 +01:00
parent a80fcd98d7
commit c1102a4863
31 changed files with 137 additions and 148 deletions

View File

@ -1,4 +1,7 @@
/* 6.4.0.1 20181217
/* 6.4.0.2 20181221
* Fix possible dtostrf buffer overflows by increasing buffers
*
* 6.4.0.1 20181217
* Add support for AZ-Instrument 7798 CO2 meter/datalogger (#4672)
* Change RAM usage BMP/BME I2C sensors
* Fix wifi strongest signal detection (#4704)

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06040001
#define VERSION 0x06040002
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"

View File

@ -402,12 +402,11 @@ boolean EnergyCommand(void)
break;
}
}
char energy_yesterday_chr[10];
char energy_daily_chr[10];
char energy_total_chr[10];
char energy_total_chr[33];
dtostrfd(energy_total, Settings.flag2.energy_resolution, energy_total_chr);
char energy_daily_chr[33];
dtostrfd(energy_daily, Settings.flag2.energy_resolution, energy_daily_chr);
char energy_yesterday_chr[33];
dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":{\"" D_JSON_TOTAL "\":%s,\"" D_JSON_YESTERDAY "\":%s,\"" D_JSON_TODAY "\":%s}}"),
@ -549,18 +548,6 @@ const char HTTP_ENERGY_SNS4[] PROGMEM = "%s"
void EnergyShow(boolean json)
{
char voltage_chr[10];
char current_chr[10];
char active_power_chr[10];
char apparent_power_chr[10];
char reactive_power_chr[10];
char power_factor_chr[10];
char frequency_chr[10];
char energy_daily_chr[10];
char energy_period_chr[10];
char energy_yesterday_chr[10];
char energy_total_chr[10];
char speriod[20];
char sfrequency[20];
@ -568,6 +555,10 @@ void EnergyShow(boolean json)
float power_factor = energy_power_factor;
char apparent_power_chr[33];
char reactive_power_chr[33];
char power_factor_chr[33];
char frequency_chr[33];
if (!energy_type_dc) {
float apparent_power = energy_apparent_power;
if (isnan(apparent_power)) {
@ -602,14 +593,21 @@ void EnergyShow(boolean json)
}
}
char voltage_chr[33];
dtostrfd(energy_voltage, Settings.flag2.voltage_resolution, voltage_chr);
char current_chr[33];
dtostrfd(energy_current, Settings.flag2.current_resolution, current_chr);
char active_power_chr[33];
dtostrfd(energy_active_power, Settings.flag2.wattage_resolution, active_power_chr);
char energy_daily_chr[33];
dtostrfd(energy_daily, Settings.flag2.energy_resolution, energy_daily_chr);
char energy_yesterday_chr[33];
dtostrfd((float)Settings.energy_kWhyesterday / 100000, Settings.flag2.energy_resolution, energy_yesterday_chr);
char energy_total_chr[33];
dtostrfd(energy_total, Settings.flag2.energy_resolution, energy_total_chr);
float energy = 0;
char energy_period_chr[33];
if (show_energy_period) {
if (energy_period) energy = (float)(energy_kWhtoday - energy_period) / 100;
energy_period = energy_kWhtoday;

View File

@ -488,7 +488,7 @@ boolean TimerCommand(void)
if (XdrvMailbox.data_len) {
Settings.longitude = (int)(CharToDouble(XdrvMailbox.data) *1000000);
}
char lbuff[32];
char lbuff[33];
dtostrfd(((double)Settings.longitude) /1000000, 6, lbuff);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, lbuff);
}
@ -496,7 +496,7 @@ boolean TimerCommand(void)
if (XdrvMailbox.data_len) {
Settings.latitude = (int)(CharToDouble(XdrvMailbox.data) *1000000);
}
char lbuff[32];
char lbuff[33];
dtostrfd(((double)Settings.latitude) /1000000, 6, lbuff);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, lbuff);
}

View File

@ -94,7 +94,7 @@ uint8_t rules_trigger_count[MAX_RULE_SETS] = { 0 };
uint8_t rules_teleperiod = 0;
char event_data[100];
char vars[MAX_RULE_VARS][10] = { 0 };
char vars[MAX_RULE_VARS][33] = { 0 };
/*******************************************************************************************/

View File

@ -551,7 +551,7 @@ void KNX_CB_Action(message_t const &msg, void *arg)
device_parameters_t *chan = (device_parameters_t *)arg;
if (!(Settings.flag.knx_enabled)) { return; }
char tempchar[25];
char tempchar[33];
if (msg.data_len == 1) {
// COMMAND

View File

@ -93,12 +93,12 @@ const char HTTP_SNS_COUNTER[] PROGMEM =
void CounterShow(boolean json)
{
char stemp[10];
char counter[16];
byte dsxflg = 0;
byte header = 0;
for (byte i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
char counter[33];
if (bitRead(Settings.pulse_counter_type, i)) {
dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter);
} else {

View File

@ -113,12 +113,12 @@ const char HTTP_SNS_SCPLUS[] PROGMEM =
void SonoffScShow(boolean json)
{
if (sc_value[0] > 0) {
char temperature[10];
char humidity[10];
float t = ConvertTemp(sc_value[1]);
float h = sc_value[0];
char temperature[33];
dtostrfd(t, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(h, Settings.flag2.humidity_resolution, humidity);
if (json) {

View File

@ -190,8 +190,7 @@ void Ds18b20EverySecond(void)
void Ds18b20Show(boolean json)
{
if (ds18b20_valid) { // Check for valid temperature
char temperature[10];
char temperature[33];
dtostrfd(ds18b20_temperature, Settings.flag2.temperature_resolution, temperature);
if(json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMP, mqtt_data, ds18b20_types, temperature);

View File

@ -424,12 +424,11 @@ void Ds18x20EverySecond(void)
void Ds18x20Show(boolean json)
{
char temperature[10];
for (uint8_t i = 0; i < ds18x20_sensors; i++) {
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);

View File

@ -170,7 +170,6 @@ void Ds18x20Type(uint8_t sensor)
void Ds18x20Show(boolean json)
{
char temperature[10];
char stemp[10];
float t;
@ -178,6 +177,7 @@ void Ds18x20Show(boolean json)
for (byte i = 0; i < Ds18x20Sensors(); i++) {
if (Ds18x20Read(i, t)) { // Check if read failed
Ds18x20Type(i);
char temperature[33];
dtostrfd(t, Settings.flag2.temperature_resolution, temperature);
if (json) {

View File

@ -207,11 +207,10 @@ void DhtEverySecond(void)
void DhtShow(boolean json)
{
char temperature[10];
char humidity[10];
for (byte i = 0; i < dht_sensors; i++) {
char temperature[33];
dtostrfd(Dht[i].t, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(Dht[i].h, Settings.flag2.humidity_resolution, humidity);
if (json) {

View File

@ -188,10 +188,9 @@ void ShtEverySecond(void)
void ShtShow(boolean json)
{
if (sht_valid) {
char temperature[10];
char humidity[10];
char temperature[33];
dtostrfd(sht_temperature, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(sht_humidity, Settings.flag2.humidity_resolution, humidity);
if (json) {

View File

@ -249,10 +249,9 @@ void HtuEverySecond(void)
void HtuShow(boolean json)
{
if (htu_valid) {
char temperature[10];
char humidity[10];
char temperature[33];
dtostrfd(htu_temperature, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(htu_humidity, Settings.flag2.humidity_resolution, humidity);
if (json) {

View File

@ -46,15 +46,15 @@ const char kBmpTypes[] PROGMEM = "BMP180|BMP280|BME280|BME680";
typedef struct {
uint8_t bmp_address; // I2C bus address
char bmp_name[7]; // Sensor name - "BMPXXX"
uint8_t bmp_type = 0;
uint8_t bmp_model = 0;
uint8_t bmp_type;
uint8_t bmp_model;
#ifdef USE_BME680
uint8_t bme680_state = 0;
float bmp_gas_resistance = 0.0;
uint8_t bme680_state;
float bmp_gas_resistance;
#endif // USE_BME680
float bmp_temperature = 0.0;
float bmp_pressure = 0.0;
float bmp_humidity = 0.0;
float bmp_temperature;
float bmp_pressure;
float bmp_humidity;
} bmp_sensors_t;
uint8_t bmp_addresses[] = { BMP_ADDR1, BMP_ADDR2 };
@ -448,10 +448,12 @@ void BmpDetect(void)
{
if (bmp_count) return;
int bmp_sensor_size = BMP_MAX_SENSORS * sizeof(bmp_sensors_t);
if (!bmp_sensors) {
bmp_sensors = (bmp_sensors_t*)malloc(BMP_MAX_SENSORS * sizeof(bmp_sensors_t));
bmp_sensors = (bmp_sensors_t*)malloc(bmp_sensor_size);
}
if (!bmp_sensors) { return; }
memset(bmp_sensors, 0, bmp_sensor_size); // Init defaults to 0
for (byte i = 0; i < BMP_MAX_SENSORS; i++) {
uint8_t bmp_type = I2cRead8(bmp_addresses[i], BMP_REGISTER_CHIPID);
@ -530,12 +532,6 @@ void BmpShow(boolean json)
for (byte bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
if (bmp_sensors[bmp_idx].bmp_type) {
float bmp_sealevel = 0.0;
char temperature[10];
char pressure[10];
char sea_pressure[10];
char humidity[10];
char name[10];
if (bmp_sensors[bmp_idx].bmp_pressure != 0.0) {
bmp_sealevel = (bmp_sensors[bmp_idx].bmp_pressure / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0), 5.255)) - 21.6;
bmp_sealevel = ConvertPressure(bmp_sealevel);
@ -543,17 +539,22 @@ void BmpShow(boolean json)
float bmp_temperature = ConvertTemp(bmp_sensors[bmp_idx].bmp_temperature);
float bmp_pressure = ConvertPressure(bmp_sensors[bmp_idx].bmp_pressure);
char name[10];
snprintf(name, sizeof(name), bmp_sensors[bmp_idx].bmp_name);
if (bmp_count > 1) {
snprintf_P(name, sizeof(name), PSTR("%s-%02X"), name, 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];
dtostrfd(bmp_sealevel, Settings.flag2.pressure_resolution, sea_pressure);
char humidity[33];
dtostrfd(bmp_sensors[bmp_idx].bmp_humidity, Settings.flag2.humidity_resolution, humidity);
#ifdef USE_BME680
char gas_resistance[10];
char gas_resistance[33];
dtostrfd(bmp_sensors[bmp_idx].bmp_gas_resistance, 2, gas_resistance);
#endif // USE_BME680
@ -566,17 +567,14 @@ void BmpShow(boolean json)
char json_gas[40];
snprintf_P(json_gas, sizeof(json_gas), PSTR(",\"" D_JSON_GAS "\":%s"), gas_resistance);
snprintf_P(mqtt_data,
sizeof(mqtt_data),
PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s,\"" D_JSON_PRESSURE "\":%s%s%s}"),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s,\"" D_JSON_PRESSURE "\":%s%s%s}"),
mqtt_data,
name,
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 : ""
);
(bmp_sensors[bmp_idx].bmp_model >= 3) ? json_gas : "");
#else
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"%s\":{\"" D_JSON_TEMPERATURE "\":%s%s,\"" D_JSON_PRESSURE "\":%s%s}"),
mqtt_data, name, temperature, (bmp_sensors[bmp_idx].bmp_model >= 2) ? json_humidity : "", pressure, (Settings.altitude != 0) ? json_sealevel : "");

View File

@ -273,12 +273,12 @@ double Veml6070UvPower(double uvrisk)
void Veml6070Show(boolean json)
{
if (veml6070_type) {
char str_uvlevel[6]; // e.g. 99999 inc = UVLevel
char str_uvrisk[6]; // e.g. 25.99 text = UvIndex
char str_uvpower[6]; // e.g. 0.399 W/m² = UvPower
// convert double values to string
char str_uvlevel[33]; // e.g. 99999 inc = UVLevel
dtostrfd((double)uvlevel, 0, str_uvlevel);
char str_uvrisk[33]; // e.g. 25.99 text = UvIndex
dtostrfd(uvrisk, 2, str_uvrisk);
char str_uvpower[33]; // e.g. 0.399 W/m² = UvPower
dtostrfd(uvpower, 3, str_uvpower);
if (json) {
#ifdef USE_VEML6070_SHOW_RAW

View File

@ -232,13 +232,12 @@ const char HTTP_SNS_INA219_DATA[] PROGMEM = "%s"
void Ina219Show(boolean json)
{
if (ina219_valid) {
char voltage[10];
char current[10];
char power[10];
float fpower = ina219_voltage * ina219_current;
char voltage[33];
dtostrfd(ina219_voltage, Settings.flag2.voltage_resolution, voltage);
char power[33];
dtostrfd(fpower, Settings.flag2.wattage_resolution, power);
char current[33];
dtostrfd(ina219_current, Settings.flag2.current_resolution, current);
if (json) {

View File

@ -98,15 +98,15 @@ void Sht3xShow(boolean json)
if (sht3x_count) {
float t;
float h;
char temperature[10];
char humidity[10];
char types[11];
for (byte i = 0; i < sht3x_count; i++) {
if (Sht3xRead(t, h, sht3x_sensors[i].address)) {
if (0 == i) { SetGlobalValues(t, h); }
char temperature[33];
dtostrfd(t, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(h, Settings.flag2.humidity_resolution, humidity);
snprintf_P(types, sizeof(types), PSTR("%s-0x%02X"), sht3x_sensors[i].types, sht3x_sensors[i].address); // "SHT3X-0xXX"

View File

@ -322,7 +322,7 @@ void MhzInit(void)
void MhzShow(boolean json)
{
char temperature[10];
char temperature[33];
dtostrfd(mhz_temperature, Settings.flag2.temperature_resolution, temperature);
GetTextIndexed(mhz_types, sizeof(mhz_types), mhz_type -1, kMhzTypes);

View File

@ -147,9 +147,9 @@ void SenseairInit(void)
void SenseairShow(boolean json)
{
char temperature[10];
char humidity[10];
char temperature[33];
dtostrfd(senseair_temperature, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(senseair_humidity, Settings.flag2.temperature_resolution, humidity);
GetTextIndexed(senseair_types, sizeof(senseair_types), senseair_type -1, kSenseairTypes);

View File

@ -63,7 +63,7 @@ const char HTTP_MGS_GAS[] PROGMEM = "%s{s}MGS %s{m}%s " D_UNIT_PARTS_PER_MILLION
void MGSShow(boolean json)
{
char buffer[25];
char buffer[33];
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"MGS\":{\"NH3\":%s"), mqtt_data, measure_gas(NH3, buffer));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"CO\":%s"), mqtt_data, measure_gas(CO, buffer));

View File

@ -189,11 +189,11 @@ const char HTTP_SDS0X1_SNS[] PROGMEM = "%s"
void NovaSdsShow(boolean json)
{
if (novasds_valid) {
char pm10[10];
char pm2_5[10];
float pm10f = (float)(novasds_data.pm100) / 10.0f;
float pm2_5f = (float)(novasds_data.pm25) / 10.0f;
char pm10[33];
dtostrfd(pm10f, 1, pm10);
char pm2_5[33];
dtostrfd(pm2_5f, 1, pm2_5);
if (json) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SDS0X1\":{\"PM2.5\":%s,\"PM10\":%s}"), mqtt_data, pm2_5, pm10);

View File

@ -51,8 +51,7 @@ void Sr04Show(boolean json)
distance = (real64_t)(sonar->ping_median(5))/ US_ROUNDTRIP_CM;
if (distance != 0) { // Check if read failed
char distance_chr[10];
char distance_chr[33];
dtostrfd(distance, 3, distance_chr);
if(json) {

View File

@ -203,28 +203,28 @@ void SDM120250ms(void) // Every 250 mSec
#ifdef USE_SDM220
case 8:
sdm120_phase_angle = value;
break;
break;
case 9:
sdm120_import_active = value;
break;
break;
case 10:
sdm120_export_active = value;
break;
break;
case 11:
sdm120_import_reactive = value;
break;
break;
case 12:
sdm120_export_reactive = value;
break;
break;
case 13:
sdm120_total_reactive = value;
break;
#endif // USE_SDM220
break;
#endif // USE_SDM220
} // end switch
sdm120_read_state++;
@ -283,35 +283,34 @@ const char HTTP_SNS_SDM120_DATA[] PROGMEM = "%s"
void SDM120Show(boolean json)
{
char voltage[10];
char current[10];
char active_power[10];
char apparent_power[10];
char reactive_power[10];
char power_factor[10];
char frequency[10];
char energy_total[10];
char phase_angle[10];
char import_active[10];
char export_active[10];
char import_reactive[10];
char export_reactive[10];
char total_reactive[10];
char voltage[33];
dtostrfd(sdm120_voltage, Settings.flag2.voltage_resolution, voltage);
char current[33];
dtostrfd(sdm120_current, Settings.flag2.current_resolution, current);
char active_power[33];
dtostrfd(sdm120_active_power, Settings.flag2.wattage_resolution, active_power);
char apparent_power[33];
dtostrfd(sdm120_apparent_power, Settings.flag2.wattage_resolution, apparent_power);
char reactive_power[33];
dtostrfd(sdm120_reactive_power, Settings.flag2.wattage_resolution, reactive_power);
char power_factor[33];
dtostrfd(sdm120_power_factor, 2, power_factor);
char frequency[33];
dtostrfd(sdm120_frequency, Settings.flag2.frequency_resolution, frequency);
char energy_total[33];
dtostrfd(sdm120_energy_total, Settings.flag2.energy_resolution, energy_total);
#ifdef USE_SDM220
char phase_angle[33];
dtostrfd(sdm120_phase_angle, 2, phase_angle);
char import_active[33];
dtostrfd(sdm120_import_active, Settings.flag2.wattage_resolution, import_active);
char export_active[33];
dtostrfd(sdm120_export_active, Settings.flag2.wattage_resolution, export_active);
char import_reactive[33];
dtostrfd(sdm120_import_reactive,Settings.flag2.wattage_resolution, import_reactive);
char export_reactive[33];
dtostrfd(sdm120_export_reactive,Settings.flag2.wattage_resolution, export_reactive);
char total_reactive[33];
dtostrfd(sdm120_total_reactive, Settings.flag2.wattage_resolution, total_reactive);
#endif // USE_SDM220
if (json) {

View File

@ -269,38 +269,37 @@ const char HTTP_SNS_SDM630_DATA[] PROGMEM = "%s"
void SDM630Show(boolean json)
{
char voltage_l1[10];
char voltage_l2[10];
char voltage_l3[10];
char current_l1[10];
char current_l2[10];
char current_l3[10];
char active_power_l1[10];
char active_power_l2[10];
char active_power_l3[10];
char reactive_power_l1[10];
char reactive_power_l2[10];
char reactive_power_l3[10];
char power_factor_l1[10];
char power_factor_l2[10];
char power_factor_l3[10];
char energy_total[10];
char voltage_l1[33];
dtostrfd(sdm630_voltage[0], Settings.flag2.voltage_resolution, voltage_l1);
char voltage_l2[33];
dtostrfd(sdm630_voltage[1], Settings.flag2.voltage_resolution, voltage_l2);
char voltage_l3[33];
dtostrfd(sdm630_voltage[2], Settings.flag2.voltage_resolution, voltage_l3);
char current_l1[33];
dtostrfd(sdm630_current[0], Settings.flag2.current_resolution, current_l1);
char current_l2[33];
dtostrfd(sdm630_current[1], Settings.flag2.current_resolution, current_l2);
char current_l3[33];
dtostrfd(sdm630_current[2], Settings.flag2.current_resolution, current_l3);
char active_power_l1[33];
dtostrfd(sdm630_active_power[0], Settings.flag2.wattage_resolution, active_power_l1);
char active_power_l2[33];
dtostrfd(sdm630_active_power[1], Settings.flag2.wattage_resolution, active_power_l2);
char active_power_l3[33];
dtostrfd(sdm630_active_power[2], Settings.flag2.wattage_resolution, active_power_l3);
char reactive_power_l1[33];
dtostrfd(sdm630_reactive_power[0], Settings.flag2.wattage_resolution, reactive_power_l1);
char reactive_power_l2[33];
dtostrfd(sdm630_reactive_power[1], Settings.flag2.wattage_resolution, reactive_power_l2);
char reactive_power_l3[33];
dtostrfd(sdm630_reactive_power[2], Settings.flag2.wattage_resolution, reactive_power_l3);
char power_factor_l1[33];
dtostrfd(sdm630_power_factor[0], 2, power_factor_l1);
char power_factor_l2[33];
dtostrfd(sdm630_power_factor[1], 2, power_factor_l2);
char power_factor_l3[33];
dtostrfd(sdm630_power_factor[2], 2, power_factor_l3);
char energy_total[33];
dtostrfd(sdm630_energy_total, Settings.flag2.energy_resolution, energy_total);
if (json) {

View File

@ -81,9 +81,8 @@ float LM75ADGetTemp(void) {
void LM75ADShow(boolean json)
{
if (lm75ad_type) {
char temperature[10];
float t = LM75ADGetTemp();
char temperature[33];
dtostrfd(t, Settings.flag2.temperature_resolution, temperature);
if (json) {

View File

@ -177,19 +177,19 @@ void MPU_6050Show(boolean json)
MPU_6050PerformReading();
double tempConv = (MPU_6050_temperature / 340.0 + 35.53);
char temperature[10];
char temperature[33];
dtostrfd(tempConv, Settings.flag2.temperature_resolution, temperature);
char axis_ax[10];
char axis_ax[33];
dtostrfd(MPU_6050_ax, Settings.flag2.axis_resolution, axis_ax);
char axis_ay[10];
char axis_ay[33];
dtostrfd(MPU_6050_ay, Settings.flag2.axis_resolution, axis_ay);
char axis_az[10];
char axis_az[33];
dtostrfd(MPU_6050_az, Settings.flag2.axis_resolution, axis_az);
char axis_gx[10];
char axis_gx[33];
dtostrfd(MPU_6050_gx, Settings.flag2.axis_resolution, axis_gx);
char axis_gy[10];
char axis_gy[33];
dtostrfd(MPU_6050_gy, Settings.flag2.axis_resolution, axis_gy);
char axis_gz[10];
char axis_gz[33];
dtostrfd(MPU_6050_gz, Settings.flag2.axis_resolution, axis_gz);
if (json) {

View File

@ -204,7 +204,7 @@ bool HxCommand(void)
}
if (show_parms) {
char item[10];
char item[33];
dtostrfd((float)Settings.weight_item / 10, 1, item);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"Sensor34\":{\"" D_JSON_WEIGHT_REF "\":%d,\"" D_JSON_WEIGHT_CAL "\":%d,\"" D_JSON_WEIGHT_MAX "\":%d,\"" D_JSON_WEIGHT_ITEM "\":%s}}"),
Settings.weight_reference, Settings.weight_calibration, Settings.weight_max * 1000, item);
@ -331,7 +331,6 @@ const char HTTP_HX711_CAL[] PROGMEM = "%s"
void HxShow(boolean json)
{
char weight_chr[10];
char scount[30] = { 0 };
uint16_t count = 0;
@ -345,6 +344,7 @@ void HxShow(boolean json)
}
weight = (float)hx_weight / 1000; // kilograms
}
char weight_chr[33];
dtostrfd(weight, Settings.flag2.weight_resolution, weight_chr);
if (json) {
@ -452,10 +452,9 @@ void HxSaveSettings(void)
void HxLogUpdates(void)
{
char weigth_ref_chr[10];
char weigth_item_chr[10];
char weigth_ref_chr[33];
dtostrfd((float)Settings.weight_reference / 1000, Settings.flag2.weight_resolution, weigth_ref_chr);
char weigth_item_chr[33];
dtostrfd((float)Settings.weight_item / 10000, 4, weigth_item_chr);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_WIFI D_JSON_WEIGHT_REF " %s, " D_JSON_WEIGHT_ITEM " %s"),

View File

@ -172,14 +172,13 @@ void Tx20Init(void) {
void Tx20Show(boolean json)
{
char wind_speed_string[10];
char wind_speed_max_string[10];
char wind_speed_avg_string[10];
char wind_direction_string[4];
char wind_speed_string[33];
dtostrfd(tx20_wind_speed_kmh, 2, wind_speed_string);
char wind_speed_max_string[33];
dtostrfd(tx20_wind_speed_max, 2, wind_speed_max_string);
char wind_speed_avg_string[33];
dtostrfd(tx20_wind_speed_avg, 2, wind_speed_avg_string);
char wind_direction_string[4];
GetTextIndexed(wind_direction_string, sizeof(wind_direction_string), tx20_wind_direction, kTx20Directions);
if (json) {

View File

@ -264,7 +264,7 @@ void RfSnsTheoV2Show(bool json)
if (rfsns_theo_v2_t1[i].time) {
char sensor[10];
snprintf_P(sensor, sizeof(sensor), PSTR("TV2T1C%d"), i +1);
char voltage[10];
char voltage[33];
dtostrfd((float)rfsns_theo_v2_t1[i].volt / 10, 1, voltage);
if (rfsns_theo_v2_t1[i].time < LocalTime() - RFSNS_VALID_WINDOW) {
@ -273,7 +273,7 @@ void RfSnsTheoV2Show(bool json)
mqtt_data, sensor, GetDT(rfsns_theo_v2_t1[i].time).c_str(), voltage);
}
} else {
char temperature[10];
char temperature[33];
dtostrfd(ConvertTemp((float)rfsns_theo_v2_t1[i].temp / 100), Settings.flag2.temperature_resolution, temperature);
if (json) {
@ -301,7 +301,7 @@ void RfSnsTheoV2Show(bool json)
if (rfsns_theo_v2_t2[i].time) {
char sensor[10];
snprintf_P(sensor, sizeof(sensor), PSTR("TV2T2C%d"), i +1);
char voltage[10];
char voltage[33];
dtostrfd((float)rfsns_theo_v2_t2[i].volt / 10, 1, voltage);
if (rfsns_theo_v2_t2[i].time < LocalTime() - RFSNS_VALID_WINDOW) {
@ -311,10 +311,10 @@ void RfSnsTheoV2Show(bool json)
}
} else {
float temp = ConvertTemp((float)rfsns_theo_v2_t2[i].temp / 100);
char temperature[10];
dtostrfd(temp, Settings.flag2.temperature_resolution, temperature);
float humi = (float)rfsns_theo_v2_t2[i].hum / 100;
char humidity[10];
char temperature[33];
dtostrfd(temp, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(humi, Settings.flag2.humidity_resolution, humidity);
if (json) {
@ -559,16 +559,16 @@ void RfSnsAlectoV2Show(bool json)
}
} else {
float temp = ConvertTemp(rfsns_alecto_v2->temp);
char temperature[10];
char temperature[33];
dtostrfd(temp, Settings.flag2.temperature_resolution, temperature);
float humi = (float)rfsns_alecto_v2->humi;
char humidity[10];
char humidity[33];
dtostrfd(humi, Settings.flag2.humidity_resolution, humidity);
char rain[10];
char rain[33];
dtostrfd(rfsns_alecto_v2->rain, 2, rain);
char wind[10];
char wind[33];
dtostrfd(rfsns_alecto_v2->wind, 2, wind);
char gust[10];
char gust[33];
dtostrfd(rfsns_alecto_v2->gust, 2, gust);
char wdir[4];
char direction[20];
@ -607,6 +607,7 @@ void RfSnsInit(void)
{
rfsns_raw_signal = (raw_signal_t*)(malloc(sizeof(raw_signal_t)));
if (rfsns_raw_signal) {
memset(rfsns_raw_signal, 0, sizeof(raw_signal_t)); // Init defaults to 0
#ifdef USE_THEO_V2
RfSnsInitTheoV2();
#endif

View File

@ -254,8 +254,9 @@ void AzInit(void)
void AzShow(boolean json)
{
char temperature[10], humidity[10];
char temperature[33];
dtostrfd(az_temperature, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
dtostrfd(az_humidity, Settings.flag2.humidity_resolution, humidity);
if (json) {