This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
#!/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
#use RRD::Simple ();
my $sensor=$ARGV[0];
my $trendsurl = "https://api.luftdaten.info/v1/sensor/$sensor/";
#https://github.com/opendata-stuttgart/meta/wiki/APIs
#https://data.sensor.community/airrohr/v1/sensor/762/ temp hum
#https://data.sensor.community/airrohr/v1/sensor/761/ pm10 pm25
#50.128,8.728
#https://wego.here.com/directions/mix/50.128,8.728/?map=50.128,8.728,16,normal
# open is for files. unless you have a file called
# 'https://graph.facebook.com/?ids=http://www.filestube.com' in your
# local filesystem, this won't work.
#{
# local $/; #enable slurp
# open my $fh, "<", $trendsurl;
# $json = <$fh>;
#}
# Create an interface object
#my $rrd = RRD::Simple->new( file => "myfile.rrd" );
# Create a new RRD file with 3 data sources called
# bytesIn, bytesOut and faultsPerSec.
#$rrd->create(
# P1 => "GAUGE",
# P2 => "GAUGE",
# time => "STRING"
# );
# 'get' is exported by LWP::Simple; install LWP from CPAN unless you have it.
# You need it or something similar (HTTP::Tiny, maybe?) to get web pages.
my $json = get( $trendsurl );
die "Could not get $trendsurl!" unless defined $json;
# This next line isn't Perl. don't know what you're going for.
#my $decoded_json = @{decode_json{shares}};
# Decode the entire JSON
my $decoded_json = decode_json( $json );
# you'll get this (it'll print out); comment this when done.
#print Dumper $decoded_json;
foreach (@{$decoded_json}) {
#print $_->{'timestamp'} . "\n";
foreach (@{$_->{'sensordatavalues'}}) {
#print "$_->{'value_type'}: ";
#print $_->{'value'} . "\n";
}
}
my $k=${$decoded_json}[0];
#print $k->{'timestamp'} . "\n";
foreach (@{$k->{'sensordatavalues'}}) {
#print $_->{'value_type'} . ": ";
#print $_->{'value'} . "\n";
}
$k=${$decoded_json}[0];
print "$k->{'timestamp'}\n";
print "$k->{'sensordatavalues'}[0]->{'value_type'} ";
print "$k->{'sensordatavalues'}[0]->{'value'}\n";
print "$k->{'sensordatavalues'}[1]->{'value_type'} ";
print "$k->{'sensordatavalues'}[1]->{'value'}\n";
print "\n";