To get the necesary Temperature Information i used several DS18S20 and a OneWire to USB Adapter.
As i want to use several Scripts to work with the same Temperature Data i wrote a small Deamon to get the Temperature Data via digitemp and save it in “sensor” files under /tmp/sensorN. OneWire Fs only gave wrong Temperature Data (85°C) and the nodejs script got some serious problems with digitemp.
NOTE: I created two UDEV rules to get a “static” path for the two serial devices(Outlet and 1Wire Adapter)
cat /etc/udev/rules.d/44-ttyusb.rules ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A6XDT7AO", SYMLINK+="steckdose", ACTION=="add" ATTRS{idVendor}=="0403", ATTRS{idProduct}=="ea90", ATTRS{serial}=="10TK4WX6", SYMLINK+="onewire", ACTION=="add"
At first you need to initialize your digitemp config file:
digitemp -i -s /dev/onewire -c /etc/digitemp.conf
The next step is to create the Daemon under /usr/local/bin/onewire/onewire.pl:
#!/usr/bin/perl use strict; use warnings; use Proc::Daemon; use Proc::PID::File; MAIN: { # Daemonize Proc::Daemon::Init; # If already running, then exit if (Proc::PID::File->running()) { exit(0); } my $continue = 1; $SIG{TERM} = sub { $continue = 0 }; my $temperature; my $c = 0; my $sensor_count = 0; # Get Sensor # open DIGITEMPCONF, "<", '/etc/digitemp.conf' || die "Can't open /etc/digitemp.conf: $!"; while() { if($_ =~ m/SENSORS/) { my @tmp = split(' ',$_); $sensor_count = $tmp[1]; } } # filling sensor files arra< my @sensorfiles; for(my $i = 0; $i ", $sensorfile || die "Can't open $sensorfile: $!"; $temperature = 85; while ($temperature == 85) { $temperature = `/usr/bin/digitemp -c /etc/digitemp.conf -t$c -q -o"%.2C" -r1000`; } print $temp_sensorfile $temperature; print $temperature; close $temp_sensorfile; $c++; } $c = 0; sleep(15); } close DIGITEMPCONF; }
And a start stop script under /etc/init.d/onewire (install it with update-rc.d onewire defaults)
#!/bin/sh ### BEGIN INIT INFO # Provides: onewire # Required-Start: # Required-Stop: # Should-Start: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Starts the onewire "daemon" to provide onewire sensor datat under /tmp/sensorN # Description: Starts the onewire "daemon" to provide onewire sensor datat under /tmp/sensorN ### END INIT INFO PATH=/sbin:/usr/sbin:/bin:/usr/bin . /lib/init/vars.sh do_start () { /usr/local/bin/onewire/onewire.pl } do_status () { if [ -f /var/run/onewire.pl.pid ] ; then echo "onewire is running"; return 0 else echo "onewire is not running"; return 4 fi } do_stop () { killall onewire.pl } case "$1" in start|"") do_start ;; restart|reload|force-reload) do_stop rm /tmp/sensor* do_start ;; stop) do_stop ;; status) do_status exit $? ;; *) echo "Usage: onewire [start|stop|status]" >&2 exit 3 ;; esac :
After a lovely /etc/init.d/onewire restart you go the sensor data for each sensor under /tmp/sensorN
for example:
cat /tmp/sensor0 24.19
The sensor data will be updated every 15 seconds and the N in the sensor file is the same number you can find in the digitemp config (/etc/digitemp.conf).