Skip to content

Commit

Permalink
DavisLogger: Now receives LOOP2 packets (#131). Also adds sea level p…
Browse files Browse the repository at this point in the history
…ressure columns (#140)

And makes that data available via new columns in the database as well as RabbitMQ.

This commit also adds database columns for mean sea level pressure. The appropriate values are now logged to the appropriate places for live data.

Davis logger for now logs the same value to both absolute and mean sea level pressure columns for samples rather than leaving the absolute pressure column as null. This will be changed near the end of ticket #140 before the data migration step.
  • Loading branch information
davidrg committed Aug 27, 2021
1 parent f1bbc65 commit e114ee5
Show file tree
Hide file tree
Showing 8 changed files with 1,268 additions and 93 deletions.
21 changes: 20 additions & 1 deletion database/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CREATE TABLE sample
wind_chill real, -- Calculated wind chill
apparent_temperature real, -- Calculated apparent temperature.
absolute_pressure real, -- Absolute pressure
mean_sea_level_pressure real, -- Mean sea level pressure
average_wind_speed real, -- Average Wind Speed.
gust_wind_speed real, -- Gust wind speed.
wind_direction integer, -- Wind Direction in degrees
Expand All @@ -117,6 +118,7 @@ COMMENT ON COLUMN sample.temperature IS 'Temperature outside in degrees Celsius'
COMMENT ON COLUMN sample.dew_point IS 'Calculated dew point in degrees Celsius. Use the dew_point function to calculate. Calculated automatically by a trigger on insert.';
COMMENT ON COLUMN sample.wind_chill IS 'Calculated wind chill in degrees Celsius. Use the wind_chill function to calculate. Calculated automatically by a trigger on insert.';
COMMENT ON COLUMN sample.apparent_temperature IS 'Calculated apparent temperature in degrees Celsius. Use the apparent_temperature to calculate. Calculated automatically by a trigger on insert.';
COMMENT ON COLUMN sample.mean_sea_level_pressure IS 'Mean sea level pressure in hPa';
COMMENT ON COLUMN sample.absolute_pressure IS 'Absolute pressure in hPa';
COMMENT ON COLUMN sample.average_wind_speed IS 'Average Wind Speed in m/s.';
COMMENT ON COLUMN sample.gust_wind_speed IS 'Gust wind speed in m/s.';
Expand Down Expand Up @@ -490,6 +492,7 @@ CREATE TABLE live_data
wind_chill real, -- Calculated wind chill
apparent_temperature real, -- Calculated apparent temperature.
absolute_pressure real, -- Absolute pressure
mean_sea_level_pressure real, -- MSL pressure
average_wind_speed real, -- Average Wind Speed.
gust_wind_speed real, -- Gust wind speed.
wind_direction integer -- Wind Direction.
Expand All @@ -505,6 +508,7 @@ COMMENT ON COLUMN live_data.dew_point IS 'Calculated dew point in degrees Celsiu
COMMENT ON COLUMN live_data.wind_chill IS 'Calculated wind chill in degrees Celsius. Use the wind_chill function to calculate. Calculated automatically by a trigger on insert.';
COMMENT ON COLUMN live_data.apparent_temperature IS 'Calculated apparent temperature in degrees Celsius. Use the apparent_temperature to calculate. Calculated automatically by a trigger on insert.';
COMMENT ON COLUMN live_data.absolute_pressure IS 'Absolute pressure in hPa';
COMMENT ON COLUMN live_data.mean_sea_level_pressure IS 'Mean sea level pressure in hPa';
COMMENT ON COLUMN live_data.average_wind_speed IS 'Average Wind Speed in m/s.';
COMMENT ON COLUMN live_data.gust_wind_speed IS 'Gust wind speed in m/s.';
COMMENT ON COLUMN live_data.wind_direction IS 'Wind Direction.';
Expand All @@ -523,6 +527,15 @@ create table davis_live_data (
forecast_rule_id int,
uv_index numeric(3,1),
solar_radiation int,
altimeter_setting real,

-- A few computed values that can be a bit of a pain to compute on the fly
average_wind_speed_2m real,
average_wind_speed_10m real,
gust_wind_speed_10m real,
gust_wind_direction_10m integer,
heat_index real,
thsw_index real,

-- Extra sensors. To populate all of these you'll need:
-- 1x 6345 Leaf/Soil transmitter setup as a leaf wetness station
Expand Down Expand Up @@ -561,7 +574,13 @@ comment on column davis_live_data.forecast_icon is 'Forecast icon';
comment on column davis_live_data.forecast_rule_id is 'Current forecast rule. See davis_forecast_rule table for values';
comment on column davis_live_data.uv_index is 'Latest UV index reading';
comment on column davis_live_data.solar_radiation is 'Latest solar radiation reading in watt/meter squared';

comment on column davis_live_data.altimeter_setting is 'Altimeter setting in hPa';
comment on column davis_live_data.average_wind_speed_2m is 'Average wind speed over the last 2 minutes in meters per second';
comment on column davis_live_data.average_wind_speed_10m is 'Average wind speed over the last 10 minutes in meters per second';
comment on column davis_live_data.gust_wind_speed_10m is 'Maximum wind gust in the last 10 minutes in meters per second';
comment on column davis_live_data.gust_wind_direction_10m is 'Direction of maximum wind gust in the last 10 minutes';
comment on column davis_live_data.heat_index is 'Heat index in degrees celsius';
comment on column davis_live_data.thsw_index is 'Temperature-Humidity-Sun-Wind index in degrees celsius';
comment on column davis_live_data.leaf_wetness_1 is 'First leaf wetness. Range is 0-15 (0=dry, 15=wet)';
comment on column davis_live_data.leaf_wetness_2 is 'Second leaf wetness. Range is 0-15 (0=dry, 15=wet)';
comment on column davis_live_data.leaf_temperature_1 is 'First leaf temperature';
Expand Down
23 changes: 23 additions & 0 deletions database/upgrade_v3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ IS 'Ensure the indoor relative humidity is in the range 0-100';
-- Timestamp really can't be nullable
alter table sample alter column time_stamp set not null;

alter table sample add column mean_sea_level_pressure real;
COMMENT ON COLUMN sample.mean_sea_level_pressure IS 'Mean sea level pressure in hPa';

alter table live_data add column mean_sea_level_pressure real;
COMMENT ON COLUMN live_data.mean_sea_level_pressure IS 'Mean sea level pressure in hPa';

-- New sort order column on station table.
alter table station add column sort_order integer;
comment on column station.sort_order is 'The order in which stations should be presented to the user';
Expand Down Expand Up @@ -584,6 +590,15 @@ create table davis_live_data (
forecast_rule_id int,
uv_index numeric(3,1),
solar_radiation int,
altimeter_setting real,

-- A few computed values that can be a bit of a pain to compute on the fly
average_wind_speed_2m real,
average_wind_speed_10m real,
gust_wind_speed_10m real,
gust_wind_direction_10m integer,
heat_index real,
thsw_index real,

-- Extra sensors. To populate all of these you'll need:
-- 1x 6345 Leaf/Soil transmitter setup as a leaf wetness station
Expand Down Expand Up @@ -622,6 +637,13 @@ comment on column davis_live_data.forecast_icon is 'Forecast icon';
comment on column davis_live_data.forecast_rule_id is 'Current forecast rule. See davis_forecast_rule table for values';
comment on column davis_live_data.uv_index is 'Latest UV index reading';
comment on column davis_live_data.solar_radiation is 'Latest solar radiation reading in watt/meter squared';
comment on column davis_live_data.altimeter_setting is 'Altimeter setting in hPa';
comment on column davis_live_data.average_wind_speed_2m is 'Average wind speed over the last 2 minutes in meters per second';
comment on column davis_live_data.average_wind_speed_10m is 'Average wind speed over the last 10 minutes in meters per second';
comment on column davis_live_data.gust_wind_speed_10m is 'Maximum wind gust in the last 10 minutes in meters per second';
comment on column davis_live_data.gust_wind_direction_10m is 'Direction of maximum wind gust in the last 10 minutes';
comment on column davis_live_data.heat_index is 'Heat index in degrees celsius';
comment on column davis_live_data.thsw_index is 'Temperature-Humidity-Sun-Wind index in degrees celsius';
comment on column davis_live_data.leaf_wetness_1 is 'First leaf wetness. Range is 0-15 (0=dry, 15=wet)';
comment on column davis_live_data.leaf_wetness_2 is 'Second leaf wetness. Range is 0-15 (0=dry, 15=wet)';
comment on column davis_live_data.leaf_temperature_1 is 'First leaf temperature';
Expand All @@ -640,6 +662,7 @@ comment on column davis_live_data.extra_temperature_1 is 'First extra temperatur
comment on column davis_live_data.extra_temperature_2 is 'Second extra temperature';
comment on column davis_live_data.extra_temperature_3 is 'Third extra temperature sensor';


create table sample_gap (
sample_gap_id serial not null primary key,
station_id integer not null references station(station_id),
Expand Down
5 changes: 4 additions & 1 deletion davis-logger/davis_logger/davis.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self):
# Setup events
self.sendData = Event()
self.loopDataReceived = Event()
self.loop2DataReceived = Event()
self.InitCompleted = Event()

self._log_data = False
Expand Down Expand Up @@ -325,6 +326,7 @@ def _console_config_ready(self, procedure):
self._rainCollectorSize, 200,
reactor.callLater)
self._looper.loopDataReceived += self.loopDataReceived.fire
self._looper.loop2DataReceived += self.loop2DataReceived.fire
self._looper.finished += self._looper_restart
self._looper.canceled += self._looper_canceled
self._state_data_handlers[STATE_LOOP] = self._looper.data_received
Expand All @@ -336,7 +338,8 @@ def _console_config_ready(self, procedure):
self._archive_interval,
self._auto_dst_enabled,
dst_on,
self._station_list)
self._station_list,
self._lps_supported)

def _write(self, data):
if self._log_data:
Expand Down
Loading

0 comments on commit e114ee5

Please sign in to comment.