]> git.zerfleddert.de Git - upsgraph/blobdiff - upsgraph.pl
iotcore: use IoTcore POST-request instead of GET
[upsgraph] / upsgraph.pl
index 55c6a62a85998e88fcd82e1239113e2d57e645c2..f9d0fe3ea558a315bdc100ea5809b94b034eb767 100755 (executable)
@@ -189,12 +189,24 @@ sub fetch_tcp_multi(@) {
 }
 
 sub fetch_iotcore(@) {
-       my $url = shift;
+       my $host = shift;
+       my $adr = shift;
+       my $mask = shift;
 
        my $ua = LWP::UserAgent->new;
        $ua->timeout(1);
 
-       my $resp = $ua->get($url);
+       my $iotcore_req = {
+               cid => 1,
+               code => 10,
+               adr => $adr,
+       };
+
+       my $req = HTTP::Request->new(POST => "http://${host}");
+       $req->content_type('application/json');
+       $req->content(encode_json($iotcore_req));
+
+       my $resp = $ua->request($req);
        return undef if (!$resp->is_success);
 
        my $pdin = decode_json($resp->decoded_content);
@@ -202,6 +214,10 @@ sub fetch_iotcore(@) {
 
        my $value = hex($pdin->{'data'}->{'value'});
 
+       if (defined($mask)) {
+               $value = $value & $mask;
+       }
+
        $value;
 }
 
@@ -497,7 +513,7 @@ while(1) {
                                        $result = $multi_values{$vars->{$var}->{'multi_id'}};
                                }
                        } elsif ($vars->{$var}->{'proto'} eq 'iotcore') {
-                               $result = fetch_iotcore($vars->{$var}->{'url'});
+                               $result = fetch_iotcore($host->{'address'}, $vars->{$var}->{'adr'}, $vars->{$var}->{'mask'});
                        }
 
                        next unless (defined $result);
Impressum, Datenschutz