Raspberry Pi‑Based Room Temperature Monitoring with Gnuplot Graphs and Email Alerts
In a high‑performance computing environment, maintaining optimal ambient temperature is critical. The following guide explains how to build a reliable, real‑time temperature monitoring system using a Raspberry Pi, a USB temperature/humidity sensor, Gnuplot for visual analytics, and Gmail for automated alerts.
Step 1: Hardware Setup
Connect the USB temperature/humidity sensor directly to a Pi’s USB port. For low‑power sensors the Pi’s native 5 V supply is sufficient; for higher‑power devices use a powered hub to avoid overloading the Pi.
The sensor streams a serial string such as:
temperature=20.9°C humidity=62.7% dewpoint=13.0°C
A Python script reads this data every five minutes, timestamps it, and writes three rolling logs: daily.dat, 24hour.dat, and 48hour.dat. These files feed Gnuplot to generate up‑to‑date visualizations.
Step 2: Software – Web Server & Dependencies
Install Apache to host the monitoring dashboard:
sudo apt-get install apache2
Install the required Python packages:
sudo apt-get install python-serial python-gnuplot
Place the dashboard’s HTML files in /var/www/html. The page pulls the latest PNG images (daily.png, 24hour.png, 48hour.png) generated by Gnuplot.
Step 3: Email Alert Configuration
Create a dedicated Gmail account for alerts (any SMTP‑capable server works with the correct port settings). In the Python script, configure the SMTP details:
from_address = "[email protected]" username = "[email protected]" password = "your_email_password"
Define recipients:
to_addresses = ["recipient1@example.com", "recipient2@example.com"]
When the temperature exceeds a predefined threshold, the script sends an email containing the relevant Gnuplot image so recipients instantly see the severity.
Step 4: Serial Parsing & Data Logging
Configure the serial port to match the sensor’s 9600 bps, 8‑N‑1 format:
import serial
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
Parse the incoming string by locating the “temperature” keyword and extracting the numeric value. Store the timestamped reading into the three log files:
from time import strftime, localtime
timestamp = strftime("%d%b%Y %H:%M:%S", localtime())
# Append to files
Step 5: Gnuplot Graph Generation
Use Gnuplot to convert the log files into PNG images. Example script for the daily graph:
import Gnuplot
p = Gnuplot.Gnuplot(debug=0)
p('cd "{path}"')
p('set xdata time')
p('set timefmt "%d%b%Y %H:%M:%S"')
p('set format x "%H:%M\n%d%b"')
p('set title "Daily Current Temperature Display"')
p('set key off')
p('set grid')
p('set xlabel "Time\nDate"')
p('set yrange [15:35]')
p('set ylabel "Temperature (°C)"')
p('set datafile missing "NaN"')
p('set terminal png size 800,400')
p('set output "daily.png"')
p('plot "daily.dat" using 1:($3) with lines')
Repeat with appropriate file names for the 24‑hour and 48‑hour views.
Step 6: Dashboard & Alert Logic
The Apache‑served HTML page refreshes the PNG images every minute, providing a live visual snapshot. The Python script checks the latest temperature; if it exceeds the user‑defined limit, it triggers an SMTP email with the latest graph attached.
This setup offers a low‑cost, open‑source solution for continuous environmental monitoring, ensuring both immediate alerts and historical data visualization.
Manufacturing process
- Connect Multiple DS18B20 1‑Wire Sensors to a Raspberry Pi for Accurate Temperature Monitoring
- Efficiently Monitor Room Temperatures with Raspberry Pi and Nagios
- How to Read Temperature with a DS18B20 on Raspberry Pi 2
- Home Temperature & Humidity Monitor with Raspberry Pi & Web Dashboard – Real‑Time Remote Tracking
- Professional Raspberry Pi Temperature Monitoring with DS18B20
- Measuring Temperature on Raspberry Pi with Maxim 1‑Wire Sensors and DS2482 I2C Bridge
- Home Energy Centre: Monitoring Solar PV, Thermal Panels, and Room Temperatures with Raspberry Pi and Moteino
- Accurate Temperature Monitoring in a Server Closet with Raspberry Pi
- Build a Multi‑Sensor Temperature & Light Monitoring System with Raspberry Pi & DS18B20
- Build an Internet‑Controlled Video‑Streaming Robot with Arduino & Raspberry Pi