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']}"
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()
--- /dev/null
+#! /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]
+ }
+ }
+}
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