Code:
/home/user/killsmlHZ.sh >/dev/null 2>&1 /home/user/smlHZ.pl >/dev/null 2>&1
/home/user/killsmlHZ.sh >/dev/null 2>&1 /home/user/smlHZ.pl >/dev/null 2>&1
# DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.LmLaF4/crontab installed on Tue Feb 4 20:00:50 2014) # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $) # m h dom mon dow command 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /home/user/killsmlHZ.sh /dev/null 2>&1 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /home/user/killsmlWP.sh /dev/null 2>&1
#!/bin/bash
# sml_smlHZ.pl starten
if [ "$(pidof smlHZ.pl)" ]
then
echo "smlHZ.pl laeuft noch"
pkill -9 smlHZ.pl
echo "smlHZ.pl gekillt"
fi
/home/user/smlHZ.pl
#!/usr/bin/perl
use warnings;
use strict;
use Device::SerialPort;
use feature "switch";
use EIBConnection;
use RRDs;
use Fcntl qw(:DEFAULT :flock);
#0701000F0700FF = 7.0 FIXME !!! [0F]0700
#070100010801FF = 1.8.1
#070100010800FF = 1.8.1
# Lock setzen damit Skript nur einmal startet
open *{0}
or die "What!? $0:$!";
flock *{0}, LOCK_EX|LOCK_NB
or die "$0 is already running somewhere!\n";
my $eib_url = "local:/tmp/eib"; #for local eibd "local:/tmp/eib" for eibd in LAN: "ip:192.168.2.220:6720"
my $device = "/dev/usbserial-A601NKCL";
my $repeat = 20; # Wiederholung alle x Sekunden
my $rrdpath = "/var/www/rrd";
my $debug = 1;
my @obis;
push @obis,{obis=>"1.8.0", fact=>10000, ga =>"14/7/51", dpt => 14, rrd_name => "HZ_Zaehler_Verbrauch", rrd => "c" }; #rrd: c=counter ; g=gauge
push @obis,{obis=>"15.7.0", fact=>10, ga =>"14/7/50", dpt => 9 , rrd_name => "HZ_Zaehler_Leistung_Ges", rrd => "g" };
my @countermodes = (5,15,60,1440); #Aufloesungen fuer COUNTER RRDs in Minuten (1440 = Tagesverbrauch)
my $port = Device::SerialPort->new($device) || die $!;
$port->databits(8) || die "failed setting databits";
$port->baudrate(9600) || die "failed setting baudrate";
$port->parity("none") || die "failed setting parity";
$port->stopbits(1);
$port->handshake("none");
$port->dtr_active(0);
$port->purge_all();
$port->read_char_time(0); # don't wait for each character
$port->read_const_time(4000); # 1 second per unfulfilled "read" call
$port->write_settings || die "cannot write settings";
my ($x,$data) = 0 ;
my $sml = 0;
my $start = 0;
my $value = 0;
my $dec_value = 0;
my $count = 0;
my $saw = 0;
if ($debug == 1) {print "Step 1 - Daten holen \n";}
while ($start < 2) # wait for second 1B1B1B1B01010101
{
($count,$saw)=$port->read(512); # will read 512 chars
if ($count == 512) # wurden 512 chars gelesen ?
{
$x = uc(unpack('H*',$saw)); # nach hex wandeln
$data .= $x;
if ($data =~ /1B1B1B1B01010101/) {$start ++};
} # if
} # while
if ($debug==1) {print "Step 2 - Reg Exp 1 Datensatz zusammensetzen \n";}
$data =~ m/1B1B1B1B01010101(.*?)B1B1B1/;
$sml = $1;
print "Zaehler Haushalt: \n";
if ($debug==1) {print "Step 3 - Datensatz auswerten \n";}
foreach my $obiscnt (@obis)
{
# Umwandeln OBIS in HEx
my $hc ="";
foreach my $c (split(/\./,$obiscnt->{obis})) {
$hc .= sprintf("%02X", $c);
}
my $obissearch = $hc;
# FF fuer Suche an Hex-Wert anhaegne
$obissearch .="FF";
if ($debug==1) { print $obissearch." Obis\n";}
$sml =~ m/$obissearch(.*?)0177/;
#$sml =~ m/$obiscnt->{obis}(.*?)0177/;
my $sml_val = $1;
if ($debug==1) { print $1." contains hex \n";}
#extract value
$sml_val =~ s/^.*52FF//;
$sml_val = substr($sml_val,2);
if ($debug == 1) { print $sml_val." hex \n";}
$value = $sml_val;
$dec_value = sprintf("%d", hex($value));
$dec_value /= $obiscnt->{fact};
print $dec_value."<<<<---- Wert\n";
# RRD-Graphen erstellen - bei Bedarf wieder aktiv setzen
if ($obiscnt->{rrd} eq "c")
{
&rrd_counter ($obiscnt->{rrd_name},$dec_value)
}
if ($obiscnt->{rrd} eq "g")
{
&rrd_gauge ($obiscnt->{rrd_name},$dec_value)
}
&knx_write ($obiscnt->{ga},$dec_value,$obiscnt->{dpt});
if ($debug == 1) {print "GA:".$obiscnt->{ga}." Wert:".$dec_value." DPT:".$obiscnt->{dpt}."\n";}
} # foreach
$port->lookclear;
$port->purge_all;
$port->purge_rx;
$port->close() || warn "Serial port did not close proper!\n";
undef $port;
### SUBS ###
sub rrd_counter
{
if ($debug==1){print ("COUNTER","\n")};
foreach (@countermodes)
{
my $obisname = $_[0];
if ($debug==1){print $obisname." obisname \n";}
my $value = $_[1];
if ($debug==1){print $value." value \n";}
my $rrdname = $obisname."_".$_."\.rrd";
if ($debug==1){print ($rrdname,"\n")};
my $rrdfile = $rrdpath."\/".$rrdname;
unless (-e $rrdfile)
{
RRDs::create ($rrdfile,"DS:value:COUNTER:".(($_*60)+600).":0:10000000000","RRA:AVERAGE:0.5:1:365","RRA:AVERAGE:0.5:7:300","-s ".($_*60));
}
my $countervalue = int($value*$_*60);
RRDs::update("$rrdfile", "N:$countervalue");
}
}
sub rrd_gauge
{
if ($debug==1){print ("GAUGE","\n")};
my $obisname = $_[0];
if ($debug==1){print $obisname." obisname \n";}
my $value = $_[1];
if ($debug==1){print $value." value \n";}
my $rrdname = $obisname."\.rrd";
if ($debug==1){print ($rrdname,"\n")};
my $rrdfile = $rrdpath."\/".$rrdname;
unless (-e $rrdfile)
{
RRDs::create ($rrdfile,"DS:value:GAUGE:900:0:10000000000","RRA:AVERAGE:0.5:1:2160","RRA:AVERAGE:0.5:5:2016","RRA:AVERAGE:0.5:15:2880","RRA:AVERAGE:0.5:60:8760");
}
RRDs::update("$rrdfile", "N:$value");
}
sub knx_write {
my ($dst,$value,$dpt,$response,$dbgmsg) = @_;
my $bytes;
my $apci = ($response) ? 0x40 : 0x80; # 0x40=response, 0x80=write
# DPT 1 (1 bit) = EIS 1/7 (move=DPT 1.8, step=DPT 1.7)
# DPT 2 (1 bit controlled) = EIS 8
# DPT 3 (3 bit controlled) = EIS 2
# DPT 4 (Character) = EIS 13
# DPT 5 (8 bit unsigned value) = EIS 6 (DPT 5.1) oder EIS 14.001 (DPT 5.10)
# DPT 6 (8 bit signed value) = EIS 14.000
# DPT 7 (2 byte unsigned value) = EIS 10.000
# DPT 8 (2 byte signed value) = EIS 10.001
# DPT 9 (2 byte float value) = EIS 5
# DPT 10 (Time) = EIS 3
# DPT 11 (Date) = EIS 4
# DPT 12 (4 byte unsigned value) = EIS 11.000
# DPT 13 (4 byte signed value) = EIS 11.001
# DPT 14 (4 byte float value) = EIS 9
# DPT 15 (Entrance access) = EIS 12
# DPT 16 (Character string) = EIS 15
# $dpt = $eibgaconf{$dst}{'DPTSubId'} unless $dpt; # read dpt from eibgaconf if existing
given ($dpt) {
when (/^12/) { $bytes = pack ("CCL>", 0, $apci, $value); } #EIS11.000/DPT12 (4 byte unsigned)
when (/^13/) { $bytes = pack ("CCl>", 0, $apci, $value); }
when (/^14/) { $bytes = pack ("CCf>", 0, $apci, $value); }
when (/^16/) { $bytes = pack ("CCa14", 0, $apci, $value); }
when (/^17/) { $bytes = pack ("CCC", 0, $apci, $value & 0x3F); }
when (/^20/) { $bytes = pack ("CCC", 0, $apci, $value); }
when (/^\d\d/) { return; } # other DPT XX 15 are unhandled
when (/^[1,2,3]/) { $bytes = pack ("CC", 0, $apci | ($value & 0x3f)); } #send 6bit small
when (/^4/) { $bytes = pack ("CCc", 0, $apci, ord($value)); }
when ([5,5.001]) { $bytes = pack ("CCC", 0, $apci, encode_dpt5($value)); } #EIS 6/DPT5.001 1byte
when ([5.004,5.005,5.010]) { $bytes = pack ("CCC", 0, $apci, $value); }
when (/^5/) { $bytes = pack ("CCC", 0, $apci, $value); }
when (/^6/) { $bytes = pack ("CCc", 0, $apci, $value); }
when (/^7/) { $bytes = pack ("CCS>", 0, $apci, $value); }
when (/^8/) { $bytes = pack ("CCs>", 0, $apci, $value); }
when (/^9/) { $bytes = pack ("CCCC", 0, $apci, encode_dpt9($value)); } #EIS5/DPT9 2byte float
default { LOGGER('WARN',"None or unsupported DPT: $dpt sent to $dst value $value"); return; }
}
my $leibcon = EIBConnection->EIBSocketURL($eib_url) or return("Error opening con: $!");
if ($leibcon->EIBOpenT_Group(str2addr($dst),1) == -1) { return("Error opening group: $!"); }
my $res=$leibcon->EIBSendAPDU($bytes);
$leibcon->EIBClose();
return $res;
# str2addr: Convert an EIB address string in the form "1/2/3" or "1.2.3" to an integer
sub str2addr {
my $str = $_[0];
if ($str =~ /(\d+)\/(\d+)\/(\d+)/) { # logical address
return ($1 << 11) | ($2 << 8) | $3;
} elsif ($str =~ /(\d+)\.(\d+)\.(\d+)/) { # physical address
return ($1 << 12) | ($2 << 8) | $3;
} else {
#bad
return;
}
}
}
sub encode_dpt9
{
# 2byte signed float
my $state = shift;
my $data;
my $sign = ($state <0 ? 0x8000 : 0);
my $exp = 0;
my $mant = 0;
$mant = int($state * 100.0);
while (abs($mant) > 2047)
{
$mant /= 2;
$exp++;
}
$data = $sign | ($exp << 11) | ($mant & 0x07ff);
return $data >> 8, $data & 0xff;
}
du -sh /*
2014-01-30 13:42:10 Received from root@wiregate1-mm.elabnet.com U=root P=local S=1344 2014-01-30 13:42:10 SMTP error from remote mail server after RCPT TO:<root@wiregate1-mm.elabnet.com>: host mail1.elabnet.de [81.16.179.52]: 450 too many connections from your IP (rate controlled) 2014-01-30 13:42:10 root@wiregate1-mm.elabnet.com R=smarthost T=remote_smtp_smarthost defer (-44): SMTP error from remote mail server after RCPT TO:<root@wiregate1-mm.elabnet.com>: host mail1.elabnet.de [81.16.179.52]: 450 too many connections from your IP (rate controlled)
# Change to no to disable tunnelled clear text passwords PasswordAuthentication yes
Wir verarbeiten personenbezogene Daten über die Nutzer unserer Website mithilfe von Cookies und anderen Technologien, um unsere Dienste bereitzustellen. Weitere Informationen findest Du in unserer Datenschutzerklärung.
Indem Du unten auf "ICH stimme zu" klickst, stimmst Du unserer Datenschutzerklärung und unseren persönlichen Datenverarbeitungs- und Cookie-Praktiken zu, wie darin beschrieben. Du erkennst außerdem an, dass dieses Forum möglicherweise außerhalb Deines Landes gehostet wird und bist damit einverstanden, dass Deine Daten in dem Land, in dem dieses Forum gehostet wird, gesammelt, gespeichert und verarbeitet werden.


Einen Kommentar schreiben: