Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
#THERE IS SECTION WHERE YOU CONFIGURE YOUR ONEWIRE TEMP SENSOR CODE!
my $device = "10-0008028fd655";
my $ret = 9999; # default to return 9999 (fail)
my $sensordata = `cat /sys/bus/w1/devices/$device/w1_slave 2>&1`;
# print "Read: $sensordata";
if(index($sensordata, 'YES') != -1) {
#fix for negative temps from http://habrahabr.ru/post/163575/
$sensordata =~ /t=(\D*\d+)/i;
#$sensor_temp =~ /t=(\d+)/i;
$sensordata = (($1/1000));
$ret = $sensordata*1000;
#SENT SENSOR DATA TO NETHOME change peerport to match you udp comminaction port what you create nethome and peeraddr to match your pi ip address if you run them same machine u can use 127.0.0.1
my $sock = IO::Socket::INET->new(
Proto => 'udp',
PeerPort => 8005,
PeerAddr => '127.0.0.1',
) or die "Could not create socket: $!\n";
#THERE YOU NEED ADJUST UPM.DeviceCOde,X,HouseCode,X section to match your upm sensor in nethome
print $sock "event,UPM_Message,Direction,In,UPM.DeviceCode,2,UPM.HouseCode,1,UPM.Primary,$ret,UPM.Secondary,122,UPM.SequenceNumber,0\n" or die "Sen$
} else {
}
Code: Select all
# 1-Wire devices
w1-gpio
# 1-Wire thermometer devices
w1-therm
then when i get all single temps to nethome i make one sh file where i call my scripts like
Code: Select all
#!/bin/bash
/opt/nethome/onewiretemp/makkaritempu.pl
sleep 2
/opt/nethome/onewiretemp/olkkaritempu.pl
sleep 2
/opt/nethome/onewiretemp/ulkotempu.pl
sleep 2
/opt/nethome/onewiretemp/pi.pl