May 20, 2019
Hot Topics:

Play It Cool: Incorporating Reporting Mechanisms from Physical Devices

  • August 23, 2006
  • By Steve Schafer
  • Send Email »
  • More Articles »

Thermal problems have been a major bane of computers since the very first computer was plugged into AC power. Despite server rooms with raised white flooring and high-end Leibert air conditioners, and over-clocked gaming rigs with water-cooling on the chipsets, heat continues to be a problem that computer administrators and technicians can't ignore.

In the first article of this series, Play It Cool: Remote Monitoring of Equipment Room Temps, a solution was presented for connecting a temperature gauge to your computer and then programmatically accessing it with a number of scripts. In this article, you'll explores how to monitor and report on this information. More importantly, you'll learn how to create a script to audibly announce the current temperature.

Note: This series of articles uses Linux as the operating system of choice, with scripts written for the shell (Bash) and in Perl. For the tasks outlined within this series, I found Linux to be ideal. If you are using a different programming platform, or if you are unable to replicate these methods on Linux, then you should still gain value from these articles. Where possible I will point out analogous possibilities in Windows and other operating systems.

Reporting Methods

At this point, I had a working sensor and script. Using a variety of methods, I could easily keep myself apprised of the current temperature of my office. The following sections discuss some of the possible reporting solutions.

Maintaining a Textual Log

At bare minimum, I wanted to keep a plain old text log of the temperature. The script shown in Listing 1 accomplishes this goal, with log entries similar to the following:

2006-07-26      15:30      73.7

Listing 1: Appending the current temperature reading to a log file



# Get the current date and time
date=‘date -I’
time=‘date +%H:%M‘

# Get the temperature

# Append data to log
echo -e "$datet$timet$temp" >>$logfile

With minimal effort, the same data could be stored in a MySQL database, thanks to the capabilities of the MySQL console application. The code snippet in Listing 2 shows the basics for inserting the data in a database by using the console-this snippet would be appended to the script in Listing 1.

Listing 2: Adding the data to a MySQL database


cat <<QUERY >./query.tmp
USE $db;
INSERT INTO $db.$table VALUES ($date, $time,$temp);


mysql -u $user -p $pass <./query.tmp
rm -rf ./query.tmp

Email Readings

The output from the reading script can easily be piped into a mailer. This allows the current temperature to be sent to any off-site address-including my cell phone. For example, consider the script shown in Listing 3.

Listing 3: Piping the temperature reading to an emailer (mail_temp.sh)


# Email address to send to (my Sprint phone)

# Get the temperature

# Build the message
cat <<MSG  >./message.tmp
The current office
temperature is:  $temp


# Send message and clean up
mail -s "Current Office Temp" $mailaddr <./message.tmp
rm -rf ./message.tmp

With a little extra coding only temperature readings over a certain threshold would be emailed. For example, the following if() clause could be used to decide whether a message should or should not be sent:

result=`echo "$temp >= $threshold" | bc‘
if [ "result" = "1" ] ; then
  # Email temperature
  # Do not email temperature

Place Temperature Reading on Web Page

The output could also be redirected to a Web page, where I could monitor it from any terminal with an Internet-connected browser. Listing 4 shows a script to accomplish this task.

Listing 4: Placing the temperature reading on a Web page (web_temp.sh)


# Get the current date and time
date=‘date -I‘
time=`date +%H:%M`

# Get the temperature

# Place temp on an HTML page
cat <<HTML >./officetemp.tmp

$date $time - $temp

</body> </html> HTML mv ./officetemp.tmp /var/www/officetemp.html

This script creates a simple Web page with the data in a format similar to the following example:

2006-07-28  15:25 - 73.4

The Same Old Problem

As these examples have shown, the structure for the temperature reading is very flexible-the data can be sent easily to numerous places. However, therein lies the problem-I still had to be physically located at or have access to the places where the data was sent, and had to actively monitor the temperature. What I needed was a way to monitor the temperature passively. The solution hit me while listening to a grandfather clock.

"The Current Core Temperature Is…"

I decided to create an audible temperature notification. That is, at preset intervals the computer would speak the temperature-loud enough to be heard in and around the office, but not loud enough (or often enough) to be an annoyance. Then, just like the grandfather clock chimes, I could be aware of the temperature of my office without actively having to seek it out.

The first thing I needed was a voice. Being a geek and a science fiction fan, I settled on a female computer voice. I asked my wife to record the following sound files, which I converted to standard WAV format:

"The current core temperature is"


60.wav, 70.wav, 80.wav
"sixty," "seventy," "eighty"

1.wav, 2.wav, 3.wav, 4.wav, 5.wav, 6.wav, 7.wav, 8.wav, 9.wav
"one," "two," "three," "four," "five," "six," "seven," "eight," "nine"

Note: I could afford to be fairly selective in my recording, as I didn't expect the temperature to fall below 60 degrees or exceed 89.9 degrees.

Now I needed a script to break down the temperature reading into bits that could be mapped to the appropriate sound files, and a command-line WAV player to play the files in sequence.

Page 1 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date