Expandmenu Shrunk


DS1820 Temp. monitoring using Linux and Cacti

This article will try to explain how to monitor and graph temperatures remotely using Dallas Semiconductor DS18xx sensors, SNMP and Cacti. DS18xx sensors are relatively cheap, accurate and multiple sensors can be connected to a single bus.

This guide is based on Ubuntu, so YMMV on other Linux/Unix based systems and may need modification to work properly.

Interfacing and software

To directly read out DS18xx sensors you need the following things:

– a Linux server running the software package digitemp (available on various platforms) and net-snmp

– a serial to 1-wire adapter (DS9097 or build one yourself with the following schematic)

– an installation of cacti running on a remote or local server

Setting up the hardware of the 1-wire network is outside the scope of the article. You can find lots of  guides to cabling and building interfaces on Google.

Testing and reading out sensors

When everything is connected properly you can try to read out the sensors. Make sure digitemp is installed and enter the following command  (this command assumes your first serial port is /dev/ttyS0, for USB serial adapters try /dev/ttyUSB0)

digitemp_DS9097 -w -s /dev/ttyS0

Digitemp should search (walk, hence the “-w”) the network and find sensors if they are connected:

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
..
Devices on the Main LAN
10A67CF501080074 : DS1820/DS18S20/DS1920 Temperature Sensor
10DF7DF5010800B7 : DS1820/DS18S20/DS1920 Temperature Sensor

In the example above two DS18xx sensors are found. If no sensors are found, check your cabling and sensors. It is also best to run as root to make sure there are no permission issues.

To make digitemp remember the sensors you have to store the settings in a configuration file. You can do a walk and configuration using the following command:

digitemp_DS9097 -i -s /dev/ttyS0

It should report the connected devices and confirm that it wrote a configuration file:

DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
..
Searching the 1-Wire LAN
10A67CF501080074 : DS1820/DS18S20/DS1920 Temperature Sensor
10DF7DF5010800B7 : DS1820/DS18S20/DS1920 Temperature Sensor
ROM #0 : 10A67CF501080074
ROM #1 : 10DF7DF5010800B7
Wrote .digitemprc

It is best to move the configuration file to a central location, for example I use /etc/digitemp/digitemp.conf.  If you have multiple sensors you might be confused which sensor is which.  A simple way to check which sensor you are measuring is to hold it in your hand and probe the sensor indexes using the following command:

digitemp_DS9097 -t 1 -c /etc/digitemp/digitemp.conf

In this example, the sensor with index “1” is measured. In the configuration file, the unique adresses of the sensors are listed so you can look them up or change the index of a device.

Interfacing with SNMP

To make interfacing with SNMP easy I wrote a script that reads out a sensor based on the index number and returns the temperature:

#!/bin/bash
# digitemp readout script

CONFFILE=/etc/digitemp/digitemp.conf

digitemp_DS9097 -t $1 -c $CONFFILE  | awk {' print $7'}| tail -n 1

This script takes the index as an argument and returns the temperature for that sensor, with all the other info stripped off. The awk command only prints the 7th column and that is piped to tail to only display the line the temperature was displayed on.

To couple this script to SNMP you have to add the following lines to /etc/snmpd.conf:

extend .1.3.6.1.4.1.2021.2000.1 temp0 /usr/local/bin/checktemp 0
extend .1.3.6.1.4.1.2021.2000.2 temp1 /usr/local/bin/checktemp 1

Shown here are two scripts coupled to different SNMP OIDs, both returning the script output for one of the connected sensors. Make sure the SNMP daemon has sufficient rights to access the serial port! On my Ubuntu 10.04 system I had to add the user “snmp” to the group “dialout” in the /etc/group file.

To test the scripts coupled to the SNMP OIDs, read them out using snmpwalk:

snmpwalk -v1 -c public localhost .1.3.6.1.4.1.2021.2000.2
UCD-SNMP-MIB::ucdavis.2000.2.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.2000.2.2.1.2.5.116.101.109.112.49 = STRING: "/usr/local/bin/checktemp"
UCD-SNMP-MIB::ucdavis.2000.2.2.1.3.5.116.101.109.112.49 = STRING: "1"
UCD-SNMP-MIB::ucdavis.2000.2.2.1.4.5.116.101.109.112.49 = ""
UCD-SNMP-MIB::ucdavis.2000.2.2.1.5.5.116.101.109.112.49 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.2000.2.2.1.6.5.116.101.109.112.49 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.2000.2.2.1.7.5.116.101.109.112.49 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.2000.2.2.1.20.5.116.101.109.112.49 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.2000.2.2.1.21.5.116.101.109.112.49 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.2000.2.3.1.1.5.116.101.109.112.49 = STRING: "24.25"
UCD-SNMP-MIB::ucdavis.2000.2.3.1.2.5.116.101.109.112.49 = STRING: "24.25"
UCD-SNMP-MIB::ucdavis.2000.2.3.1.3.5.116.101.109.112.49 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.2000.2.3.1.4.5.116.101.109.112.49 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.2000.2.4.1.2.5.116.101.109.112.49.1 = STRING: "24.25"
End of MIB

For some reason the output of the script is displayed multiple times. I always use the most unique OID (in this case the last OID on the output) and it seems to work all the time, no problems whatsoever. If SNMP is running and accessible by either the localhost or a remote server running cacti, you can read out the temperature from Cacti.

Graphing the output in Cacti

To graph a single temperature in Cacti is quite simple. Generate a new data source using the SNMP –  Generic OID template, fill in the OID and Cacti will poll the data every 5 minutes. To graph the data source, create a graph using the SNMP – Generic OID graph template. Under Graph Item Fields you can select the data source containing the SNMP data. Save the settings (Cacti could ask for a min and max value, enter something between -20 and 100 ) and the temperature should now be graphed. You can find additional Cacti documentation on this subject here.

8 Responses to DS1820 Temp. monitoring using Linux and Cacti

  1. Ieder z’n hobby :P

  2. Wat zijn jouw hobbies? Gare blek vinyl sparen en luisteren? :P

  3. Trouwens, dit is wel enigszins blek verantwoord, je kan met een oogopslag zien of het buiten “grim and frostbitten” is ;)

  4. Idd. heb laatst een platenspeler aangeschaft. Dus nu kan ik eindelijk al die gare platen luisteren die ik al 10 jaar heb staan :P Heb alweer een stapeltje lp’s die weg kunnen. Interesse?

  5. Je bedoelt dus dat je gewoon te lui bent om even je kop/arm het raam uit te steken…? ;P

  6. Great! Nice tutotrial. Thanks!

  7. Kiitos :)

  8. Pingback:JulietMikeBravo » Blog Archive » Online geiger counter using Arduino and Cacti