Hi,
If you are using the Raspberry Pi's inbuilt 1-wire modules (wire, w1-gpio & w1-therm) then as far as I know, the only way to read the temperatures is with the cat command.
There are other ways of running a 1-wire network from the Pi. These use small hardware devices that manage the 1-wire timing and communication, and the Pi does simple communication with the device. The upside of these devices is that the timing of the signals on the 1-wire network is mainly hardware controlled and is highly accurate, compared to the Pi's system where the timing is software generated and more susceptible to errors.
The downside is that the hardware devices cost money! For small networks, particularly if you have some software checking of results with automatic re-reads, the Pi's system will be OK.
There are USB dongles that provide 1-wire connection and management, although I have not used one, and there is software to manage the communication between the Pi and the USB connected device (you won't be using 'cat').
The other device (that I have used) is the HA7s from Embedded Systems
http://www.embeddeddatasystems.com/HA7S ... _p_23.html
This device communicates with the Pi using the UART - a simple serial communication on pins 8 and 10.
They claim that up to 100 devices can be connected and it will work on up to 1000 feet of cat 5 cable.
It's other advantage is that you are not limited to temperature measurement - other 1-wire devices can be used. Also you can interact with the temperature sensors, for example to change measurement sensitivity and to use the alarm features of the sensors. To use the HA7s with the Pi, all you need is some simple serial communication using the UART (/dev/ttyAMA0).
Using the Pi's inbuilt system on pin 7, you can do all the work using a bash script. Here is the script I used:
Code: Select all
#!/bin/bash
# a script to read and save temperature readings from all the group 28 1-wire temperature sensors
#
# get all devices in the '28' family
FILES=`ls /sys/bus/w1/devices/w1_bus_master1/ | grep '^28'`
# iterate through all the devices
for file in $FILES
do
# get the 2 lines of the response from the device
GETDATA=`cat /sys/bus/w1/devices/w1_bus_master1/$file/w1_slave`
GETDATA1=`echo "$GETDATA" | grep crc`
GETDATA2=`echo "$GETDATA" | grep t=`
# get temperature
TEMP=`echo $GETDATA2 | sed -n 's/.*t=//;p'`
#
# test if crc is 'YES' and temperature is not -62 or +85
if [ `echo $GETDATA1 | sed 's/^.*\(...\)$/\1/'` == "YES" -a $TEMP != "-62" -a $TEMP != "85000" ]
then
# crc is 'YES' and temperature is not -62 or +85 - so save result
echo `date +"%d-%m-%Y %H:%M:%S "; echo $GETDATA2 | sed -n 's/.*t=//;p'` >> /var/1w_files/$file
else
# there was an error (crc not 'yes' or invalid temperature)
# try again after waiting 1 second
sleep 1
# get the 2 lines of the response from the device again
GETDATA=`cat /sys/bus/w1/devices/w1_bus_master1/$file/w1_slave`
GETDATA1=`echo "$GETDATA" | grep crc`
GETDATA2=`echo "$GETDATA" | grep t=`
# get the temperature from the new response
TEMP=`echo $GETDATA2 | sed -n 's/.*t=//;p'`
if [ `echo $GETDATA1 | sed 's/^.*\(...\)$/\1/'` == "YES" -a $TEMP != "-62" -a $TEMP != "85000" ]
then
# save result if crc is 'YES' and temperature is not -62 or +85 - if not, just miss it and move on
echo `date +"%d-%m-%Y %H:%M:%S "; echo $GETDATA2 | sed -n 's/.*t=//;p'` >> /var/1w_files/$file
fi
# this is a retry so log the failure - record date/time & device ID
echo `date +"%d-%m-%Y %H:%M:%S"`" - ""$file" >> /var/1w_files/err.log
fi
done
exit 0
# before using this script you need to make a folder for the data files
# sudo mkdir /var/1w_files
# then create files for each device e.g. /var/1w_files/28-0000018a4be8
# 28-0000018a4be8 is one of your 1-wire devices and will be the filename for its data
# and create a file for the error log:
# /var/1w_files/err.log
# The bash script will need to be made executable for you
# sudo chown <username> <script name>
# sudo chmod 0700 <script name>
The script can then be automatically called at regular intervals using crontab
(add the script path/filename and read frequency to crontab by entering crontab -e in a terminal)
Now you have a nice log file with date & time stamp and temperature readings for every temperature sensor
Then you can create charts and statistics
Regards
anita2R