From d2e4d3af04a24786b2e96fec3538027452585706 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Tue, 15 Oct 2019 22:13:45 +0000 Subject: [PATCH] 'Bash/Pinger/BTPing.sh.examp' toevoegen --- Bash/Pinger/BTPing.sh.examp | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Bash/Pinger/BTPing.sh.examp diff --git a/Bash/Pinger/BTPing.sh.examp b/Bash/Pinger/BTPing.sh.examp new file mode 100644 index 0000000..c7f15f6 --- /dev/null +++ b/Bash/Pinger/BTPing.sh.examp @@ -0,0 +1,63 @@ +#!/bin/bash + +# Set Parameters +Name='' +domoticzserverip='127.0.0.1:8080' +IDX='' +bluetoothmac='' + +echo $$ > /var/log/pid/"$Name".pid + +while [ 1 ] +do +# First bluetooth ping attempt +bt1=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off") +if [[ $bt1 == 'On' ]]; then +device="On" +technology="Online using: Bluetooth 1" +success="yes" +fi + +# Waiting 10 seconds to avoid haning the script +if [[ $success != 'yes' ]]; then +sleep 10 +fi + +# Second bluetooth ping attempt +if [[ $success != 'yes' ]]; then +bt2=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off") +if [[ $bt2 == 'On' ]]; then +device="On" +technology="Online using: Bluetooth 2" +success="yes" +fi +fi + +# If the device is still offline, declare it for processing +if [[ $success != 'yes' ]]; then +technology="Offline" +device="Off" +fi + +# Check Online / Offline state of Domoticz device +domoticzstatus=$(curl -s "http://"$domoticzserverip"/json.htm?type=devices&rid="$IDX"" | grep '"Data" :' | awk '{ print $3 }' | sed 's/[!@#\$%",^&*()]//g') +# Compare ping result to Domoticz device status +if [ "$device" = "$domoticzstatus" ] ; then +echo "Current status: $technology" +else +echo "Status desynchronized, resynchronizing..." +if [ "$device" = On ] ; then +echo "$Name" "set Online" +curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null +else +echo "$Name" "set Offline" +curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null +fi +fi + +# Waiting 10 seconds to avoid haning the script +if [[ $success != 'yes' ]]; then +sleep 10 +fi + +done