From: Michael Gernoth Date: Thu, 31 Jan 2019 12:59:38 +0000 (+0100) Subject: iotcore: use IoTcore POST-request instead of GET X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/commitdiff_plain/c952fc0ba78932df14eef9e502cd5b7bb6375666?hp=72d2ded0ea9c38f3ae9d498134c89ee749aa71e4 iotcore: use IoTcore POST-request instead of GET --- diff --git a/ifmdl-temperature.conf b/ifmdl-temperature.conf index 3f9dd94..3c0ef63 100644 --- a/ifmdl-temperature.conf +++ b/ifmdl-temperature.conf @@ -14,9 +14,10 @@ $hosts = [ '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, + 'mask' => 0xffff, }, } }, diff --git a/upsgraph.pl b/upsgraph.pl index 55c6a62..f9d0fe3 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -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);