

That just gives jQuery an element with the “piTemp” ID to reference in the JS. Then, wherever you want to see the Pi’s temp text, add a tag like this: Now we just need to call that getData() function each time the page is loaded so we do that in the body tag’s onLoad: That bit of JavaScript uses jQuery’s ‘get’ function to read the text file and then jQuery’s text function to set that text into the element with the ID of “piTemp” (which is case- sensitive). Then add this block of JavaScript or something very similar to the section: In that file, we’re going to use jQuery to read the text file, with something like this:

#MONITOR CPU TEMPERATURE RASPBERRY PI HOW TO#
If you don’t have one of those setup yet, you probably want to go search for how to set that up and then come back here to finish this setup.Įdit your html file or whichever web page you want to add the Pi’s temperature to:
#MONITOR CPU TEMPERATURE RASPBERRY PI CODE#
Now we just need to add some code to the home page running on the Pi’s web server. If you want to tweak that I recommend using the awesome Cron tool at .Īgain, when you’re happy with that, press Ctrl-X and then type Y to save and exit. That tells the OS to run the checktemp.sh script once every 15 minutes, on ever day.

In the crontab screen, add this line to the end of the listing: Now we schedule that to be run on a regular basis with cron: You should see the temperature output and there should also be a new file out at the www/html folder. Run that to test it and make sure it’s working as you want: Once you’ve got all that in the nano screen, press Ctrl-X and then type Y to save the file and exit nano.

and the GPU temperature from vcgencmd (in Celsius),.gets the Pi’s CPU temperature from a system file under /sys/class/….# get the CPU temp in Celsius as a numberĬpu=$( $(/opt/vc/bin/vcgencmd measure_temp)"įar=$(echo - | awk -v cpu=$cpu '')Ĭurrentdatestamp=``date +"%A, %b %d, %Y %I:%M %p"`` message="Pi temp $far2 degrees F - as of "Įcho $message $currentdatestamp > /home/pi/www/html/pitemp.txt Get yourself into the Pi user’s home folder:Įxecute this command to create the shell script: Here’s what that looks like now that it’s all setup:ġ - Write a shell script to get the temp and save it into a text file.Ģ - Run that on a regular basis via cron (a crontab file really).ģ - Add some JavaScript and HTML to the Pi’s web page which reads that text file and then adds that info to the page.Īnd here are the details (these steps assume you have Raspbian running as the operating system on the Pi but if not, you will need to adjust to use whatever text editor or other things you have) So I then figured out how to get the Pi’s html home web page to include that info. I recently figured out how to determine the core CPU and GPU temperatures for my new Raspberry Pi 4 by way of a shell script, and it didn’t take long before I got tired of running that manually.
