From f2ac15921368a5e421f4e42e4317aff7ee1c7a1e Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sun, 2 Aug 2020 02:26:03 +0200 Subject: add mqtt_monitor_systemlock.sh --- scripts/mqtt_monitor_systemlock.sh | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 scripts/mqtt_monitor_systemlock.sh (limited to 'scripts') diff --git a/scripts/mqtt_monitor_systemlock.sh b/scripts/mqtt_monitor_systemlock.sh new file mode 100755 index 0000000..92ce987 --- /dev/null +++ b/scripts/mqtt_monitor_systemlock.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Automatically lock/unlock system with bluetooth based presence detection +# using monitor on raspi and mosquitto MQTT client +# +# ./mqtt_monitor_systemlock.sh [BROKER] [TOPIC] + + +readonly THRESHHOLD=50 +LAST_CONFIDENCE=100 + +readonly DEPENDS=( mosquitto_sub jq xset xsecurelock ) +for prog in "${DEPENDS[@]}"; do + if ! which $prog > /dev/null 2>&1; then + echo $prog not found + exit 1 + fi +done + +while read msg; do + if ! CONFIDENCE=$(jq -r ".confidence" <<< "$msg"; exit $?); then + echo JQ parse error. + exit 1 + fi + + if [ $CONFIDENCE -lt $THRESHHOLD -a $LAST_CONFIDENCE -ge $THRESHHOLD ]; then + echo [$(date +%d.%m.%Y\ %H:%M)] OFF + + XSECURELOCK_PASSWORD_PROMPT=kaomoji xsecurelock 2> /dev/null & + LOCK_PID=$! + + xset dpms force standby + elif [ $CONFIDENCE -gt $THRESHHOLD -a $LAST_CONFIDENCE -le $THRESHHOLD ]; then + echo [$(date +%d.%m.%Y\ %H:%M)] ON + + kill $LOCK_PID + + xset dpms force on + fi + + LAST_CONFIDENCE=$CONFIDENCE +done < <( mosquitto_sub -h "$1" -t "$2" ) -- cgit v1.2.3