diff --git a/documentation/boards/enviro-weather.md b/documentation/boards/enviro-weather.md index 7b3866d..25e4ff7 100644 --- a/documentation/boards/enviro-weather.md +++ b/documentation/boards/enviro-weather.md @@ -11,6 +11,7 @@ Enviro Weather is a super slimline all in one board for keeping a (weather) eye |Temperature|`temperature`|celcius|°C|`22.11`| |Humidity|`humidity`|percent|%|`55.42`| |Air Pressure|`pressure`|hectopascals|hPa|`997.16`| +|Adjusted Sea Level Air Pressure|`sea_level_pressure`|hectopascals|hPa|`1014.06`| |Luminance|`luminance`|lux|lx|`35`| |Rainfall|`rain`|millimetres|mm|`1.674`| |Rainfall Average|`rain_per_second`|millimetres per second|mm/s|`1.674`| diff --git a/enviro/boards/weather.py b/enviro/boards/weather.py index 9b44e13..42a81f7 100644 --- a/enviro/boards/weather.py +++ b/enviro/boards/weather.py @@ -3,7 +3,7 @@ from breakout_ltr559 import BreakoutLTR559 from machine import Pin, PWM from pimoroni import Analog -from enviro import i2c, activity_led +from enviro import i2c, activity_led, config import enviro.helpers as helpers from phew import logging from enviro.constants import WAKE_REASON_RTC_ALARM, WAKE_REASON_BUTTON_PRESS @@ -190,14 +190,27 @@ def get_sensor_readings(seconds_since_last, is_usb_power): ltr_data = ltr559.get_reading() rain, rain_per_second = rainfall(seconds_since_last) + # Adjust pressure to calculated sea level value if set to in config + pressure = bme280_data[1] / 100.0 + temperature = bme280_data[0] + from ucollections import OrderedDict - return OrderedDict({ - "temperature": round(bme280_data[0], 2), + readings = OrderedDict({ + "temperature": round(temperature, 2), "humidity": round(bme280_data[2], 2), - "pressure": round(bme280_data[1] / 100.0, 2), + "pressure": round(pressure, 2), "luminance": round(ltr_data[BreakoutLTR559.LUX], 2), "wind_speed": wind_speed(), "rain": rain, "rain_per_second": rain_per_second, "wind_direction": wind_direction() }) + + if config.sea_level_pressure: + logging.info(f" - recorded temperature: {temperature}") + logging.info(f" - recorded pressure: {pressure}") + sea_level_pressure = round(helpers.get_sea_level_pressure(pressure, temperature, config.height_above_sea_level), 2) + logging.info(f" - calculated mean sea level pressure: {sea_level_pressure}") + readings["sea_level_pressure"] = round(sea_level_pressure, 2) + + return readings \ No newline at end of file diff --git a/enviro/config_defaults.py b/enviro/config_defaults.py index 63a5877..0f4ee74 100644 --- a/enviro/config_defaults.py +++ b/enviro/config_defaults.py @@ -23,6 +23,19 @@ def add_missing_config_settings(): except AttributeError: warn_missing_config_setting("wifi_country") config.wifi_country = "GB" + + try: + config.sea_level_pressure + except AttributeError: + warn_missing_config_setting("sea_level_pressure") + config.sea_level_pressure = False + + try: + config.height_above_sea_level + except AttributeError: + warn_missing_config_setting("height_above_sea_level") + config.height_above_sea_level = 0 + def warn_missing_config_setting(setting): logging.warn(f"> config setting '{setting}' missing, please add it to config.py") diff --git a/enviro/config_template.py b/enviro/config_template.py index 11404a9..0ef218b 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -55,3 +55,8 @@ # compensate for usb power usb_power_temperature_offset = 4.5 + +# sea level pressure conversion (adjusts measured pressure output for mean sea level value) +sea_level_pressure = False +# height in metres +height_above_sea_level = 0 \ No newline at end of file diff --git a/enviro/helpers.py b/enviro/helpers.py index 1503ad4..fd4ce73 100644 --- a/enviro/helpers.py +++ b/enviro/helpers.py @@ -98,3 +98,10 @@ def get_saturation_vapor_pressure(temperature_in_k): temperature_in_k * (a1*v + a2*v**1.5 + a3*v**3 + a4*v**3.5 + a5*v**4 + a6*v**7.5) ) + +# Calculates mean sea level pressure (QNH) from observed pressure +# https://keisan.casio.com/exec/system/1224575267 +def get_sea_level_pressure(observed_pressure, temperature_in_c, altitude_in_m): +# def sea(pressure, temperature, height): + qnh = observed_pressure * ((1 - ((0.0065 * altitude_in_m) / (temperature_in_c + (0.0065 * altitude_in_m) + 273.15)))** -5.257) + return qnh \ No newline at end of file