Showing posts with label cooling. Show all posts
Showing posts with label cooling. Show all posts

Saturday, July 30, 2022

Recording temprature data to InfluxDB for use within Grafana for display!

Temperature is knowledge!  Now that we have the values read via Python as seen in the previous installment - https://astromaphilli14.blogspot.com/2021/08/building-dual-temperature-sensor-on.html we're now able to consider storing these values for logging and trending.  You'll want to consider a proper database to house all your temp and humidy values.  InfluxDB is an awesome opensource package, so that is what I used.

 

Thanks to one of my coworkers for showing me the ropes of database and sql queries!  The secret sauce is reusing the python script that reads the temp values to simply write as they're read.  The following edits to the python code allow us to InfluxDB for use in Grafana!  GO NERDS!!!!

 

Overly simplified you simply write the data that you want:

 

from influxdb import InfluxDBClient

 

# defines DB resource

client = InfluxDBClient("www.sm.sm", 8086, "grafana", "YOURSECRET", "astrocarttemp")

 

 

        client.create_database('astrocarttemp')

        client.write_points(json_AirTemp)

        client.write_points(json_MirrorTemp)

        client.write_points(json_AirHumidity)

        client.write_points(json_MirrorHumidity)

        client.write_points(json_DeltaT)

 

 

The scripts are all in my github pages - https://github.com/maphilli14/RPiTempSensorGrafanaLogger/commits/main

The logic is somewhat simple:

 

  1. Read air and mirror sensors and parse out the temperature and humidity values
  2. Assign values to JSON data
  3. Write to InfluxDB
  4. Graph in Grafana
  5. Optionally I pull OpenWeather to compare to my own air measurements, helpful when scope is indoors!

 

There are a lot of steps to take that data written in InfluxDB to open them up and setup in Grafana, but there's plenty of guides to help you with that.
 
Here's a few basics that can help get started.
 
Install Grafana and add your new InfluxDB.  I've skipped installation of Influx and Grafana as there are plenty of guides to search up, I'm just trying to cover the basic logic and steps.

 

 

SELECT mean("value") FROM "AirTemp" WHERE $timeFilter GROUP BY time($__interval) fill(null)

 

SELECT mean("value") FROM "MirrorTemp", "AirTemp" WHERE $timeFilter GROUP BY time($__interval) fill(null)

 

SELECT mean("value") FROM "MirrorTemp", "AirTemp", "MirrorHumidity", "AirHumidity", "DeltaT" WHERE $timeFilter GROUP BY time($__interval) fill(null)

 

 

 

Home Dashboard wi 20210518.0444.gif (CL 
A small kindness car 
Immigrant prisoners 
Glory'/VaIor Points PL 
P roble m loading pag 
Raspberry Pi MC L X 
Grischa Hahn (WinJUPOS & Cary teen wins interm 
InfluxD8CIient userrv 
nfIuxD8-Python — + 
.sm.sm 
1 C" now- 1 h " now", "astrocarttemp" " policy" "default", " resultFormat" "time_series", "order8yTime' 
lil\ O O 
@ @ Minor Planet Bulletin DR c SW ESA- European Space m 
@ Explore 
O 
astrocarttemp 
LECT FROM "AirTemp" WHERE $timeFilter GROUP BY time _interval) fill(nulD 
FORMAT AS 
Help > 
+ Add query 
Graph 
76.3 
76.3 
76.3 
76.2 
76.2 
76.2 
76.2 
76.1 
76.1 
Time series 
ALIAS BY 
Naming pattern 
O Query inspector 
18:10 
äw to SS t3MM O @ Balancing Intensem„ 
Georgesmsm - Statusm Microsoft Planner @Sign in to Cisco Other Bookmarks 
split 
Run Query v 
0.2s @ 
11 • • I 
Query history 
18:05 
18:15 
18:20 
18:25 
18:30 
18:35 
18:40 
18:45 
18:50 
18:55 
— AirTenw.mean 
Table 
Time 
2021-0522 
2021-0522 18:23:52 
19: 
AirTemp.mean 
O

 

 

This seems like lots of work but that graphs used in the Why do you need blog are used to help illustrate the need for temperature control and considerations.

 

My current influxDB setup looks like this in grafana!

M*rorTemp 
0449:30 
AirTemp 
04 SC-m 
T”,準 Delta 
T”鬱 History 
04:Sl訇0 
T”,平 Delta 
,詹『ror 
Air Humidity 
0453: 
Humidity HistMY 
0451:噫 
이:臼:閬 
044하閬 
0451:* 
0451:閬 
04曾閬 
Openweather Temp 4 Humidity 

This view shows you the realtime, averaged and trending temps / humidity for both air and mirrors as well as the openweather temp and humidity!

 

 

 

This is a historical live view of the cooling running on the scope while it was outside at night!

 

 Gen 3 一 7A2 「 OTen 
03 5 
enw , T p Humidity 
2022 占 7 , 120 20b0m202 07 , 1204 … 00 … 59

Blog Archive