Plotting the temperature of your PI

If you are living in Arizona and you have a PI outside, you might want to keep an eye on its temperature. It might get a bit hot, and you might need to know how far you can push the PI before it starts acting funny...
So here is a recipe for doing this.


I'm assuming that

  • you will use two systems: The PI, and a regular system, which I will refer to as the "PC."
  • Both are on the same network, and you can ssh into the pi, and you know the IP address of the PI, or it has a name you can somehow resolve into an IP address.
  • you use the account "pi" on the pi.
  • you have the plot utilities package installed

Shell script on the pi:

  • copy the text below into a file ""

    while [ 0 ] ; do 
    (echo -n $(date +"%s ") " " ;cat /sys/class/thermal/thermal_zone0/temp)  >> temp_recordings ; sleep 60 ; done
  • run command

    chmod 755
  • To have script start on power-up run command

    crontab -e

    and add this line:

    @reboot /home/pi/

Set up ssh login without password

  • on the PC, if you do not already have a file ~/.ssh/, run the command
    You can give empty responses to all prompts.
  • scp the file ~/.ssh/ to the pi
  • on the pi, append the content of the transferred file to file .ssh/authorized_keys
    cat ~/ >> .ssh/authorized_keys
  • verify that you can ssh into the pi without the need of a password

If you want to publish your work to a web site, set up an appropriate folder there.

Set up the PC side of things

  • create a folder ~/bin
  • create the file ~/bin/ with the content below. Adjust the variables DIR, PI_IP, and (if you desire so) PUBLISH_URL

    set -x
    #local variables: 
    #folder in which the work happens and the url to which to publish
    #leave this blank if you don't want to publish
    #prep function. creates folder where the processing happens and
    #puts in the html template
    function prep
    mkdir -p ${DIR}
    cd ${DIR}
    <script type="text/JavaScript">
    function AutoRefresh( t ) {
    	setTimeout("location.reload(true);", t);
    //   -->
    <body onload="AutoRefresh(100000)">
    <img src=temp.png></img>
    #iter function. Does the work periodically
    function iter 
    rm -f `find . -type f | grep -v html | grep -v png|grep -v template`
    scp "pi@${PI_IP}:temp_recordings" .
    if [ $? -ne 0 ] ; then
    gnuplot <<EOF
    set terminal png
    set output 'temp.png'
    set grid back
    show grid
    set xtic 3600*24
    set xdata time
    set timefmt "%s"
    set key outside bottom
    set format x "%m/%d"
    plot "temp_recordings" using (\$1-7*3600):(\$2/1000) smooth cspline with lines lw 4 title 'temp_centigrade'
    cat abc.template | sed -e "s/replacing/$(date)/" > temp.html
    #publish if a url has been defined
    if [ "x${PUBLISH_URL}" != "x" ] ; then
      scp *.html *.png ${PUBLISH_URL}/.
    while [ 0 ] ; do iter ; sleep 600 ; done
  • run
    chmod 755 ~/bin/
  • on the PC, run the command
    crontab -e
    and add the following line

    @reboot ~/bin/

At this point you can reboot the PI and the PC, and the scripts should start running
if you are lucky, you should see a working example here.