root@raspberrypi:/home/pi/domoticz/scripts# sudo ./iphone_roger.sh
./iphone_roger.sh: 1: ./iphone_roger.sh: #!/bin/bash: not found
./iphone_roger.sh: 25: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 35: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 45: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 55: ./iphone_roger.sh: [[: not found
Status out of sync, correcting...
iPhone Roger Offline
./iphone_roger.sh: 25: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 35: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 45: ./iphone_roger.sh: [[: not found
./iphone_roger.sh: 55: ./iphone_roger.sh: [[: not found
Status out of sync, correcting...
iPhone Roger Offline
./iphone_roger.sh: 25: ./iphone_roger.sh: [[: not found
Got the script working but it is a bit over eager to change the status as it never gets to the 2nd attempt part of the script and just jumps to device offline, bearing in mind that this appears to pole every couple of seconds it could do with a better "cool off" period before it changes status.
You better check FHEM for any device presence. I have described that on viewtopic.php?f=28&t=10640&p=87396#p87194 for bluetooth beacons but it can also detect from a snmp enabled wireless AP, if a MAC address is active and report state back to domoticz!
This is a wonderful concept! Thanks for putting the script together. It gave me some little headache so I fixed it. Added a sleep statement; a resolution of 1 minute is good enough for my purpose. I've added the port number. And the quotes in the curl statements gave me errors (Raspbian)
I have the script running with Supervisor to guard its status.
#!/bin/bash
while [ 1 ]
do
# Set Parameters
Name='Phone'
domoticzserverip='192.168.0.10:8080'
IDX='30'
IP='192.168.0.9'
bluetoothmac='ab:cd:ef:ab:cd:ef'
# First network ping attempt
fping -c1 -b 32 -t1000 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ] ; then
device=$(echo "On")
technology="Wifi 1st attempt"
success="yes"
sleep 1
else
success="no"
technology=''
fi
# First bluetooth ping attempt
if [[ $success != 'yes' ]]; then
bt1=$(l2ping -c1 -s32 -t1 "$bluetoothmac" > /dev/null && echo "On" || echo "Off")
if [[ $bt1 == 'On' ]]; then
device=$(echo "On")
technology="Bluetooth 1st attempt"
success="yes"
fi
fi
# Second network ping attempt
if [[ $success != 'yes' ]]; then
fping -c1 -b 32 -t1000 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ] ; then
device=$(echo "On")
technology="Wifi 2nd attempt"
success="yes"
fi
fi
# Second bluetooth ping attempt
if [[ $success != 'yes' ]]; then
bt1=$(l2ping -c1 -s32 -t1 "$bluetoothmac" > /dev/null && echo "On" || echo "Off")
if [[ $bt1 == 'On' ]]; then
device=$(echo "On")
technology="Bluetooth 2nd attempt"
success="yes"
fi
fi
# If the device is still offline, declare it for processing
if [[ $success != 'yes' ]]; then
device=$(echo "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 "Status in sync $technology"
else
echo "Status out of sync, correcting..."
if [ "$device" = On ] ; then
echo "$Name" "Online"
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null
else
echo "$Name" "Offline"
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null
fi
fi
sleep 60
done
jnoel68 wrote:Works fine for me, with a CSR 4.0 USB dongle plugged on my synology.
I'm able to detect my iPhone via Wifi or Bluetooth.
But I would like to go further and try to detect my beacons (chipolos), but I'm not able to find their ble mac address.
Any idea guys ?
Thx
I managed too to get the script working on my sinology, but i'm quite noob in scripting and really don't know how to automate the script without having to manually launch it... Can someone help?
ben53252642 wrote:
I have a php version of this which writes to a MySQL database and is "multi node", as in I have Raspberry Pi's around the house with Bluetooth dongles on them and they each report to the database if they can see the target device, this was my approach for extending the range of the presence detection.
I'll be making the code for the multi-node setup available shortly.
Hello Ben,
A while since you wrote this - but any progress on your multi system?
Probably a stupid question but i'll ask anyway. I creatd the script and the script detects my iPhone. But in domoticz nothing happens. My idx (65) is not respondig. Any tips?
aee74 wrote:Probably a stupid question but i'll ask anyway. I creatd the script and the script detects my iPhone. But in domoticz nothing happens. My idx (65) is not respondig. Any tips?
Found it. I had to set the port number for my domoticz server.
Does anyone kwow how to edit the script to detect a second device?
balk wrote:This is a wonderful concept! Thanks for putting the script together. It gave me some little headache so I fixed it. Added a sleep statement; a resolution of 1 minute is good enough for my purpose. I've added the port number. And the quotes in the curl statements gave me errors (Raspbian)
I have the script running with Supervisor to guard its status.
Hi balk, thanks for the enhancement. I installed the script and added it to crontab which start it every 10 min. Now lets see how it works.
aee74 wrote:Does anyone kwow how to edit the script to detect a second device?
Just create a second script for the second device.
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
Hmm adding the script to crontab isn't a good idea... Eventually the memory increase leads to a crash of domoticz.
Screen could be an option, but is there a better way?
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
The script runs in a loop right? When starting the script every 10 minutes it will run 6times in parallel after an hour.
You should also see this behavior in the log of the switch
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
It is not shown in domoticz since it is a external script. The actual script performs a fping/bt check every minute. I expect it only needs to be started once. Does anyone has a tip how to get it started automatically 'just once' also after a reboot of the RPi?
Raspberry Pi 3, RaZberry, RFXtrx433
Various Z-Wave devices, KlikAanKlikUit devices, ESP8266 NodeMCU, Sonoff POW and a Essent E-thermostaat
IP camera: Dahua 4MP IPC-HDBW4421R-AS, Vivotek FD8134V
Status in sync
./android.sh: line 26: l2ping: command not found
./android.sh: line 46: l2ping: command not found
Status in sync
./android.sh: line 26: l2ping: command not found
./android.sh: line 46: l2ping: command not found
Status in sync
./android.sh: line 26: l2ping: command not found
./android.sh: line 46: l2ping: command not found
Status in sync
./android.sh: line 26: l2ping: command not found
./android.sh: line 46: l2ping: command not found
Status in sync
./android.sh: line 26: l2ping: command not found
./android.sh: line 46: l2ping: command not found