Raspberry pi + nethome + onewire temp howto!
Posted: Fri Feb 06, 2015 10:08 am
Ok i write there some example script how i get nethome onewire temp sensors , i use perl script below this text to sent onewire temp to nethome udp packet i have configure that upm temp sensor same code where my script sent this , of course this example think you can read onewire temps in pi command line , there is good tuturials on net how get this to work.
i autoload modules via /etc/modules example nano /etc/modules and add this lines there
after that remember save file and after reboot if all go ok you get autoload onewire modules and that perl script work.
then when i get all single temps to nethome i make one sh file where i call my scripts like
Ofc someone think well not want use own script to one device and mod script like perl search $tempsensor in linux and read them and sent them nethome that work but if you add sensors there there is no quarantee that logic keep same , my first script was that and some times temps go wrong nethome items , so modded manual that onewire device name and now i know i get allways my bedroom temp to bedroom nethome item
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