Tag Archives: linux

Temperature and humidity graph with raspberry pi

Top posted update:
Now it looks like this
pre-requisites:

  • a pinch of pygal
  • 1 raspberry pi (I used model B)
  • breadboard + accessories
  • DHT22 (or equivalent)

I just followed Adafruit’s tutorial for the wiring and the software
Then I did a slight modification to the script provided by Adafruit to write the data to a log file (temp-hum.log) instead of google drive spreadsheet.

Actual work
Updated code on Github
To generate the log file that will be parsed by pygal on github
Adafruit’s code for the sensor forked on github

A short python script to generate the graphic using Pygal:

#!/usr/bin/env python

import pygal

temp = []
hum  = []

logdata = open('temp-hum.log','r')
for line in logdata.readlines():
  line = line.split()[1:]
  temp.append(float(line[0]))
  hum.append(float(line[1]))

print(temp)
print(hum)

line_chart = pygal.Line(width=1200)
line_chart.title = 'Temperature Humidity'
line_chart.add('Temperature *C', temp)
line_chart.add('Humidity %', hum) 
line_chart.render_to_file('temp-hum.svg')
breadboard and flat cable
breadboard and flat cable
DHT22 and cables
DHT22 and cables
r-pi and all
r-pi and all
Adafruit_DHT
Adafruit_DHT
DHT22 sensor
DHT22 sensor
breadboard
breadboard
r-pi with sensor
r-pi with sensor

And the graphic looks like:
this

Sources: Adafruit DHT22 tutorial

Raspberry pi: installing lighttpd + php


root@raspberrypi-2:/home/pi# apt-get install lighttpd php5-cgi
[...]
root@raspberrypi-2:/home/pi# lighty-enable-mod fastcgi-php
Met dependency: fastcgi
Enabling fastcgi-php: ok
Enabling fastcgi: ok
Run /etc/init.d/lighttpd force-reload to enable changes
root@raspberrypi-2:/home/pi# invoke-rc.d lighttpd force-reload
[ ok ] Reloading web server configuration: lighttpd.

set vim as default editor


update-alternatives --config editor
There are 3 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
------------------------------------------------------------
* 0 /bin/nano 40 auto mode
1 /bin/nano 40 manual mode
2 /usr/bin/vim.basic 30 manual mode
3 /usr/bin/vim.tiny 10 manual mode

emptying huge log files with `find`

this will list the files:
find /var/log/ -name "*.log*" -size +10000000c -type f -exec ls -lh {} \;

this will empty the files:
find /var/log/ -name "*.log*" -size +10000000c -type f -exec sh -c '> $1' -- {} \;