init III
This commit is contained in:
51
Perl Luftdaten/read_sensor2db.pl
Normal file
51
Perl Luftdaten/read_sensor2db.pl
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/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 $DEBUG=1;
|
||||
|
||||
my $sensor;
|
||||
my $trendsurl;
|
||||
my $json;
|
||||
my $decoded_json;
|
||||
|
||||
my $PM10;
|
||||
my $PM25;
|
||||
my $TEMP;
|
||||
my $HUMI;
|
||||
my $LON;
|
||||
my $LAT;
|
||||
my $HPA;
|
||||
|
||||
my @sensors = qw /761 762 13728 13729 26940 26941 31386 31387/;
|
||||
|
||||
foreach my $sensor (@sensors) {
|
||||
for (my $i=1; $i<=3; $i++) {
|
||||
$trendsurl = "https://api.luftdaten.info/v1/sensor/$sensor/";
|
||||
$json = get( $trendsurl );
|
||||
die "Could not get $trendsurl!" unless defined $json;
|
||||
$decoded_json = decode_json( $json );
|
||||
|
||||
my $k=${$decoded_json}[0];
|
||||
print "$k->{'timestamp'}\n";
|
||||
foreach (@{$k->{'sensordatavalues'}}) {
|
||||
my $type_alias=$_->{'value_type'};
|
||||
my $sensor_value=$_->{'value'};
|
||||
print "$sensor $type_alias $sensor_value\n" if ($DEBUG);
|
||||
}
|
||||
|
||||
#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'};
|
||||
|
||||
sleep (30);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user