Files
scripts/Perl Luftdaten/13728_13729/read_multiple.pl
2024-10-14 00:08:40 +02:00

62 lines
2.0 KiB
Perl

#!/usr/bin/perl
use LWP::Simple; # From CPAN
use JSON qw( decode_json ); # From CPAN
use Data::Dumper; # Perl core module
use strict; # Good practice
use warnings; # Good practice
my $rrdfile="/scripts/luftdaten/13728_13729/db_13728_13729.rrd";
my $sensor;
my $trendsurl;
my $json;
my $decoded_json;
my $k;
my $PM10;
my $PM25;
my $TEMP;
my $HUMI;
my $LON;
my $LAT;
my $i;
for ($i=1; $i<=3; $i++) {
$sensor=13728;
$trendsurl = "https://api.luftdaten.info/v1/sensor/$sensor/";
$json = get( $trendsurl );
die "Could not get $trendsurl!" unless defined $json;
$decoded_json = decode_json( $json );
$k=${$decoded_json}[0];
print "$k->{'timestamp'}\n";
printf "%-20s %6.2f\n", $k->{'sensordatavalues'}[0]->{'value_type'}, $k->{'sensordatavalues'}[0]->{'value'};
printf "%-20s %6.2f\n", $k->{'sensordatavalues'}[1]->{'value_type'}, $k->{'sensordatavalues'}[1]->{'value'};
$PM10 = $k->{'sensordatavalues'}[0]->{'value'};
$PM25 = $k->{'sensordatavalues'}[1]->{'value'};
$LAT = $k->{'location'}->{'latitude'};
$LON = $k->{'location'}->{'longitude'};
open FILE, ">/scripts/luftdaten/13728_13729/here";
printf FILE "<a href='https://wego.here.com/directions/mix/$LAT,$LON/?map=$LAT,$LON,16,normal' target='_map'>wego.here</a>";
close FILE;
$sensor=13729;
$trendsurl = "https://api.luftdaten.info/v1/sensor/$sensor/";
$json = get( $trendsurl );
die "Could not get $trendsurl!" unless defined $json;
$decoded_json = decode_json( $json );
$k=${$decoded_json}[0];
printf "%-20s %6.2f\n", $k->{'sensordatavalues'}[0]->{'value_type'}, $k->{'sensordatavalues'}[0]->{'value'};
printf "%-20s %6.2f\n\n", $k->{'sensordatavalues'}[1]->{'value_type'}, $k->{'sensordatavalues'}[1]->{'value'};
$TEMP = $k->{'sensordatavalues'}[0]->{'value'};
$HUMI = $k->{'sensordatavalues'}[1]->{'value'};
`/usr/bin/rrdtool update $rrdfile N:$PM25:$PM10:$TEMP:$HUMI:U`;
sleep (30);
}