Færa aflestur frá hitanema ds18b20 inn í graphite

 

#!/usr/bin/perl
use IO::Socket;

$mods = `cat /proc/modules`;
if ($mods =~ /w1_gpio/ && $mods =~ /w1_therm/)
{
# print "w1 modules already loaded \n";
}
else 
{
#print "loading w1 modules \n";
$mod_gpio = `sudo modprobe w1-gpio`;
$mod_them = `sudo modprobe w1-therm`;
}

my $carbon_server = '127.0.0.1';
my $carbon_port = 2003;

my $sock = IO::Socket::INET->new(
PeerAddr => $carbon_server,
PeerPort => $carbon_port,
Proto => 'tcp'
);

die "Unable to connect: $!\n" unless ($sock->connected);

my $time = time;

$sensor_temp = `cat /sys/bus/w1/devices/w1_bus_master1/28*/w1_slave 2>&1`;

if ($sensor_temp !~ /No such file or directory/)
{
if ($sensor_temp !~ /NO/)
{
$sensor_temp =~ /t=(\d+)/i;
$tempreature = (($1/1000)-0);

# print "Heima.Nemi2 = $tempreature $time\n"; 
$sock->send("Heima.Nemi2 $tempreature $time\n");
exit;
}
die "Error locating sensor file or sensor CRC was invalid";

}

 

 

 

graphite