- priority
- snooze time (if already alerted, when to re-alert?)
- text: subject/body
-- Reduce wireless sensor resource footprint:
- - use `nmcli monitor`, instead of polling, for state changes
- - use `iwconfig`, instead of `nmcli`, for SSID and signal strength
["--weather_station_id"]='KJFK'
["--screen_brightness_device_name"]='acpi_video0'
["--prefixes_of_net_interfaces_to_show"]='w' # comma-separated
+ ["--wifi_interface"]=''
["--disk_space_device"]='/'
["--disk_io_device"]='sda'
["--thermal_zone"]=0
esac
done
+ if [ "${opts['--wifi_interface']}" = '' ]
+ then
+ echo 'Please provide the required parameter: --wifi_interface' >&2
+ exit 1
+ fi
+
(
echo '=============================================='
echo "Khatus starting with the following parameters:"
cmd_sens_mpd_state="khatus_sensor_mpd_state $bin"
cmd_sens_net_addr_io="khatus_sensor_net_addr_io $bin"
cmd_sens_volume="khatus_sensor_volume $bin"
+ cmd_sens_wifi="khatus_sensor_net_wifi_status $bin ${opts['--wifi_interface']}"
fork_watcher "$pipe" "$bin" "khatus_sensor_energy $bin" 'in:ENERGY'
fork_poller "${opts['--interval_inp_datetime']}" "$pipe" "$bin" khatus_sensor_datetime 'in:DATE_TIME'
fork_poller "${opts['--interval_inp_mpd_song']}" "$pipe" "$bin" khatus_sensor_mpd_song 'in:MPD_SONG'
fork_poller "${opts['--interval_inp_volume']}" "$pipe" "$bin" "$cmd_sens_volume" 'in:VOLUME'
fork_poller "${opts['--interval_inp_bluetooth']}" "$pipe" "$bin" "$cmd_sens_bluetooth" 'in:BLUETOOTH_POWER'
- fork_poller "${opts['--interval_inp_net_wifi']}" "$pipe" "$bin" khatus_sensor_net_wifi_status 'in:NET_WIFI_STATUS'
+ fork_poller "${opts['--interval_inp_net_wifi']}" "$pipe" "$bin" "$cmd_sens_wifi" 'in:NET_WIFI_STATUS'
fork_poller "${opts['--interval_inp_net_io']}" "$pipe" "$bin" "$cmd_sens_net_addr_io" 'in:NET_ADDR_IO'
fork_poller "${opts['--interval_inp_disk_space']}" "$pipe" "$bin" "$cmd_sens_disk_space" 'in:DISK_SPACE'
fork_poller "${opts['--interval_inp_disk_io']}" "$pipe" "$bin" "$cmd_sens_disk_io" 'in:DISK_IO'
{
shift()
shift()
- db["net_wifi_status"] = $0
+ set_net_wifi_status()
}
/^OK in:BLUETOOTH_POWER/\
db["disk_io_diff_r"] = curr_r - prev_r
}
+function set_net_wifi_status( interface) {
+ interface = $1
+ shift()
+ db["net_wifi_status", interface] = $0
+}
+
function set_net_addr_io( \
interface, address, io_curr_w, io_curr_r, io_prev_w, io_prev_r\
) {
io_stat = "--"
}
if (interface ~ "^w") {
- label = label ":" db["net_wifi_status"]
+ label = label ":" db["net_wifi_status", interface]
}
if (++count_printed > 1) {
sep = " "
--- /dev/null
+#! /usr/bin/awk -f
+#
+# Example iwconfig output:
+# -----------------------
+# $ iwconfig wlp3s0
+# wlp3s0 IEEE 802.11 ESSID:"BPLUNWIRED"
+# Mode:Managed Frequency:5.785 GHz Access Point: E2:55:2D:C0:64:B8
+# Bit Rate=135 Mb/s Tx-Power=15 dBm
+# Retry short limit:7 RTS thr:off Fragment thr:off
+# Power Management:on
+# Link Quality=59/70 Signal level=-51 dBm
+# Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
+# Tx excessive retries:0 Invalid misc:0 Missed beacon:0
+#
+#
+# USAGE: khatus_parse_iwconfig -v requested_interface="$wifi_interface"
+
+/^[a-z0-9]+ +IEEE 802\.11 +ESSID:/ {
+ interface = $1
+ split($4, essid_parts, ":")
+ essid[interface] = essid_parts[2]
+ gsub("\"", "", essid[interface])
+}
+
+/^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
+ split($2, lq_parts_eq, "=")
+ split(lq_parts_eq[2], lq_parts_slash, "/")
+ cur = lq_parts_slash[1]
+ max = lq_parts_slash[2]
+ link[interface] = cur / max * 100
+}
+
+END {
+ i = requested_interface
+ status = link[i] ? sprintf("%s %s:%d%%", i, essid[i], link[i]) : "--"
+ print(status)
+}
set -e
-nmcli \
- -f ACTIVE,SSID,SIGNAL \
- -t \
- d wifi \
-| awk \
- -F ':' \
- '
- BEGIN {wifi_status = "--"}
- $1 == "yes" {wifi_status = $2 ":" $3 "%"}
- END {print wifi_status}
- '
+dir_bin="$1"
+wifi_interface="$2"
+
+iwconfig "$wifi_interface" \
+| "$dir_bin"/khatus_parse_iwconfig -v requested_interface="$wifi_interface"