cmd_sens_fan="khatus_sensor_fan $fan_path"
+ cmd_sens_bluetooth="khatus_sensor_bluetooth_power $dir_bin"
+
# TODO: Redirect each worker's stderr to a dedicated log file
pipe="$file_pipe"
log="$dir_logs"/khatus_sensors.log
fork_poller $interval_inp_mpd_state "$pipe" "$dir_bin" "$log" khatus_sensor_mpd_state 'in:MPD_STATE'
fork_poller $interval_inp_mpd_song "$pipe" "$dir_bin" "$log" khatus_sensor_mpd_song 'in:MPD_SONG'
fork_poller $interval_inp_volume "$pipe" "$dir_bin" "$log" khatus_sensor_volume 'in:VOLUME'
- fork_poller $interval_inp_bluetooth "$pipe" "$dir_bin" "$log" khatus_sensor_bluetooth_power 'in:BLUETOOTH_POWER'
+ fork_poller $interval_inp_bluetooth "$pipe" "$dir_bin" "$log" "$cmd_sens_bluetooth" 'in:BLUETOOTH_POWER'
fork_poller $interval_inp_net_wifi "$pipe" "$dir_bin" "$log" khatus_sensor_net_wifi_status 'in:NET_WIFI_STATUS'
fork_poller $interval_inp_net_io "$pipe" "$dir_bin" "$log" khatus_sensor_net_addr_io 'in:NET_ADDR_IO'
fork_poller $interval_inp_disk_space "$pipe" "$dir_bin" "$log" "$cmd_sens_disk_space" 'in:DISK_SPACE'
--- /dev/null
+#! /usr/bin/awk -f
+
+/^Controller / {
+ controller = $2
+ controllers[++ctrl_count] = controller
+}
+
+/^\t[A-Z][A-Za-z]+:/ {
+ key = $1
+ sub(":$", "", key)
+ sub("^" $1, "")
+ val = $0
+ data[controller, key] = val
+}
+
+END {
+ # Using the 1st seen controller. Should we select specific instead?
+ power_status = data[controllers[1], "Powered"]
+ if (ctrl_count > 0) {
+ if (power_status == "no") {
+ show = "off"
+ } else if (power_status == "yes") {
+ show = "on"
+ } else {
+ print_error("Unexpected bluetooth power status: " power_status)
+ show = "ERROR"
+ }
+ } else {
+ show = "off" # TODO: Perhaps use differentiated marker?
+ }
+ print(show)
+}
+
+function print_error(msg) {
+ print(msg) > "/dev/stderr"
+}
set -e
-echo -e 'show \n quit' \
-| bluetoothctl \
-| awk '
- /^Controller / {
- controller = $2;
- controllers[++ctrl_count] = controller;
- }
- /^\t[A-Z][A-Za-z]+:/ {
- key = $1;
- sub(":$", "", key);
- val = $2;
- for (i=3; i<=NF; i++) {
- val = val " " $i};
- data[controller, key] = val;
- }
- END {
- # Using the 1st seen controller. Should we select specific instead?
- power_status = data[controllers[1], "Powered"];
- if (ctrl_count > 0) {
- if (power_status == "no") {
- power_status = "off"
- } else if (power_status == "yes") {
- power_status = "on"
- } else {
- printf("Unexpected bluetooth power status: %s\n", power_status)\
- > "/dev/stderr";
- power_status = "ERROR"
- }
- } else {
- power_status = "off" # TODO: Perhaps use differentiated marker?
- }
- printf("%s\n", power_status);
- }'
+dir_bin="$1"
+
+echo -e 'show \n quit' | bluetoothctl | "$dir_bin"/khatus_parse_bluetoothctl_show