From c952fc0ba78932df14eef9e502cd5b7bb6375666 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 31 Jan 2019 13:59:38 +0100 Subject: [PATCH] iotcore: use IoTcore POST-request instead of GET --- ifmdl-temperature.conf | 3 ++- upsgraph.pl | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) 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); -- 2.39.5