'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,
},
}
},
}
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);
my $value = hex($pdin->{'data'}->{'value'});
+ if (defined($mask)) {
+ $value = $value & $mask;
+ }
+
$value;
}
$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);