'Bash/Pinger/Smartping.sh.examp' updaten
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Set Parameters
|
echo $$ > /var/log/pid/Smartping-Bram@OP6T.pid
|
||||||
Name='<Name>'
|
|
||||||
domoticzserverip='127.0.0.1:8080'
|
|
||||||
IDX='<Dev-IDX>'
|
|
||||||
IP='<IPaddr>'
|
|
||||||
bluetoothmac='<BT-Mac>'
|
|
||||||
|
|
||||||
echo $$ > /var/log/pid/"$Name".pid
|
# Set Parameters
|
||||||
|
Name='<DevName>'
|
||||||
|
domoticzserverip='127.0.0.1:8080'
|
||||||
|
IDX='<DomoIDX>'
|
||||||
|
IP='<DevStaticIP>'
|
||||||
|
bluetoothmac='<DevBTMac:>'
|
||||||
|
|
||||||
while [ 1 ]
|
while [ 1 ]
|
||||||
do
|
do
|
||||||
@@ -15,9 +15,8 @@ do
|
|||||||
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
||||||
if [ "$?" = 0 ] ; then
|
if [ "$?" = 0 ] ; then
|
||||||
device="On"
|
device="On"
|
||||||
technology="Online using: Wifi 1"
|
technology="Online, Wifi 1"
|
||||||
success="yes"
|
success="yes"
|
||||||
sleep 1
|
|
||||||
else
|
else
|
||||||
success="no"
|
success="no"
|
||||||
fi
|
fi
|
||||||
@@ -27,7 +26,7 @@ if [[ $success != 'yes' ]]; then
|
|||||||
bt1=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
bt1=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
||||||
if [[ $bt1 == 'On' ]]; then
|
if [[ $bt1 == 'On' ]]; then
|
||||||
device="On"
|
device="On"
|
||||||
technology="Online using: Bluetooth 1"
|
technology="Online, Bluetooth 1"
|
||||||
success="yes"
|
success="yes"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -37,7 +36,7 @@ if [[ $success != 'yes' ]]; then
|
|||||||
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
||||||
if [ "$?" = 0 ] ; then
|
if [ "$?" = 0 ] ; then
|
||||||
device="On"
|
device="On"
|
||||||
technology="Online using: Wifi 2"
|
technology="Online, Wifi 2"
|
||||||
success="yes"
|
success="yes"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -47,7 +46,7 @@ if [[ $success != 'yes' ]]; then
|
|||||||
bt2=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
bt2=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
||||||
if [[ $bt2 == 'On' ]]; then
|
if [[ $bt2 == 'On' ]]; then
|
||||||
device="On"
|
device="On"
|
||||||
technology="Online using: Bluetooth 2"
|
technology="Online, Bluetooth 2"
|
||||||
success="yes"
|
success="yes"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -60,18 +59,24 @@ fi
|
|||||||
|
|
||||||
# Check Online / Offline state of Domoticz device
|
# 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')
|
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
|
# Compare ping result to Domoticz device status
|
||||||
if [ "$device" = "$domoticzstatus" ] ; then
|
if [ "$device" = "$domoticzstatus" ] ; then
|
||||||
echo "Current status: $technology"
|
echo "$CurTime | Device: $Name | Status: $technology"
|
||||||
else
|
else
|
||||||
echo "Status desynchronized, resynchronizing..."
|
echo "Status desynchronized, resynchronizing..."
|
||||||
if [ "$device" = On ] ; then
|
if [ "$device" = On ] ; then
|
||||||
echo "$Name" "set Online"
|
echo "$CurTime | Device: $Name | Sync: Online"
|
||||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null
|
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null
|
||||||
else
|
else
|
||||||
echo "$Name" "set Offline"
|
echo "$CurTime | Device: $Name | Sync: Offline"
|
||||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null
|
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
#Waiting if Device is online
|
||||||
|
if [ "$device" = On ] ; then
|
||||||
|
echo "$CurTime | Device: $Name | Status: Online, Waiting"
|
||||||
|
sleep 60
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
Reference in New Issue
Block a user