From 72d8ff0ce6e9af5f8f7fbf6ee1d9b965bd436b73 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Fri, 5 Jun 2020 00:44:08 +0000 Subject: [PATCH] 'Bash/Pinger/ WIFI-Ping.sh.examp' toevoegen --- Bash/Pinger/ WIFI-Ping.sh.examp | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Bash/Pinger/ WIFI-Ping.sh.examp diff --git a/Bash/Pinger/ WIFI-Ping.sh.examp b/Bash/Pinger/ WIFI-Ping.sh.examp new file mode 100644 index 0000000..f3e8e13 --- /dev/null +++ b/Bash/Pinger/ WIFI-Ping.sh.examp @@ -0,0 +1,72 @@ +#!/bin/bash + +# Set Parameters +Name='' +domoticzserverip='127.0.0.1:8080' +IDX='' +IP='' + +echo $$ > /var/log/pid/"$Name".pid + +while [ 1 ] +do +# First Network ping attempt +fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1 +if [ "$?" = 0 ] ; then +device="On" +technology="Online, Wifi 1" +success="yes" +else +success="no" +fi + +# Waiting 10 seconds to avoid haning the script +if [[ $success != 'yes' ]]; then +sleep 10 +fi + +# Second network ping attempt +if [[ $success != 'yes' ]]; then +fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1 +if [ "$?" = 0 ] ; then +device="On" +technology="Online, Wifi 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') +CurTime=$(date '+%d/%m/%Y %H:%M'); +# Compare ping result to Domoticz device status +if [ "$device" = "$domoticzstatus" ] ; then +echo "$CurTime | Device: $Name | Domo: Synced | Status: $technology" +else +#echo "Status desynchronized, resynchronizing..." +if [ "$device" = On ] ; then +echo "$CurTime | Device: $Name | Domo: Desynced | Status: $technology" +curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null +else +echo "$CurTime | Device: $Name | Domo: Desynced | Status: $technology" +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 + +#Waiting if Device is online +if [ "$device" = On ] ; then +echo "$CurTime | Device: $Name | Status: Online, Waiting" +sleep 60 + +done \ No newline at end of file