sub process_data { if ($debug) { say "Processing polled data...." } my $json_line = shift(@_); my $dt = DateTime->now(); $dt->set_time_zone( 'America/Chicago' ); my $sth; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile" ,"",""); $q = "insert into weather_data values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $sth = $dbh->prepare($q); if ( (exists($json->{'bbl'})) and (not exists($json->{'ra'}))) { $sth->execute(undef, $dt->datetime(), $dt->ymd(), $dt->hms(), $json->{'wd'}, $json->{'wv'}, $json->{'tF'}, $json->{'tC'}, $json->{'bp'}, $json->{'rh'}, $json->{'li'}, $json->{'ov'}, $json->{'lux'}, $json->{'bbl'}, $json->{'irl'}, 'null', 'null' ); } elsif ( (exists($json->{'ra'})) and (exists($json->{'bbl'}))) { $sth->execute(undef,$dt->datetime(), $dt->ymd(), $dt->hms(), $json->{'wd'}, $json->{'wv'}, $json->{'tF'}, $json->{'tC'}, $json->{'bp'}, $json->{'rh'}, $json->{'li'}, $json->{'ov'}, $json->{'lux'}, $json->{'bbl'}, $json->{'irl'}, $json->{'ra'}, $json->{'rr'} ); } elsif ( (exists($json->{'ra'})) and (not exists($json->{'bbl'}))) { $sth->execute(undef,$dt->datetime(), $dt->ymd(), $dt->hms(), $json->{'wd'}, $json->{'wv'}, $json->{'tF'}, $json->{'tC'}, $json->{'bp'}, $json->{'rh'}, $json->{'li'}, $json->{'ov'}, 'null', 'null', 'null', $json->{'ra'}, $json->{'rr'} ); } elsif ( (not exists($json->{'ra'})) and (not exists($json->{'bbl'}))) { $sth->execute(undef,$dt->datetime(), $dt->ymd(), $dt->hms(), $json->{'wd'}, $json->{'wv'}, $json->{'tF'}, $json->{'tC'}, $json->{'bp'}, $json->{'rh'}, $json->{'li'}, $json->{'ov'}, 'null', 'null', 'null', 'null', 'null' ); } $sth->finish; $dbh->disconnect; }