mirror of https://github.com/arendst/Tasmota.git
fix floats, resolutions, and utilise common units (#17961)
This commit is contained in:
parent
208c70adf2
commit
774fbfef92
|
@ -20,12 +20,12 @@
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
#ifdef USE_SEN5X
|
#ifdef USE_SEN5X
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* SEN5X - Gas (VOC - Volatile Organic Compounds / NOx - Nitrous Oxides) and Particulates (PPM)
|
* SEN5X - Gas (VOC - Volatile Organic Compounds / NOx - Nitrous Oxides) and Particulates (PM)
|
||||||
*
|
*
|
||||||
* Source: Sensirion SEN5X Driver + Example, and Tasmota Driver 98 by Jean-Pierre Deschamps
|
* Source: Sensirion SEN5X Driver + Example, and Tasmota Driver 98 by Jean-Pierre Deschamps
|
||||||
* Adaption for TASMOTA: Tyeth Gundry
|
* Adaption for TASMOTA: Tyeth Gundry
|
||||||
*
|
*
|
||||||
* I2C Address: 0x59
|
* I2C Address: 0x69
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_103 103
|
#define XSNS_103 103
|
||||||
|
@ -39,7 +39,6 @@ SensirionI2CSen5x *sen5x = nullptr;
|
||||||
|
|
||||||
struct SEN5XDATA_s {
|
struct SEN5XDATA_s {
|
||||||
bool sen5x_ready;
|
bool sen5x_ready;
|
||||||
float abshum;
|
|
||||||
float massConcentrationPm1p0;
|
float massConcentrationPm1p0;
|
||||||
float massConcentrationPm2p5;
|
float massConcentrationPm2p5;
|
||||||
float massConcentrationPm4p0;
|
float massConcentrationPm4p0;
|
||||||
|
@ -165,17 +164,17 @@ void SEN5XUpdate(void) // Perform every second to ensure proper operation of the
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_TASMOTA_SENSOR
|
#ifdef DEBUG_TASMOTA_SENSOR
|
||||||
DEBUG_SENSOR_LOG(PSTR("SEN5x readings:-"));
|
DEBUG_SENSOR_LOG(PSTR("SEN5x readings:-"));
|
||||||
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm1p0: %f\n"), SEN5XDATA->massConcentrationPm1p0);
|
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm1p0: %1_f\n"), &SEN5XDATA->massConcentrationPm1p0);
|
||||||
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm2p5: %f\n"), SEN5XDATA->massConcentrationPm2p5);
|
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm2p5: %1_f\n"), &SEN5XDATA->massConcentrationPm2p5);
|
||||||
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm4p0: %f\n"), SEN5XDATA->massConcentrationPm4p0);
|
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm4p0: %1_f\n"), &SEN5XDATA->massConcentrationPm4p0);
|
||||||
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm10p0: %f\n"), SEN5XDATA->massConcentrationPm10p0);
|
DEBUG_SENSOR_LOG(PSTR("MassConcentrationPm10p0: %1_f\n"), &SEN5XDATA->massConcentrationPm10p0);
|
||||||
if (isnan(SEN5XDATA->ambientHumidity))
|
if (isnan(SEN5XDATA->ambientHumidity))
|
||||||
{
|
{
|
||||||
DEBUG_SENSOR_LOG(PSTR("AmbientHumidity: n/a\n"));
|
DEBUG_SENSOR_LOG(PSTR("AmbientHumidity: n/a\n"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_SENSOR_LOG(PSTR("AmbientHumidity: %f\n"), SEN5XDATA->ambientHumidity);
|
DEBUG_SENSOR_LOG(PSTR("AmbientHumidity: %*_f\n"), 2, &SEN5XDATA->ambientHumidity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isnan(SEN5XDATA->ambientTemperature))
|
if (isnan(SEN5XDATA->ambientTemperature))
|
||||||
|
@ -184,7 +183,7 @@ void SEN5XUpdate(void) // Perform every second to ensure proper operation of the
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_SENSOR_LOG(PSTR("AmbientTemperature: %f\n"), SEN5XDATA->ambientTemperature);
|
DEBUG_SENSOR_LOG(PSTR("AmbientTemperature: %*_f\n"), 2, &SEN5XDATA->ambientTemperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isnan(SEN5XDATA->vocIndex))
|
if (isnan(SEN5XDATA->vocIndex))
|
||||||
|
@ -193,7 +192,7 @@ void SEN5XUpdate(void) // Perform every second to ensure proper operation of the
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_SENSOR_LOG(PSTR("VocIndex: %f\n"), SEN5XDATA->vocIndex);
|
DEBUG_SENSOR_LOG(PSTR("VocIndex: %*_f\n"), 0, &SEN5XDATA->vocIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isnan(SEN5XDATA->noxIndex))
|
if (isnan(SEN5XDATA->noxIndex))
|
||||||
|
@ -202,19 +201,15 @@ void SEN5XUpdate(void) // Perform every second to ensure proper operation of the
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_SENSOR_LOG(PSTR("NoxIndex: %f\n"), SEN5XDATA->noxIndex);
|
DEBUG_SENSOR_LOG(PSTR("NoxIndex: %*_f\n"), 0, &SEN5XDATA->noxIndex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (!isnan(SEN5XDATA->ambientTemperature) && SEN5XDATA->ambientHumidity > 0) {
|
|
||||||
SEN5XDATA->abshum = sen5x_AbsoluteHumidity(SEN5XDATA->ambientTemperature, SEN5XDATA->ambientHumidity);
|
|
||||||
DEBUG_SENSOR_LOG(PSTR("AbsoluteHumidity: %f\n"), SEN5XDATA->abshum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
const char HTTP_SNS_SEN5X_UNITS[] PROGMEM = "{s}SEN5X %s{m}%.*f %s{e}";
|
const char HTTP_SNS_SEN5X_UNITS[] PROGMEM = "{s}SEN5X %s{m}%*_f %s{e}";
|
||||||
const char HTTP_SNS_SEN5X_UNITLESS[] PROGMEM = "{s}SEN5X %s{m}%.*f{e}";
|
const char HTTP_SNS_SEN5X_UNITLESS[] PROGMEM = "{s}SEN5X %s{m}%*_f{e}";
|
||||||
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
// {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||||
const char HTTP_SNS_AHUMSEN5X[] PROGMEM = "{s}SEN5X Abs Humidity{m}%s g/m³{e}";
|
const char HTTP_SNS_AHUMSEN5X[] PROGMEM = "{s}SEN5X Abs Humidity{m}%s g/m³{e}";
|
||||||
#endif
|
#endif
|
||||||
|
@ -223,48 +218,49 @@ const char HTTP_SNS_AHUMSEN5X[] PROGMEM = "{s}SEN5X Abs Humidity{m}%s g/m³{e}";
|
||||||
|
|
||||||
void SEN5XShow(bool json)
|
void SEN5XShow(bool json)
|
||||||
{
|
{
|
||||||
|
float convertedTemp = 0;
|
||||||
|
float convertedHum = 0;
|
||||||
if (SEN5XDATA->sen5x_ready)
|
if (SEN5XDATA->sen5x_ready)
|
||||||
{
|
{
|
||||||
char sen5x_abs_hum[33];
|
char sen5x_abs_hum[13];
|
||||||
bool ahum_available = !isnan(SEN5XDATA->ambientTemperature) && (SEN5XDATA->ambientHumidity > 0);
|
bool ahum_available = !isnan(SEN5XDATA->ambientTemperature) &&
|
||||||
|
!isnan(SEN5XDATA->ambientHumidity) &&
|
||||||
|
SEN5XDATA->ambientHumidity > 0;
|
||||||
if (ahum_available)
|
if (ahum_available)
|
||||||
{
|
{
|
||||||
// has humidity + temperature
|
convertedTemp = ConvertTempToFahrenheit(SEN5XDATA->ambientTemperature);
|
||||||
dtostrfd(SEN5XDATA->abshum, 4, sen5x_abs_hum);
|
convertedHum = ConvertHumidity(SEN5XDATA->ambientHumidity);
|
||||||
|
dtostrfd(sen5x_AbsoluteHumidity(convertedTemp,convertedHum), 4, sen5x_abs_hum);
|
||||||
}
|
}
|
||||||
if (json)
|
if (json)
|
||||||
{
|
{
|
||||||
ResponseAppend_P(PSTR(",\"SEN5X\":{"));
|
ResponseAppend_P(PSTR(",\"SEN5X\":{"));
|
||||||
ResponseAppend_P(PSTR("\"PM1\":%.1f,"), SEN5XDATA->massConcentrationPm1p0);
|
ResponseAppend_P(PSTR("\"" D_ENVIRONMENTAL_CONCENTRATION "1\":%1_f,"), &SEN5XDATA->massConcentrationPm1p0);
|
||||||
ResponseAppend_P(PSTR("\"PM2.5\":%.1f,"), SEN5XDATA->massConcentrationPm2p5);
|
ResponseAppend_P(PSTR("\"" D_ENVIRONMENTAL_CONCENTRATION "2.5\":%1_f,"), &SEN5XDATA->massConcentrationPm2p5);
|
||||||
ResponseAppend_P(PSTR("\"PM4\":%.1f,"), SEN5XDATA->massConcentrationPm4p0);
|
ResponseAppend_P(PSTR("\"" D_ENVIRONMENTAL_CONCENTRATION "4\":%1_f,"), &SEN5XDATA->massConcentrationPm4p0);
|
||||||
ResponseAppend_P(PSTR("\"PM10\":%.1f,"), SEN5XDATA->massConcentrationPm10p0);
|
ResponseAppend_P(PSTR("\"" D_ENVIRONMENTAL_CONCENTRATION "10\":%1_f,"), &SEN5XDATA->massConcentrationPm10p0);
|
||||||
if (!isnan(SEN5XDATA->noxIndex))
|
if (!isnan(SEN5XDATA->noxIndex))
|
||||||
ResponseAppend_P(PSTR("\"NOx\":%.0f,"), SEN5XDATA->noxIndex);
|
ResponseAppend_P(PSTR("\"NOx\":%0_f,"), &SEN5XDATA->noxIndex);
|
||||||
if (!isnan(SEN5XDATA->vocIndex))
|
if (!isnan(SEN5XDATA->vocIndex))
|
||||||
ResponseAppend_P(PSTR("\"VOC\":%.0f,"), SEN5XDATA->vocIndex);
|
ResponseAppend_P(PSTR("\"VOC\":%0_f,"), &SEN5XDATA->vocIndex);
|
||||||
if (!isnan(SEN5XDATA->ambientTemperature))
|
|
||||||
ResponseAppendTHD(SEN5XDATA->ambientTemperature, SEN5XDATA->ambientHumidity);
|
|
||||||
if (ahum_available)
|
if (ahum_available)
|
||||||
|
ResponseAppendTHD(convertedTemp, convertedHum);
|
||||||
ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"), sen5x_abs_hum);
|
ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"), sen5x_abs_hum);
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
|
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "PM1", 1, SEN5XDATA->massConcentrationPm1p0, "μg/m³");
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, PSTR(D_ENVIRONMENTAL_CONCENTRATION "1"), 1, &SEN5XDATA->massConcentrationPm1p0, D_UNIT_MICROGRAM_PER_CUBIC_METER);
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "PM2.5", 1, SEN5XDATA->massConcentrationPm2p5, "μg/m³");
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, PSTR(D_ENVIRONMENTAL_CONCENTRATION "2.5"), 1, &SEN5XDATA->massConcentrationPm2p5, D_UNIT_MICROGRAM_PER_CUBIC_METER);
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "PM4", 1, SEN5XDATA->massConcentrationPm4p0, "μg/m³");
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, PSTR(D_ENVIRONMENTAL_CONCENTRATION "4"), 1, &SEN5XDATA->massConcentrationPm4p0, D_UNIT_MICROGRAM_PER_CUBIC_METER);
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "PM10", 1, SEN5XDATA->massConcentrationPm10p0, "μg/m³");
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, PSTR(D_ENVIRONMENTAL_CONCENTRATION "10"), 1, &SEN5XDATA->massConcentrationPm10p0, D_UNIT_MICROGRAM_PER_CUBIC_METER);
|
||||||
if (!isnan(SEN5XDATA->noxIndex))
|
if (!isnan(SEN5XDATA->noxIndex))
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITLESS, "NOx", 0, SEN5XDATA->noxIndex);
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITLESS, "NOx", 0, &SEN5XDATA->noxIndex);
|
||||||
if (!isnan(SEN5XDATA->vocIndex))
|
if (!isnan(SEN5XDATA->vocIndex))
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITLESS, "VOC", 0, SEN5XDATA->vocIndex);
|
WSContentSend_PD(HTTP_SNS_SEN5X_UNITLESS, "VOC", 0, &SEN5XDATA->vocIndex);
|
||||||
if (!isnan(SEN5XDATA->ambientTemperature))
|
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "Temperature", 2, SEN5XDATA->ambientTemperature, "°C");
|
|
||||||
if (!isnan(SEN5XDATA->ambientHumidity))
|
|
||||||
WSContentSend_PD(HTTP_SNS_SEN5X_UNITS, "Humidity", 2, SEN5XDATA->ambientHumidity, "%RH");
|
|
||||||
if (ahum_available)
|
if (ahum_available)
|
||||||
|
WSContentSend_THD(PSTR("SEN5X"), convertedTemp, convertedHum);
|
||||||
WSContentSend_PD(HTTP_SNS_AHUMSEN5X, sen5x_abs_hum);
|
WSContentSend_PD(HTTP_SNS_AHUMSEN5X, sen5x_abs_hum);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue