-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
basti122303
committed
May 9, 2023
0 parents
commit 5edd3e4
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/perl | ||
# A simple pure perl reimplementation of | ||
# https://wiki.volkszaehler.org/hardware/channels/solar_inverters/deye | ||
# I need to query multiple inverters. | ||
|
||
use strict; | ||
use warnings; | ||
use LWP::UserAgent; | ||
|
||
our %config; | ||
do "/etc/vz/config" or die $@; | ||
|
||
my @err; | ||
my $ua = LWP::UserAgent->new; | ||
|
||
foreach my $inverter (@{$config{inverter}}){ | ||
my $response = $ua->get("http://$inverter->[0]/status.html"); | ||
$response->authorization_basic($inverter->[2], $inverter->[3]); | ||
if ($response->is_success) { | ||
my $content = $response->content; | ||
for (split /^/, $content) { | ||
chomp(); | ||
my $line = $_; | ||
if ($line =~ /(?<=webdata_now_p = ")\d+/) { | ||
$line =~ s/[^0-9]//g; | ||
$response = $ua->get("http://$config{DB_Host}/middleware/data/$inverter->[1].json?operation=add&value=$line"); | ||
if (!$response->is_success) { | ||
push @err,$response->status_line; | ||
} | ||
last; | ||
} | ||
} | ||
} | ||
else { | ||
push @err,$response->status_line; | ||
} | ||
} | ||
foreach (@err) { | ||
print "$_\n"; | ||
} | ||
exit @err ? 1 : 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%config=( | ||
DB_Host=>'vzhost.example.com', | ||
inverter=>[ | ||
['inverter.example.com','<YOUR UUID>','admin','yourpass'], | ||
['inverter2.example.com','<YOUR UUID2>','admin','yourpass'], | ||
], | ||
); |