In my previous post, I was writting about how to graph temperature and humidity from AM2302 sensor on RasberryPi. In addition, we will add dewpoint monitoring. We need two variables to calculate dewpoint, temperature and humidity. I took some already made scripts and combined them together to fit my needs. I wanted to calculate dewpoint completely with bash and bc, but since I’m to lazy, I just used the python script from this blog.
Get to the root shell (we don’t want to type sudo everytime):
sudo -s
Create python script (for dewpoint calculations):
pico /opt/dewpoint.py
Paste the code, save and exit (CTRL + C), Y, ENTER
import sys import numpy as np # approximation valid for # 0 degC < T < 60 degC # 1% < RH < 100% # 0 degC < Td < 50 degC # constants a = 17.271 b = 237.7 # degC # sys.argv[0] is program name T=float(sys.argv[1]) RH=float(sys.argv[2]) def dewpoint_approximation(T,RH): Td = (b * gamma(T,RH)) / (a - gamma(T,RH)) return Td def gamma(T,RH): g = (a * T / (b + T)) + np.log(RH/100.0) return g Td = dewpoint_approximation(T,RH) print Td
Make the script executable:
chmod +x /opt/dewpoint.py
Create plugin file:
pico /etc/munin/plugins/dewpoint
Paste the code, save and exit (CTRL + C), Y, ENTER
#!/bin/sh case $1 in config) cat <<'EOM' graph_title Dewpoint graph_vlabel Celsius graph_category AM2302 dewpoint.label Temperature dewpoint.draw AREASTACK dewpoint.colour 403075 EOM exit 0;; esac humidity=$(/opt/lol_dht22/loldht 7 | grep -i "humidity" | cut -d ' ' -f3) temperature=$(/opt/lol_dht22/loldht 7 | grep -i "temperature" | cut -d ' ' -f7) printf "dewpoint.value " python /opt/dewpoint.py $temperature $humidity
chmod +x /etc/munin/plugins/dewpoint
Open munin-node file:
pico /etc/munin/plugin-conf.d/munin-node
Add the line at the end of the file, save and exit:
[dewpoint*]
Restart services:
munin-node-configure /etc/init.d/munin-node restart