Hallo
Ja, Habe ich im Router so eingestellt.
Gruß NetFritz
@makki
die :85 ist aber absichtlich so eingestellt oder?
die :85 ist aber absichtlich so eingestellt oder?
Gruß NetFritz
!/usr/bin/perl -w use strict; use warnings; use IO::Socket::INET; use JSON; my $debug=0; my $webboxIP = "192.168.2.251:85"; my %rpc = (); &configure_requests; &cls; my $data = &get_data_from_sunny_webbox($webboxIP,$rpc{"get_devices"}); print "RPC_GET_DEVICES : \n"; print "----------------- \n"; print $data."\n\n\n"; my $js_hash_ref = decode_json $data ; # decode JSON Data , result is a Hash-reference my $tab = -1; # preset number of tabs to format printout &print_hash($js_hash_ref); &pause(1); $data = &get_data_from_sunny_webbox($webboxIP,$rpc{"get_plant_overview"}); print "RPC_GET_PLANT_OVERVIEW : \n"; print "------------------------ \n"; print $data."\n\n\n"; $js_hash_ref = decode_json $data ; &print_hash($js_hash_ref); sub print_hash { my $hash_ref = shift; # reference to a hash my %h = %$hash_ref; # dereference $tab++; my $t = "\t"x$tab; foreach my $k (sort keys %h) { print "$t$k: "; if (ref($h{$k}) eq "HASH") { # if element is a hash then print it ... print "\n"; &print_hash($h{$k}); next; } if (ref($h{$k}) eq "ARRAY") { # if element is an array then print array print "\n"; &print_array($h{$k}); next; } print "$h{$k}\n"; if ($debug) {&pause} } $tab--; } sub print_array { my $arr_ref = shift; # reference to an array my @arr = @$arr_ref; # dereference $tab++; my $t = "\t"x$tab; foreach (sort @arr) { print $t."\t"; if (ref($_) eq "HASH") { # if element is a hash then print it ... print "\n"; &print_hash($_); next; } if (ref($_) eq "ARRAY") { # if element is an array then print array print "\n"; &print_array($_); next; } print $_."\n"; if ($debug) {&pause} } $tab--; } sub get_data_from_sunny_webbox { my $ip = shift; my $request = shift; my $response; my $received; my $RecvSocket = new IO::Socket::INET->new(LocalPort=>34268,Proto=>'udp'); my $SendSocket = new IO::Socket::INET->new(PeerPort=>34268,Proto=>'udp',PeerAddr=>"$ip"); my $cs = $SendSocket->send($request); if ( ! defined $cs) { return "Send-Error";} $response = $RecvSocket->recv($received,1024); $received =~ s/\0//go; undef $RecvSocket; undef $SendSocket; return $received; } sub configure_requests { my $r = "get_devices"; my $obj = '{ "version":"1.0", "proc":"GetDevices", "id":"1", "format":"JSON" }'; $obj = &add_null_chars($obj); $rpc{$r} = $obj; $r = "get_plant_overview"; $obj = '{"version":"1.0", "proc":"GetPlantOverview", "id":"1", "format":"JSON" }'; $obj = &add_null_chars($obj); $rpc{$r} = $obj; # add more requests here ... } sub add_null_chars { my $s = shift; $s =~ s/\s//go; $s =~ s/(.)/$1\0/go; return $s; } sub remove_null_chars { my $s = shift; $s =~ s/\0//go; return $s; } sub cls { my $os = $^O; # get Operating System if (index(lc($os),"win") > -1) { system("cls"); # Windows then clear screen (batch command) } else { system("clear"); # Linux/Unix/Solars clear screen (bash command) } } sub pause { my $pr = shift; if ($pr) {print "\n\n\npress <return> to continue ...\n"} my $p = <stdin> }
-------------------------------------------------------- [URL]http://IP_der-Webbox/rpc?RPC=[/URL]{"version":"1.0","proc":"GetDevices","id":"1","format":"JSON"}} ------------------------------------------------------- [URL]http://IP_der-Webbox/rpc?RPC=[/URL]{"version":"1.0","proc":"GetProcessDataChannels","id":"1","format":"JSON","params":{"device":"0083:7e5cb61d"}} ------------------------------------------------------ [URL]http://IP_der-Webbox/rpc?RPC=[/URL]{ "version": "1.0", "proc": "GetProcessData", "id": "1", "format": "JSON", "params": { "devices": [ { "key": "004e:7d30b9bc", "channels": null } ] } } ------------------------------------------------------------- [URL]http://IP_der-Webbox/rpc?RPC=[/URL]{ "version": "1.0", "proc": "GetPlantOverview", "id": "1", "format": "JSON" }
# return; # holt über HTTP-RPC die Daten von der SMA-Webbox # es wird GetProcessData und GetPlantOverview abgefragt # by NetFritz 5.2012 # use HTML::Entities; use LWP::UserAgent; use JSON::XS; use DBI; my $stkd; # in $iso steht Datum-Zeit = 'Y-m-d H:M:S' my @dta = localtime(time); my $iso=($dta[5]+1900)."-"; $iso.=sprintf('%02d-',$dta[4]+1); $iso.=sprintf('%02d ',$dta[3]); $iso.=sprintf('%02d:',$dta[2]); $iso.=sprintf('%02d:',$dta[1]); $iso.=sprintf('%02d',$dta[0]); # ======= Anfang Konfig ======= my $url = "http://192.168.2.7:85"; # IP der Webbox my $key = "xxxx:xxxxxxxx"; # Key des WR muss vorher ermittelt werden my $leistung_ga = "5/0/1"; my $leistung_pro_kw_ga = "5/0/2"; my $tagesertrag_ga = "5/0/3"; my $gesammtertrag_ga = "5/0/4"; my $zustand_ga = "5/0/5"; my $meldung_ga = "5/0/6"; my $DC_Strom_Eingang_ga = "5/0/7"; my $DC_Spannung_Eingang_ga = "5/0/8"; my $Netzstrom_ga = "5/0/9"; my $Leistung_Haushalt_ga = "5/0/15"; # ======= Ende Konfig ========= # Eigenen Aufruf-Zyklus auf 60 Sekunden setzen # der Aufrufzyklus ist unabhängig von der Taktzeit und muss kürzer sein! $plugin_info{$plugname.'_cycle'} = 60; my $res; my $ref; # ===== Abfragestring GetProcessData ===== my $callobj = '/rpc?RPC={ "version": "1.0", "proc": "GetProcessData", "id": "1", "format": "JSON", "params": { "devices": [ { "key": "'. $key .'", "channels": null } ] } }'; # # ==== Abfragestring GetPlantOverview ===== my $callobj1 = '/rpc?RPC={ "version": "1.0", "proc": "GetPlantOverview", "id": "1", "format": "JSON" }'; # # ====== Abfrage GetProcessData ====== $res = $url.$callobj; $ref = rpcs($res); # my $Ipv = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[0]->{'value'}; # DC Strom Eingang my $Upv = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[1]->{'value'}; # DC Spannung Eingang my $Fac = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[5]->{'value'}; # NetzFrequenz my $Iac = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[6]->{'value'}; # Netzstrom my $Pac = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[7]->{'value'}; # Leistung my $Riso = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[8]->{'value'}; # Isolationswiderstand my $hon = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[10]->{'value'}; # Einspeisezeit my $hTotal = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[11]->{'value'}; # Betriebszeit my $ETotal = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[12]->{'value'}; # Gesammtertrag my $NetzEin = $ref->{'result'}->{'devices'}->[0]->{'channels'}->[13]->{'value'}; # Netz-Ein # return $Ipv . "=" . $Upv . "=" . $Fac . "=" . $Iac . "=" . $Pac . "=" . $Riso . "=" . $hon . "=" . $hTotal . "=" . $ETotal . "=" . $NetzEin; # # ===== Abfrage GetPlantOverview ===== $res = $url.$callobj1; $ref = rpcs($res); my $GriPwr = $ref->{'result'}->{'overview'}->[0]->{'value'}; # Leistung my $GriEgyTdy = $ref->{'result'}->{'overview'}->[1]->{'value'}; # Tagesertrag my $GriEgyTot = $ref->{'result'}->{'overview'}->[2]->{'value'}; # Gesamtertrag my $OpStt = $ref->{'result'}->{'overview'}->[3]->{'value'}; # Zustand my $Msg = $ref->{'result'}->{'overview'}->[4]->{'value'}; # Meldung # if ($Msg == ""){ $Msg = "iO"; knx_write("5/0/24",0,1); # PV Stoerung false }else{ knx_write("5/0/24",1,1); # PV Stoerung true } $plugin_info{'email.pl.Stoerung'} = $Msg." ".$OpStt; # knx_write($gesammtertrag_ga,$GriEgyTot,9); # return $GriPwr . "=" . $GriEgyTdy ."=". $GriEgyTot ."=". $OpStt ."=". $Msg ; # return $GriPwr; # system("/usr/bin/nohup ./var/www/myhouse/cron/sml_zaehler.pl"); # Zaehler-Script aufrufen # auf den KNX-Bus schreiben # my $Tag_CO2_vermeidung = $GriEgyTdy*700; # 700g/kWh # Werte auf den BUS schreiben knx_write($leistung_ga,$GriPwr,9); knx_write($leistung_pro_kw_ga,$GriPwr/4.05,9); knx_write($tagesertrag_ga,$GriEgyTdy,9); # knx_write($gesammtertrag_ga,$GriEgyTot,9); knx_write($zustand_ga,$OpStt,16); knx_write($DC_Strom_Eingang_ga,$Ipv,9); knx_write($DC_Spannung_Eingang_ga,$Upv,9); knx_write($Netzstrom_ga,$Iac,9); knx_write($meldung_ga,$Msg,16); my $leistung_pv = knx_read("5/0/1",0,9); my $Leistung_Zaehler = knx_read("5/0/12",0,9); my $leistg_haush = $leistung_pv-$Leistung_Zaehler; # Leistung Haushalt knx_write($Leistung_Haushalt_ga,$leistg_haush,9); my $eigenverbrausquote = eval {sprintf ("%.1f", $leistg_haush/($leistung_pv/100))}; if($eigenverbrausquote > 1000) { $eigenverbrausquote = 1000; } # # my $eigenverbrauch = $leistg_haush/($leistung_pv/100); my $eigenverbrauch = eval { sprintf ("%.1f", $leistg_haush/($leistung_pv/100))}; if ($eigenverbrauch <= 0) { $eigenverbrauch = 0; } elsif($eigenverbrauch > 100) { $eigenverbrauch = 100; } knx_write("5/0/16",$eigenverbrauch,9); update_rrd("Eigenverbrauch","",$eigenverbrauch*10); # # 70%Regelung my $siebzig = 2835; # 70% von 4050Wp if ($Leistung_Zaehler > $siebzig){ update_rrd("pv_70","",$Leistung_Zaehler - $siebzig); }else{ update_rrd("pv_70","","0"); } # Wert in RRD schreiben update_rrd("pv_leistung","",$GriPwr); update_rrd("pv_leistung_kW","",$Pac/1000); update_rrd("pv_std","",$Pac/1000); # 1 Wert pro Std. update_rrd("pv_10min","",$Pac/1000); # 1 Wert pro 10min. update_rrd("pv_tagesertrag","",$GriEgyTdy); update_rrd("pv_DC_Strom_Eingang","",$Ipv*100); #update_rrd("pv_DC_Spannung_Eingang","",$Upv); update_rrd("Leistung_Haushalt","",$leistg_haush); update_rrd("pv_Eigenverbrausquote","",$eigenverbrausquote); # schreibt in DB # DB oeffnen my $dbargs = {AutoCommit => 0, PrintError => 1}; my $dbh = DBI->connect("dbi:SQLite2:dbname=/var/www/myhouse/sq_lite/myhouse.sqlite", "", "", $dbargs); #if ($dbh->err()) { die "$DBI::errstr\n"; } # $dbh->do("UPDATE myhouse SET date_zeit='".$iso."', wert='".$GriEgyTot."' WHERE adr='5/0/4'"); # $dbh->commit; # Änderungen auf die Datenbank einfügen # $dbh->disconnect(); # DB schliessen # # ===== Sub holt die Werte von der Webbox ===== sub rpcs{ my $res = shift; my $brs = LWP::UserAgent->new; $brs->timeout(5); my $req = HTTP::Request->new(GET => $res); my $resp = $brs->request($req); # if($resp->is_success()) { # print "Erfolg !"; }else { return "Keine Antwort !"; } # my $content = $resp->content; my %js_hash_ref = %{decode_json $content}; my $ref=\%js_hash_ref; # return($ref); } #return($stkd . $OpStt. "=" . $Msg); return();
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.
Kommentar