#!/bin/bash # start the bridge in the background /usr/bin/node /usr/local/lib/node_modules/mqtt-dss-bridge/index.js > /dev/null 2>&1 & PID=$! echo "DSS Bridge started with PID $PID" # start a loop to monitor the status every second errcntr=0 lastUpdate=999 while true; do lastUpdate=$(( \ $(date +%s)\ -\ $(date -d "$(\ mosquitto_sub -h localhost -u sonoffs -P sonoff -t dss/state/lastDiscovered -C 1 | \ sed -E -e 's/"([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}).*$/\1 \2Z/'\ )" +%s)\ )) if [ 10 -lt $lastUpdate ]; then if [ $errcntr -lt 10 ]; then let errcntr++ echo "DSS Bridge state is too old (last updated $lastUpdate seconds ago, max 10 allowed). This was failure $errcntr out of 10 accepted failures" else echo "DSS bridge state is still too old ($lastUpdate seconds) after 10 retries. killing mqtt-dss-bridge (pid $PID) and exit with error status 1" kill $PID exit 1 fi fi sleep 1 done