Skip to content

Commit

Permalink
Merge pull request #13 from hplato/ia7
Browse files Browse the repository at this point in the history
Ia7 merge
  • Loading branch information
Wayne Gatlin authored Sep 21, 2017
2 parents 324c3f0 + e5eea1f commit d9bd75b
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 31 deletions.
43 changes: 33 additions & 10 deletions code/common/internet_weather_noaa.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
#
#@ This code will retrieve and parse data from the XML feeds provided
#@ by the Natiional Weather service.
#@ by the Natiional Weather service. (MH5 Updated)
#@
#@ Check <a href="http://www.weather.gov/data/current_obs/">http://www.weather.gov/data/current_obs/</a>
#@ for the nearest station's ID. Add the ID to the "weather_noaa_station"
Expand All @@ -19,7 +19,7 @@
Revision History
Version 2 September 19, 2017
Version 0.1 December 8, 2006
Initial version
Expand All @@ -32,24 +32,39 @@

my $NWSdata;
my $station = $config_parms{weather_noaa_station};
my $internet_weather_noaa_file = $config_parms{data_dir} . '/web/weather_noaa.html';

$station = 'KARR' unless $station;

# create object
$xml = new XML::Simple;

$v_get_xml_weather = new Voice_Cmd('Get XML weather data');
$p_internet_weather_noaa_fetch = new Process_Item(qq{get_url -quiet "http://www.weather.gov/data/current_obs/$station.xml" "$internet_weather_noaa_file"});

# Create trigger
if ($Reload) {
&trigger_set( "time_cron '15 * * * *'", "run_voice_cmd('Get XML weather data')", 'NoExpire', 'get xml weather' ) unless &trigger_get('get xml weather');
$Weather_Common::weather_module_enabled = 1;

}

if ( said $v_get_xml_weather) {
if (&net_connect_check) {
$v_get_xml_weather->respond("app=weather Retrieving XML weather...");
#
start $p_internet_weather_noaa_fetch;
$v_get_xml_weather->respond("app=weather Retrieving XML weather...");
}

if ( done_now $p_internet_weather_noaa_fetch or $Reload ) {
&process_noaa;
}

sub process_noaa {
my $data = file_read $internet_weather_noaa_file;
return unless ($data);
# read XML file
$NWSdata = $xml->XMLin( get( "http://www.weather.gov/data/current_obs/" . $station . ".xml" ) );
$NWSdata = $xml->XMLin( $data );

print Dumper $NWSdata;

# hash used to temporarily store weather info before selective load into %Weather
my %w = ();
Expand All @@ -66,6 +81,18 @@
$w{DewOutdoor} = NA_to_zero( $NWSdata->{dewpoint_f} );
$w{Summary_Short} = $NWSdata->{weather};

($w{LastUpdated}) = $NWSdata->{observation_time} =~ /Last Updated on (.*)$/;

$w{IsRaining} = 0;
$w{IsRaining} = 1 if ($NWSdata->{weather} =~ m/rain/i);

$w{IsSnowing} = 0;
$w{IsSnowing} = 1 if ($NWSdata->{weather} =~ m/snow/i);

$w{Clouds} = $NWSdata->{weather};
$w{Clouds} = "" if ($NWSdata->{weather} =~ m/fair/i);


&populate_internet_weather( \%w );
&weather_updated;

Expand All @@ -78,10 +105,6 @@
&print_log( "weather_xml: finished retrieving weather for station " . $station );
$v_get_xml_weather->respond( 'app=weather connected=0 Weather data for ' . $NWSdata->{location} . ' retrieved.' );

}
else {
$v_get_xml_weather->respond("I must be connected to the Internet to get weather data.");
}
}

sub NA_to_zero {
Expand Down
3 changes: 2 additions & 1 deletion code/common/weather_metar.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# $Revision$
# $Date$
#
#@ Weather METAR parser
#@ Weather METAR parser (MH5 Updated)
#@
#@ $Revision$
#@
Expand Down Expand Up @@ -50,6 +50,7 @@
if ($Reload) {
&trigger_set( '$New_Minute and $Minute == 5', '$p_weather_metar_page->start', 'NoExpire', 'Update weather information via METAR' )
unless &trigger_get('Update weather information via METAR');
$Weather_Common::weather_module_enabled = 1;
}

if ( said $v_get_metar_weather) {
Expand Down
30 changes: 23 additions & 7 deletions code/common/weather_wunderground.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Category = Weather
#@ Updates live weather variables from http://api.wunderground.com.
#@ Updates live weather variables from http://api.wunderground.com. (Updated MH5)

=begin
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Expand Down Expand Up @@ -36,13 +36,19 @@
my $wunderground_getweather_file;
my $wunderground_stationid = $config_parms{wunderground_stationid};
my $wunderground_apikey = $config_parms{wunderground_apikey};
my $wunderground_units = "f";
$wunderground_units = $config_parms{wunderground_units} if (defined $config_parms{wunderground_units});
my $wunderground_units2 = "mph";
$wunderground_units2 = "kph" if ((defined $config_parms{wunderground_units}) and (lc $config_parms{wunderground_units} eq "c"));

my $wunderground_url;
my %wunderground_data;
my @wunderground_keys;
$p_weather_wunderground_getweather = new Process_Item();

my $wunderground_states = 'getweather,parsefile,debug';
$v_wunderground = new Voice_Cmd("wunderground [$wunderground_states]");
$Weather_Common::weather_module_enabled = 1;

# noloop=stop

Expand Down Expand Up @@ -114,25 +120,26 @@
@wunderground_keys = [];

#TempOutdoor
weather_wunderground_addelem( $channel, 'TempOutdoor', 'temp_f' );
weather_wunderground_addelem( $channel, 'TempOutdoor', 'temp_' . $wunderground_units );

#DewOutdoor
weather_wunderground_addelem( $channel, 'DewOutdoor', 'dewpoint_f' );
weather_wunderground_addelem( $channel, 'DewOutdoor', 'dewpoint_' . $wunderground_units );

#WindAvgDir
weather_wunderground_addelem( $channel, 'WindAvgDir', 'wind_dir' );

#WindAvgSpeed
weather_wunderground_addelem( $channel, 'WindAvgSpeed', 'wind_mph' );
weather_wunderground_addelem( $channel, 'WindAvgSpeed', 'wind_' . $wunderground_units2 );

#WindGustDir
#WindGustSpeed
weather_wunderground_addelem( $channel, 'WindGustSpeed', 'wind_gust_mph' );
weather_wunderground_addelem( $channel, 'WindGustSpeed', 'wind_gust' . $wunderground_units2 );

#WindGustTime
#Clouds
#Conditions
weather_wunderground_addelem( $channel, 'Conditions', 'weather' );
#Clouds
weather_wunderground_addelem( $channel, 'Clouds', 'weather' );

#Barom
weather_wunderground_addelem( $channel, 'Barom', 'pressure_mb' );
Expand All @@ -144,14 +151,23 @@
weather_wunderground_addelem( $channel, 'HumidOutdoor', 'relative_humidity' );

#IsRaining
$wunderground_data{IsRaining} = 0;
$wunderground_data{IsRaining} = 1 if ($wunderground_data{Conditions} =~ m/rain/i);

#IsSnowing
$wunderground_data{IsSnowing} = 0;
$wunderground_data{IsSnowing} = 1 if ($wunderground_data{Conditions} =~ m/snow/i);

weather_wunderground_addelem( $channel, 'Clouds', 'weather' );

#RainTotal
weather_wunderground_addelem( $channel, 'RainTotal', 'precip_today_in' );

#RainRate
weather_wunderground_addelem( $channel, 'LastUpdated', 'observation_time' );
$wunderground_data{LastUpdated} =~ s/^Last Updated on //;

print_log "[WUnderground] " . Dumper %wunderground_data if $Debug{weather} >= 5;

print_log "[WUnderground] Using elements: $config_parms{weather_wunderground_elements}" if $Debug{weather};
&Weather_Common::populate_internet_weather( \%wunderground_data, $config_parms{weather_wunderground_elements} );
&Weather_Common::weather_updated;
Expand Down
1 change: 1 addition & 0 deletions lib/Weather_Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BEGIN {
}

our @weather_hooks;
our $weather_module_enabled; #used to display an icon on web interface if a weather module is enabled

# this should be called whenever a client has FINISHED updating %main::Weather

Expand Down
4 changes: 2 additions & 2 deletions lib/ia7_utilities.pl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for v1.3 update.");
} else {
$json_data->{meta}->{version} = "1.3";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.3 (MH 4.3 IA7 v1.4.400 support)");
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.3 (MH 5.0 IA7 v1.4.400 support)");
$updated = 1;
}
}
Expand All @@ -158,7 +158,7 @@ sub ia7_update_collection {
&main::print_log("[IA7_Collection_Updater] : WARNING: decode_json failed for v1.4 update.");
} else {
$json_data->{meta}->{version} = "1.4";
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.4 (MH 4.3 IA7 v1.5.800 weathericon change)");
&main::print_log("[IA7_Collection_Updater] : Updating $file to version 1.4 (MH 5.0 IA7 v1.5.800 weathericon change)");
$updated = 1;
}
}
Expand Down
6 changes: 5 additions & 1 deletion lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,22 @@ sub json_get {
if ( $path[0] eq 'weather' || $path[0] eq 'misc' || $path[0] eq '' ) {
my $source = "weather";
$source = "misc" if ($path[0] eq 'misc');
my $enabled = 0;
$enabled = 1 if (defined $Weather_Common::weather_module_enabled and $Weather_Common::weather_module_enabled=1);
$json_data{$source}{barom} = $Weather{"Barom"};
$json_data{$source}{summary} = $Weather{"Summary"};
$json_data{$source}{summary_long} = $Weather{"Summary_Long"};
$json_data{$source}{tempindoor} = $Weather{"TempIndoor"};
$json_data{$source}{tempoutdoor} = $Weather{"TempOutdoor"};
$json_data{$source}{wind} = $Weather{"Wind"};
$json_data{$source}{clouds} = $Weather{"Clouds"};
$json_data{$source}{clouds} = (lc $Weather{"Clouds"});
$json_data{$source}{clouds} =~ s/^\s+|\s+$//g; #remove leading/trailing spaces
$json_data{$source}{raining} = int($Weather{"IsRaining"});
$json_data{$source}{snowing} = int($Weather{"IsSnowing"});
$json_data{$source}{night} = $Dark;
$json_data{$source}{weather_lastupdated} = $Weather{"LastUpdated"};
$json_data{$source}{weather_enabled} = $enabled;


}

Expand Down
Loading

0 comments on commit d9bd75b

Please sign in to comment.