Raspberry Pi CPU Temperature
After finding some free time recently, I decided to come back to my Raspberry Pi, so I whipped up a quick website. I currently have the Apache server with PHP running on my Model B Pi. I like webpages that have a link to something in the real world, so I made a page that shows the temperature of the Raspberry Pi CPU. You can view the HTML, CSS, and PHP code right here. The HTML code is pretty basic; just the regular tags for the simplest of webpages. One interesting tag, though, is the <meta> tag, which tells the viewer's browser to automagically refresh the page every 10 seconds to display the most up-to-date CPU temperature information. All that the CSS does is give the PHP-generated text some snazz, centering it, making it larger, and coloring it. The CSS also gives the page a nice repeating background image (located on the Raspberry Pi in the same directory as the webpage), available here. The PHP code is the really interesting part. It may be intimidating; I condensed it so save space. However, it really isn't all that complicated. The first line executes the command "cat /sys/class/thermal/thermal_zone0/temp" and assigns its output to the variable "$outarray". The command just reads the Raspberry Pi CPU temperature file, located at "/sys/class/thermal/thermal_zone0/temp". This file contains the Raspberry Pi's CPU temperature in millidegrees Celsius. "$outarray" is apparently an array, so the next line treats it as such, reading the zeroeth element, dividing that by 1,000 to get degrees Celsius, and then multiplying it by 9/5 and adding 32 to get Fahrenheit. It then assigns this temperature to the variable "$temperature". The last line of the PHP code echos (prints on the webpage) this result, using the "round()" command to get rid of unnecessary decimal places. Directly after this block of PHP code is "°F", which codes for the degrees symbol and then an "F" to represent Fahrenheit. Thus, the end result might be "101.3°F". I am quite pleased with the results- I have a nicely-formatted auto-updating webpage that shows my Raspberry Pi's CPU temperature in Fahrenheit. Have a blast, and don't bake your Raspberry Pi!