Skip to content

Instantly share code, notes, and snippets.

@stefansbv
Created September 24, 2017 12:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefansbv/4b22c3e825178eddede1d800f03872a9 to your computer and use it in GitHub Desktop.
Save stefansbv/4b22c3e825178eddede1d800f03872a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use HiPi::Device::OneWire;
my @devices = HiPi::Device::OneWire->list_slaves();
for my $w1 ( @devices ) {
for ( qw( id family name description ) ) {
print qq($_ = $w1->{$_}\n);
}
my $data = HiPi::Device::OneWire->read_data( $w1->{id} );
process($data);
}
sub process {
my $data = shift;
my @lines = split /\n/, $data;
if ($lines[0] !~ m/YES/){
print "CRC Error:\n$data\n";
}
else {
print "Temp is ", get_temp($lines[1]), "\n";
}
}
sub get_temp {
my $text = shift;
( my $raw ) = $text =~ m/t=(\d+)/;
my $temp_c = $raw / 1000.0;
return $temp_c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment