What we’ll do in this step is to read the on-board CPU temperature of the ARM 3359 processor, every second and inform any attached browser of the most recent value. In an obscure forum discussion, I was able to find out my Debian BBB-specific distro makes this CPU temperature register location available at the /sys/devices/ocp.3/44e10448.bandgap/temp1_input – you may need to verify that this is available on your OS or if there is a slight variation of the location. Information on the bandgap register is available in the AM335x Technical Reference Manual (chapter 9). The temp_input file holds the current temperature (multiplied by 1000) – for example, in the image below, the CPU temperature is 53 C. On the web, you’ll see many caveats that this not an accurate measurement and should not be used for any serious application – but for our demo app, it serves the purpose of sending I/O changes from the BBB to any attached browser.
Node.Js CPU Temperature Server
Our node.js server does two things, first it serves up a web page, when requested, and secondly, every second it sends the latest temperature to all of the attached browsers.
Our first step to getting this working is to install socket.io using the node package manager (npm), which handles the transporting of temperature information to the browser.
Unexpected Detour to Fix Disk Size
I noticed that I was having problems doing any work, node started behaving weird and I started getting errors. I realized that the partition allocated for the Linux kernel on my SD card was full. While I had an 8GB SD lying around, I was able to stumble on this excellent set of instructions to expand the Linux kernel partition on my SD card, which allows me to continue to use my 4GB SD card, with a 10 minute procedure.
Here’s what my SD card’s Linux kernel partition looked like before:
Here’s the disk allocation after expanding the partition size:
And finally, after finishing up the resizing command:
What I learned from this detour is that a 2GB SD card shouldn’t be used for Debian on BBB, the 4GB is fine, but consider right-sizing the partitions beforehand and, if available, start with a 8GB SD.
Temperature Sensor App
So back from our tangent, we’re ready to test out reading the on-board temperature measurement and displaying it in (near) real-time to a connected browser. I’ve written a very small node.js app called bbbTemp which performs this function.
I found a very useful utility, called WinSCP, to allow me to transfer files to the BBB from my Windows machine. WinSCP gives me the luxury of doing development and testing in Windows, then fine tuning and minor debugging on the BBB. (It’s one of the nice little tools that deserves a donation – I gave mine and I hope that you will too.)
In next week’s post, I’ll share the code, but in the meantime, here’s a video of our application running: