Skip to content

Commit

Permalink
Add calculation of Wet-Bulb Globe Temperature (WBGT) and Wet-Bulb Tem…
Browse files Browse the repository at this point in the history
…perature (#225)

* Added Natural Wet-Bulb and Wet-Bulb Globe Temperature calculations
* Added calculated WBGT (Wet Bulb Globe Temperature) to MQTT messages
  • Loading branch information
matthias-bs authored Jan 29, 2025
1 parent 57f1d85 commit 13e127f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
// 20240603 Modified for arduino-esp32 v3.0.0
// 20241113 Added getting/setting of sensor include/exclude lists via MQTT
// 20250127 Added Globe Thermometer Temperature (8-in-1 Weather Sensor)
// 20250129 Added calculated WBGT (Wet Bulb Globe Temperature)
//
// ToDo:
//
Expand Down Expand Up @@ -710,6 +711,12 @@ void publishWeatherdata(bool complete)
{
mqtt_payload2 += String(",\"perceived_temp_c\":") + JSON_FLOAT(String(perceived_temperature(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.wind_avg_meter_sec, weatherSensor.sensor[i].w.humidity), 1));
}
if (weatherSensor.sensor[i].w.tglobe_ok)
{
float t_wet = calcnaturalwetbulb(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.humidity);
float wbgt = calcwbgt(t_wet, weatherSensor.sensor[i].w.tglobe_c, weatherSensor.sensor[i].w.temp_c);
mqtt_payload2 += String(",\"wgbt\":") + JSON_FLOAT(String(wbgt, 1));
}
}
if (weatherSensor.sensor[i].w.uv_ok || complete)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
// 20240603 Modified for arduino-esp32 v3.0.0
// 20241113 Added getting/setting of sensor include/exclude lists via MQTT
// 20250127 Added Globe Thermometer Temperature (8-in-1 Weather Sensor)
// 20250129 Added calculated WBGT (Wet Bulb Globe Temperature)
//
// ToDo:
//
Expand Down Expand Up @@ -709,6 +710,12 @@ void publishWeatherdata(bool complete)
{
mqtt_payload2 += String(",\"perceived_temp_c\":") + JSON_FLOAT(String(perceived_temperature(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.wind_avg_meter_sec, weatherSensor.sensor[i].w.humidity), 1));
}
if (weatherSensor.sensor[i].w.tglobe_ok)
{
float t_wet = calcnaturalwetbulb(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.humidity);
float wbgt = calcwbgt(t_wet, weatherSensor.sensor[i].w.tglobe_c, weatherSensor.sensor[i].w.temp_c);
mqtt_payload2 += String(",\"wgbt\":") + JSON_FLOAT(String(wbgt, 1));
}
}
if (weatherSensor.sensor[i].w.uv_ok || complete)
{
Expand Down
40 changes: 38 additions & 2 deletions examples/BresserWeatherSensorMQTTCustom/src/WeatherUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <Arduino.h>
#include <math.h>
#include <string>
#if defined(ESP32) || defined(ESP8266)
#include <string>
#endif
#include <string.h>
#include "WeatherUtils.h"

#if defined(ESP32) || defined(ESP8266)
// Mapping of wind direction in degrees to text
// Note: add your localization as desired
const std::string COMPASS_POINTS[17] = {
Expand All @@ -24,6 +28,7 @@ char * winddir_flt_to_str(float dir, char * buf)

return buf;
};
#endif

//
// Convert wind speed from meters per second to Beaufort
Expand Down Expand Up @@ -136,10 +141,41 @@ float calcheatindex(float celsius, float humidity) {
return (-8.784695 + 1.61139411 * celsius + 2.338549 * humidity - 0.14611605 * celsius * humidity - 0.012308094 * celsius * celsius - 0.016424828 * humidity * humidity + 0.002211732 * celsius * celsius * humidity + 0.00072546 * celsius * humidity * humidity - 0.000003582 * celsius * celsius * humidity * humidity);
}

/*
* Calculate natural wet bulb temperature
*
* Source:
* Stull, Roland B., 1950-.
* “Wet-Bulb Temperature from Relative Humidity and Air Temperature.”
* A. American Meteorological Society, 2011. Web. 29 Jan. 2025.
* https://open.library.ubc.ca/collections/facultyresearchandpublications/52383/items/1.0041967.
* Faculty Research and Publications.
*/
float calcnaturalwetbulb(float temperature, float humidity)
{
return temperature * atan(0.151977 * pow(humidity + 8.313659, 0.5))
+ atan(temperature + humidity)
- atan(humidity - 1.676331)
+ 0.00391838 * pow(humidity, 1.5) * atan(0.023101 * humidity)
- 4.686035;
}


/*
* Calculate wet bulb globe temperature (WBGT)
*
* Source:
* https://en.wikipedia.org/wiki/Wet-bulb_globe_temperature
*/
float calcwbgt(float t_wet, float t_globe, float t_dry)
{
return 0.7 * t_wet + 0.2 * t_globe + 0.1 * t_dry;
}

/*
* Source: https://myscope.net/hitzeindex-gefuehle-temperatur/
*
* Valid for Valid for temperatures >= 27°C and humidity >=40%
* Valid for temperatures >= 27°C and humidity >=40%
*/
float calchumidex(float temperature, float humidity) {
float e = (6.112 * pow(10,(7.5 * temperature/(237.7 + temperature))) * humidity/100); //vapor pressure
Expand Down
28 changes: 27 additions & 1 deletion examples/BresserWeatherSensorMQTTCustom/src/WeatherUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#if !defined(WEATHER_UTILS_H)
#define WEATHER_UTILS_H

#ifdef ARDUINO_ARCH_AVR
#include <stdint.h>
#endif

/*!
* \brief Calculate dew point
*
Expand All @@ -19,7 +23,7 @@ float calcdewpoint(float celsius, float humidity);
* \param celsius air temperature in °C
* \param windspeed wind speed in km/h
*
* \returns windchill tempoerature in °C
* \returns windchill temperature in °C
*/
float calcwindchill(float celsius, float windspeed);

Expand All @@ -45,6 +49,28 @@ float calcheatindex(float celsius, float humidity);
*/
float calchumidex(float temperature, float humidity);

/*!
* \brief Calculate natural wet bulb temperature
*
* \param temperature Dry-bulb temperature (air temperature) in °C
* \param humidity relative humidity in %
*
* \returns natural wet bulb temperature in °C
*/
float calcnaturalwetbulb(float temperature, float humidity);

/*!
* \brief Calculate wet bulb globe temperature (WBGT)
*
* \param t_wet Natural wet-bulb temperature in °C
* \param t_globe Globe thermometer temperature (black globe thermometer) in °C
* \param t_dry Dry-bulb temperature (actual air temperature) in °C
*
* \returns WBGT in °C
*/
float calcwbgt(float t_wet, float t_globe, float t_dry);


/*!
* \brief Calculate perceived temperature (feels-like temperature)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
// 20240603 Modified for arduino-esp32 v3.0.0
// 20241113 Added getting/setting of sensor include/exclude lists via MQTT
// 20250127 Added Globe Thermometer Temperature (8-in-1 Weather Sensor)
// 20250129 Added calculated WBGT (Wet Bulb Globe Temperature)
//
// ToDo:
//
Expand Down Expand Up @@ -893,6 +894,12 @@ void publishWeatherdata(bool complete)
{
mqtt_payload2 += String(",\"perceived_temp_c\":") + JSON_FLOAT(String(perceived_temperature(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.wind_avg_meter_sec, weatherSensor.sensor[i].w.humidity), 1));
}
if (weatherSensor.sensor[i].w.tglobe_ok)
{
float t_wet = calcnaturalwetbulb(weatherSensor.sensor[i].w.temp_c, weatherSensor.sensor[i].w.humidity);
float wbgt = calcwbgt(t_wet, weatherSensor.sensor[i].w.tglobe_c, weatherSensor.sensor[i].w.temp_c);
mqtt_payload2 += String(",\"wgbt\":") + JSON_FLOAT(String(wbgt, 1));
}
}
if (weatherSensor.sensor[i].w.uv_ok || complete)
{
Expand Down
31 changes: 31 additions & 0 deletions src/WeatherUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ float calcheatindex(float celsius, float humidity) {
return (-8.784695 + 1.61139411 * celsius + 2.338549 * humidity - 0.14611605 * celsius * humidity - 0.012308094 * celsius * celsius - 0.016424828 * humidity * humidity + 0.002211732 * celsius * celsius * humidity + 0.00072546 * celsius * humidity * humidity - 0.000003582 * celsius * celsius * humidity * humidity);
}

/*
* Calculate natural wet bulb temperature
*
* Source:
* Stull, Roland B., 1950-.
* “Wet-Bulb Temperature from Relative Humidity and Air Temperature.”
* A. American Meteorological Society, 2011. Web. 29 Jan. 2025.
* https://open.library.ubc.ca/collections/facultyresearchandpublications/52383/items/1.0041967.
* Faculty Research and Publications.
*/
float calcnaturalwetbulb(float temperature, float humidity)
{
return temperature * atan(0.151977 * pow(humidity + 8.313659, 0.5))
+ atan(temperature + humidity)
- atan(humidity - 1.676331)
+ 0.00391838 * pow(humidity, 1.5) * atan(0.023101 * humidity)
- 4.686035;
}


/*
* Calculate wet bulb globe temperature (WBGT)
*
* Source:
* https://en.wikipedia.org/wiki/Wet-bulb_globe_temperature
*/
float calcwbgt(float t_wet, float t_globe, float t_dry)
{
return 0.7 * t_wet + 0.2 * t_globe + 0.1 * t_dry;
}

/*
* Source: https://myscope.net/hitzeindex-gefuehle-temperatur/
*
Expand Down
22 changes: 22 additions & 0 deletions src/WeatherUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ float calcheatindex(float celsius, float humidity);
*/
float calchumidex(float temperature, float humidity);

/*!
* \brief Calculate natural wet bulb temperature
*
* \param temperature Dry-bulb temperature (air temperature) in °C
* \param humidity relative humidity in %
*
* \returns natural wet bulb temperature in °C
*/
float calcnaturalwetbulb(float temperature, float humidity);

/*!
* \brief Calculate wet bulb globe temperature (WBGT)
*
* \param t_wet Natural wet-bulb temperature in °C
* \param t_globe Globe thermometer temperature (black globe thermometer) in °C
* \param t_dry Dry-bulb temperature (actual air temperature) in °C
*
* \returns WBGT in °C
*/
float calcwbgt(float t_wet, float t_globe, float t_dry);


/*!
* \brief Calculate perceived temperature (feels-like temperature)
*
Expand Down

0 comments on commit 13e127f

Please sign in to comment.