]> git.zerfleddert.de Git - upsgraph/commitdiff
iotcore: use IoTcore POST-request instead of GET
authorMichael Gernoth <michael@gernoth.net>
Thu, 31 Jan 2019 12:59:38 +0000 (13:59 +0100)
committerMichael Gernoth <michael@gernoth.net>
Thu, 31 Jan 2019 15:00:46 +0000 (16:00 +0100)
ifmdl-temperature.conf
upsgraph.pl

index 3f9dd94a6145cf9b3fa60db97011c13803b81f0c..3c0ef633298ce78244d735d9423af4d0ba6dd756 100644 (file)
@@ -14,9 +14,10 @@ $hosts = [
                'vars' => {
                        'TD2501' => {
                                'name' => 'TD2501',
                'vars' => {
                        'TD2501' => {
                                'name' => 'TD2501',
-                               'url' => 'http://10.133.0.9/iolinkmaster/port[1]/iolinkdevice/pdin/getdata',
+                               'adr' => 'iolinkmaster/port[1]/iolinkdevice/pdin/getdata',
                                'proto' => 'iotcore',
                                'factor' => 1/10,
                                'proto' => 'iotcore',
                                'factor' => 1/10,
+                               'mask' => 0xffff,
                        },
                }
        },
                        },
                }
        },
index 55c6a62a85998e88fcd82e1239113e2d57e645c2..f9d0fe3ea558a315bdc100ea5809b94b034eb767 100755 (executable)
@@ -189,12 +189,24 @@ sub fetch_tcp_multi(@) {
 }
 
 sub fetch_iotcore(@) {
 }
 
 sub fetch_iotcore(@) {
-       my $url = shift;
+       my $host = shift;
+       my $adr = shift;
+       my $mask = shift;
 
        my $ua = LWP::UserAgent->new;
        $ua->timeout(1);
 
 
        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);
        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'});
 
 
        my $value = hex($pdin->{'data'}->{'value'});
 
+       if (defined($mask)) {
+               $value = $value & $mask;
+       }
+
        $value;
 }
 
        $value;
 }
 
@@ -497,7 +513,7 @@ while(1) {
                                        $result = $multi_values{$vars->{$var}->{'multi_id'}};
                                }
                        } elsif ($vars->{$var}->{'proto'} eq 'iotcore') {
                                        $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);
                        }
 
                        next unless (defined $result);
Impressum, Datenschutz