# Remote Temperature Monitoring with Linux

in
Use a small footprint Linux with some cheap hardware to create a remote temperature monitor.
Software Choices

Two choices were available to perform resistance-to-temperature conversion in the script. I could use a lookup table with pairs of resistance-to-temperature values in an array. The sheer number of elements in this array would be a drawback to this approach. A span from -40 degrees C to +40 degrees C requires 81 (don't forget 0 degrees C) pairs of values. There was no easy way to manipulate a text file available from the thermistor manufacturer, and entering the values by hand would take time and be prone to errors.

Instead, I used what's called the Steinhart-Hart equation (see sidebar). The equation was developed in the late 1960s to help process ocean temperature data collected with thermistors and provides direct conversion of resistance to temperature. A spreadsheet utility found on the Web helped with calculating coefficients unique to each family of thermistors and was used in the equation.

Display Data

Once the script calculates temperature from a multimeter reading, it needs to be displayed or stored. With this in mind, I extended the test script to convert and display temperature, and show the time and resistance reading. University Linux uses the 2.0 kernel, and root user login by Telnet is allowed. When ordinary users attempt to run the grabtemp.pl script, an error is displayed because of the file permissions used for the serial port, /dev/ttyS1. I fixed this by changing permissions with:

```chmod a+x /dev/ttyS1
```

Now, ordinary users could log in and run the script to check temperature. They wouldn't need root access.

Here is the output from the resulting showtemp.pl script:

```/perlserial: perl -w showtemp.pl
01-05-2006 14:43 34 F 1.3 C 30.52 k Ohms
```

Here you can see the date, time, temperatures in degrees F and degrees C, along with the actual resistance reading. I checked the temperature where the sensor was located and found that the reading was accurate, so the conversion formula part of the script worked.

Not too many computer users are comfortable with using a command-line program interface. Web browsers with a point-and-click interface are a lot less intimidating. So, I extended the script once again to allow users to operate the system with a Web browser.

With the thttpd server configured and running, it was just a matter of directing the output from the script to build a Web page for display. This was fairly straightforward as the following code shows: shows:

```
print "content-type: text/html \n\n";
print "<HTML><BODY><P>";
print "<H2>Mechanical Room</H2> ";
print '<form action="webtemp.pl" method=post> <P> <P>';
print "Interior Air Temperature = \$out_tempF<BR>";
print "<BR>";
print "<BR>";
print "Date: \$out_date  <BR>";
print "Time: \$out_time  <BR>";
print "<BR>";
print "</form>";
print "</BODY></HTML>";

```

Running the webtemp.pl script from /cgi-bin gives the user a display like the example shown in Figure 1.

Figure 1. The temperature monitor now has a Web interface.

This example shows the temperature in the room as well as the time and the date of the reading. You can press the Update Reading button to rerun the script and display another temperature value.

It is easy to write an extension to the script to log temperature over time. I put a line in the rc (boot) script that launches a data logging script, which then runs continuously in the background. I found that I could use measurement intervals of 5-10 minutes, because changes in air temperature are slow indoors in an air-conditioned space.

You can access the temperature log through the command line by using Telnet. Because the format was space-delimited, the date file was used with Microsoft Excel to plot graphs and view trends. You can see a sample output in Figure 2.

Figure 2. A sample set of values kept in the temperature monitoring log as seen through Telnet.

Security Concerns

The overall objective was to create a reliable and easy-to-use electronic means to display and record temperature data. When you actually deploy the system, the location of the system and the network connection can vary widely. Depending on circumstances, you have to evaluate the security concerns for each installation. You may have to implement some workarounds to address the security concerns. For example, you can log temperature readings in the form of text or HTML pages by a script running in the background and not by a script in the cgi directory, which isolates the logging process from Web access. Alternately, you can gather data from this server using another secure server through FTP or HTTP. This would add another layer to prevent direct access by the outside world, but still make the information available.

______________________

## Comment viewing options

### Try ipmitool

Try ipmitool - read the man page.

### Linux Temperature Sensor

I know this is an old post, but if your looking for a temperature sensor to use with Linux, try a google search for DirecTemp or contact Quality Thermistor.

They have a virtual serial version that works well.

### Alternative solution

Nice article about connecting digtal multimetr to Linux box. In the case you just want to measure temperature, you can find several other solutions on the web. One of them is
http://www.digitemp.com/
That one uses network of digital temperature sensors (DALLAS DS1820). From my point of view it is cheaper and more better solution for your needs and you don't need to solve "ugly" DTR/RTS hacks.

Other similar projects to connect sensors with I2C or Dallas interface to serial or prallel port exists as well...

### RTS?

``` If I connected the multimeter serial interface cable RTS to the RTS pin of the second serial port, the multimeter would be faked into seeing the correct line setting. ```

Why not just tie RTS to ground to pull it low?

You can't assume that everyone has a second serial port or that it won't be initialized, sending that RTS line high too.

### DTR, RTS & Linux

DTR & RTS signals, are you kidding? Yes, I know these signals are not supported well in Linux. You selected nice hw workarround. I selected hardware workarround in the past too.

Windows users don't need such workarrounds. Why Linux should? Why everyone only uses hw workarround and doesn't fix it in proper way in driver and user utilities? Are developers in Linux world just ignorants? I understand why Linux don't have (open source) NVidia and ATI drivers, and drivers for special hardware (like WiFi cards, etc). But I don't understand why problem with RTS and DTS on serial ports wasn't solved long time ago...