-
Notifications
You must be signed in to change notification settings - Fork 0
/
deye2vzlogger
executable file
·49 lines (45 loc) · 1.51 KB
/
deye2vzlogger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
# A simple pure perl reimplementation of
# https://wiki.volkszaehler.org/hardware/channels/solar_inverters/deye
# I need to query multiple inverters.
# You can push the values direct in the middleware DB or collect them by vzlogger (see config)
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;
if ($config{DB_direct} == 1) {
$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;
}
} else {
print "$inverter->[4] = $line\n";
}
last;
}
}
}
else {
push @err,$response->status_line;
}
}
foreach (@err) {
print "$_\n";
}
if ($config{DB_direct} == 0) {
sleep(10);
}
exit @err ? 1 : 0;