]> git.zerfleddert.de Git - upsgraph/commitdiff
Implement fetching values from IFM IoTcore
authorMichael Gernoth <michael@gernoth.net>
Wed, 30 Jan 2019 16:32:31 +0000 (17:32 +0100)
committerMichael Gernoth <michael@gernoth.net>
Wed, 30 Jan 2019 16:32:31 +0000 (17:32 +0100)
Sample configuration is in ifmdl-temperature.conf, AL13xx with
attached TD2501 on port 1.

ifmdl-temperature.conf [new file with mode: 0644]
upsgraph.pl

diff --git a/ifmdl-temperature.conf b/ifmdl-temperature.conf
new file mode 100644 (file)
index 0000000..3f9dd94
--- /dev/null
@@ -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;
index adf33c968e96bfd7e71c5f612cae759f9e40a3d8..55c6a62a85998e88fcd82e1239113e2d57e645c2 100755 (executable)
@@ -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);
Impressum, Datenschutz