From: Siraaj Khandkar Date: Wed, 8 Aug 2018 00:05:00 +0000 (-0400) Subject: Alert on reported weather phenomena X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=654ea6e2ddf5986f1975cd860575248c114102fe;p=khatus.git Alert on reported weather phenomena --- diff --git a/bin/khatus b/bin/khatus index 6ae08b0..48d3cef 100755 --- a/bin/khatus +++ b/bin/khatus @@ -138,7 +138,7 @@ main() { cmd_sens_screen_brightness='khatus_sensor_screen_brightness' cmd_sens_screen_brightness+=" $screen_brightness_device_path" - cmd_sens_weather="khatus_sensor_weather ${opts['--weather_station_id']}" + cmd_sens_weather="khatus_sensor_weather $bin ${opts['--weather_station_id']}" cmd_sens_disk_space="khatus_sensor_disk_space ${opts['--disk_space_device']}" cmd_sens_disk_io="khatus_sensor_disk_io ${opts['--disk_io_device']}" cmd_sens_temperature="khatus_sensor_temperature ${opts['--thermal_zone']}" diff --git a/bin/khatus_controller b/bin/khatus_controller index c67e640..587e37c 100755 --- a/bin/khatus_controller +++ b/bin/khatus_controller @@ -133,13 +133,22 @@ db["mpd_status_percent"] = $3 } -/^OK in:WEATHER/\ +/^OK in:WEATHER temperature/\ { + shift() shift() shift() db["weather_temperature"] = $0 } +/^OK in:WEATHER phenomena/\ +{ + shift() + shift() + shift() + alert_trigger_low("weather_phenomena", "WeatherPhenomena", $0) +} + /^OK in:DATE_TIME/\ { shift() diff --git a/bin/khatus_parse_metar_d_output b/bin/khatus_parse_metar_d_output new file mode 100755 index 0000000..49f1067 --- /dev/null +++ b/bin/khatus_parse_metar_d_output @@ -0,0 +1,44 @@ +#! /usr/bin/awk -f +# +# Qualifying the name as "_d_output" lest it be mistaken for parser of actual +# metar format. + +function strip(s) { + sub("^ *", "", s) + sub(" *$", "", s) + return s +} + +/METAR pattern not found in NOAA data/ { + failures++ + exit +} + +/[A-z][a-z]+ *: / { + split($0, line, ":") + key = strip(line[1]) + val = strip(line[2]) + values[NR] = val + first[key] = NR + last[key] = NR +} + +/^ +/ { + values[NR] = strip($0) + last[key] = NR +} + +END { + if (failures) { + print "metar fetch failed" > "/dev/stderr" + } else { + temp_string = values[first["Temperature"]] + split(temp_string, temp_parts, " +") + temp_celsius = temp_parts[1] + temp_fahrenheit = (temp_celsius * (9 / 5)) + 32 + print "temperature " temp_fahrenheit "°F" + for (i=first["Phenomena"]; i<=last["Phenomena"]; i++) { + print "phenomena " values[i] + } + } +} diff --git a/bin/khatus_sensor_weather b/bin/khatus_sensor_weather index 340175d..371010f 100755 --- a/bin/khatus_sensor_weather +++ b/bin/khatus_sensor_weather @@ -2,23 +2,7 @@ set -e -weather_station_id="$1" +dir_bin="$1" +weather_station_id="$2" -metar -d "$weather_station_id" 2>&1 \ -| awk ' - /METAR pattern not found in NOAA data/ { - failures++ - } - - /^Temperature/ { - celsius = $3; - fahrenheit = (celsius * (9 / 5)) + 32; - temperature = fahrenheit - } - - END { - if (failures > 0) { - temperature = "--" - } - print temperature "°F" - }' +metar -d "$weather_station_id" 2>&1 | "$dir_bin"/khatus_parse_metar_d_output