I am just getting into this and whilst I can display the temp via SSH, I am struggling with displaying it on the little webpage I setup on my Pi running Apache2. I followed this example http://www.raspberrypi.org/phpBB3/viewtopic.php?t=35487&p=310038 which included some AJAX and a script in the cgi-bin directory, but I get an error saying that $ was not defined
and being really clueless with JavaScript, I have no clue where the error lies. I am wondering if it could be the cgi-bin directory. I just created it and could not locate info on whether or not I had to do anything special to enable its use for scripts. Can anyone answer that question for me? If it is relevant, I am running latest version of Raspbian.
Eventually, I want to log the values to a database and graph from it, but first things first. :)
Main question is how can I display the temperature on my webpage from the internal sensor?
EDIT
I will try the first suggestion later tonight when I get home, but I quickly got the second one (Lenik) going which seems to be working good. I had to make some edits though to get it to work. The script wouldn't create the rrd file so I manually created it by using the syntax he used in the script. I also modified the UPDATE
command since it didn't like the value that was being passed to it. I had to remove the width
portion from the GRAPH
command because it threw an error as well. Then at the end, I added a cp
so that it places the file in the images directory of the website and then added */5 * * * * /home/root/scripts/temprec.sh >/dev/null 2>&1
to my crontab so it runs every 5 minutes. It seems to be working, but with only 4 samples so far it is difficult to know for sure. Within an hour or so I'll have a better idea if my edits have worked.
#!/bin/bash
#
# update .rrd database with CPU temperature
#
# $Id: update_cputemp 275 2013-05-16 05:20:56Z lenik $
# Thanks to Lenik @ Raspberrypi.stackexchange.com.
cd /path/to/scripts
# read the temperature and convert .59234. into .59.234. (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`
/usr/bin/rrdtool update cputemp.rrd N:$TEMPERATURE
/usr/bin/rrdtool graph cputemp.png DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00
cp /path/to/scripts/cputemp.png /path/to/website/images