Temperature Sensors Part 1: Influx DB
This is part 1 in a series describing my DIY temperature and humidity sensors.
I built some temperature and humidity sensors based on ESP8266 Wi-Fi modules for house so I know just how cold I am at any given moment. This details the settings on the InfluxDB server that stores everything. I made package this up in to a little library (Github) to make things easier.
InfluxDB
Each sensor has it’s own measurement (the name of the room they’re located in) and updates the database multiple times per minute. This is excessive, but I forgot about it and it’s a bit of pain to reprogram them.
name: DanielsRoom
time fahrenheit host region relative_humidity
---- ---------- ---- ------ -----------------
2018-10-20T00:00:02.328505836Z esp8266-DanielsRoom1 us-east 0.547224
2018-10-20T00:00:03.528801987Z 72.574486 esp8266-DanielsRoom1 us-east
2018-10-20T00:00:03.768001235Z esp8266-DanielsRoom1 us-east 0.547147
2018-10-20T00:00:04.687234974Z 72.574486 esp8266-DanielsRoom1 us-east
name: LivingRoom
time fahrenheit host region relative_humidity
---- ---------- ---- ------ -----------------
2018-10-20T00:00:02.643783571Z 72.207687 esp8266-LivingRoom1 us-east
2018-10-20T00:00:03.048582528Z esp8266-LivingRoom1 us-east 0.504728
2018-10-20T00:00:03.79192576Z 72.188385 esp8266-LivingRoom1 us-east
2018-10-20T00:00:04.052576581Z esp8266-LivingRoom1 us-east 0.504651
LivingRoom and DanielsRoom belong to a retention policy called two_hours which stores the data points for… two hours!
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 false
two_hours 2h0m0s 1h0m0s 1 true
forever 0s 168h0m0s 1 false
Long before the two hour time limit is up a continuous query runs and calculates the average sensor value for the past minute and stores it in the forever retention policy which keeps it forever.
name:
name query
---- -----
cq_1m_danielsroom_humidity CREATE CONTINUOUS QUERY cq_1m_danielsroom_humidity ON BEGIN SELECT mean(relative_humidity) AS mean_relative_humidity INTO HouseholdDatabase.forever.danielsroom_relative_humidity FROM HouseholdDatabase.two_hours.DanielsRoom GROUP BY time(1m) END
cq_1m_danielsroom_fahrenheit CREATE CONTINUOUS QUERY cq_1m_danielsroom_fahrenheit ON BEGIN SELECT mean(fahrenheit) AS mean_fahrenheit INTO HouseholdDatabase.forever.danielsroom_fahrenheit FROM HouseholdDatabase.two_hours.DanielsRoom GROUP BY time(1m) END
cq_1m_livingroom_fahrenheit CREATE CONTINUOUS QUERY cq_1m_livingroom_fahrenheit ON BEGIN SELECT mean(fahrenheit) AS mean_fahrenheit INTO HouseholdDatabase.forever.livingroom_fahrenheit FROM HouseholdDatabase.two_hours.LivingRoom GROUP BY time(1m) END
cq_1m_livingroom_relative_humidity CREATE CONTINUOUS QUERY cq_1m_livingroom_relative_humidity ON BEGIN SELECT mean(relative_humidity) AS mean_relative_humidity INTO HouseholdDatabase.forever.livingroom_relative_humidity FROM HouseholdDatabase.two_hours.LivingRoom GROUP BY time(1m) END