Page 3 of 5
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 31 August 2016 13:13
by siebke
I was using the correct syntax indeed “sudo ./iphone_roger.sh” so that’s not likely the problem.
Running the sudo/bin/bash command doesn’t seem to give any output…..?
Code: Select all
root@raspberrypi:/home/pi/domoticz/scripts# sudo /bin/bash
root@raspberrypi:/home/pi/domoticz/scripts#
I also added de Domoticz port number and this seems to change the output but sill it doesn’t work like it should.
Code: Select all
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
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 31 August 2016 13:48
by bizziebis
Your sh script seems to be in the wrong format. Something like MS-DOS vs Unix encoding. Did you create the file in Windows and move it to your PI?
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 31 August 2016 14:30
by siebke
Thanks!! @bizziebis
That was indeed the problem. Seems that wen't something wrong while saving the file in Unix Encoding with Notepad++.
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 19 October 2016 21:31
by DavidB
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.
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Saturday 26 November 2016 20:30
by gooxbe
Would it work with ping only?
Installing fping on a synology DS213+ is a pain... I build it from sources and fping doesn't work.

Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Sunday 27 November 2016 5:44
by korniza
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!
The howto guide is here:
http://www.fhemwiki.de/wiki/Anwesenheitserkennung (google translate is your friend)
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Friday 02 December 2016 22:34
by balk
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.
Code: Select all
#!/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
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Monday 12 December 2016 15:26
by kinghuzi
Need a bit of assistance with this script. Something wrong with cooling off period as it keeps changes the virtual switch on/off every minute.
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Sunday 18 December 2016 8:38
by kinghuzi
Would anyone please assist with above. Really am desperate to get this to work and wife is loosing patience with home automation project :/
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 21 December 2016 8:43
by sach
Thanks for the script. I had it running for a day but found that it was causing major battery drain on my device.
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Saturday 21 January 2017 13:58
by Stewie3112
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?
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Sunday 05 February 2017 23:05
by clearminds
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?
Best Regards
Daniel
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Saturday 18 February 2017 14:56
by aee74
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?
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Sunday 19 February 2017 8:43
by aee74
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?
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Friday 24 February 2017 20:40
by mlamie
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.
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Tuesday 28 February 2017 17:52
by mlamie
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?

Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Tuesday 28 February 2017 19:44
by pvm
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
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Tuesday 28 February 2017 20:43
by mlamie
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?
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Thursday 16 March 2017 21:15
by possible
Hi,
I am trying to use the script, but ive got the following errors:
Code: Select all
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
I really dont know what cant be found??
Re: Ultimate Wifi and Bluetooth Presence Detection
Posted: Wednesday 22 March 2017 12:32
by hannibal2206
I removed the ´while .. do´ statement in the script so it only runs once; and call that script via a crontab entry every 1 minute.
Seems to work fine