From 72d2ded0ea9c38f3ae9d498134c89ee749aa71e4 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 30 Jan 2019 17:32:31 +0100 Subject: [PATCH 1/1] Implement fetching values from IFM IoTcore Sample configuration is in ifmdl-temperature.conf, AL13xx with attached TD2501 on port 1. --- ifmdl-temperature.conf | 25 +++++++++++++++++++++++++ upsgraph.pl | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 ifmdl-temperature.conf diff --git a/ifmdl-temperature.conf b/ifmdl-temperature.conf new file mode 100644 index 0000000..3f9dd94 --- /dev/null +++ b/ifmdl-temperature.conf @@ -0,0 +1,25 @@ +package UPSGRAPH; + +$outdir="/var/www/html/temperature/"; +$step=60; + +$hosts = [ + { + 'address' => "10.133.0.9", + 'name' => "al13-og", + 'rrdfile' => "/var/spool/upsgraph/temp.al13-og.rrd", + + 'fields' => [ 'TD2501' ], + + 'vars' => { + 'TD2501' => { + 'name' => 'TD2501', + 'url' => 'http://10.133.0.9/iolinkmaster/port[1]/iolinkdevice/pdin/getdata', + 'proto' => 'iotcore', + 'factor' => 1/10, + }, + } + }, +]; + +1; diff --git a/upsgraph.pl b/upsgraph.pl index adf33c9..55c6a62 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -15,6 +15,8 @@ use IO::Select; use RRDs; use File::Copy; use Data::Dumper; +use LWP::UserAgent; +use JSON; $UPSGRAPH::outdir = ""; $UPSGRAPH::daysCovered = 370; @@ -186,6 +188,23 @@ sub fetch_tcp_multi(@) { %values; } +sub fetch_iotcore(@) { + my $url = shift; + + my $ua = LWP::UserAgent->new; + $ua->timeout(1); + + my $resp = $ua->get($url); + return undef if (!$resp->is_success); + + my $pdin = decode_json($resp->decoded_content); + return undef if (!defined($pdin)); + + my $value = hex($pdin->{'data'}->{'value'}); + + $value; +} + sub dayGraphFunc { my $dataSrc = shift; my $mode = shift; @@ -477,6 +496,8 @@ while(1) { @multi_values{keys %values} = values %values; $result = $multi_values{$vars->{$var}->{'multi_id'}}; } + } elsif ($vars->{$var}->{'proto'} eq 'iotcore') { + $result = fetch_iotcore($vars->{$var}->{'url'}); } next unless (defined $result); -- 2.39.5