Alert on reported weather phenomena
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 8 Aug 2018 00:05:00 +0000 (20:05 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 8 Aug 2018 00:05:00 +0000 (20:05 -0400)
bin/khatus
bin/khatus_controller
bin/khatus_parse_metar_d_output [new file with mode: 0755]
bin/khatus_sensor_weather

index 6ae08b0..48d3cef 100755 (executable)
@@ -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']}"
index c67e640..587e37c 100755 (executable)
     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 (executable)
index 0000000..49f1067
--- /dev/null
@@ -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]
+        }
+    }
+}
index 340175d..371010f 100755 (executable)
@@ -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
This page took 0.031353 seconds and 4 git commands to generate.