Ultimate Wifi and Bluetooth Presence Detection

All kinds of 'OS' scripts
siebke
Posts: 3
Joined: Monday 29 August 2016 13:53
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by siebke » Wednesday 31 August 2016 13:13

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

User avatar
bizziebis
Posts: 540
Joined: Saturday 19 October 2013 14:00
Target OS: Raspberry Pi
Domoticz version: 3.8805
Location: The Netherlands
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by bizziebis » Wednesday 31 August 2016 13:48

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?

siebke
Posts: 3
Joined: Monday 29 August 2016 13:53
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by siebke » Wednesday 31 August 2016 14:30

Thanks!! @bizziebis

That was indeed the problem. Seems that wen't something wrong while saving the file in Unix Encoding with Notepad++.

DavidB
Posts: 12
Joined: Tuesday 25 November 2014 18:44
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by DavidB » Wednesday 19 October 2016 21:31

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.

gooxbe
Posts: 7
Joined: Wednesday 23 November 2016 11:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by gooxbe » Saturday 26 November 2016 21:30

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. :(

korniza
Posts: 198
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi
Domoticz version: V3.6028
Location: Greece
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by korniza » Sunday 27 November 2016 6:44

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)
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)

balk
Posts: 1
Joined: Monday 02 May 2016 21:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by balk » Friday 02 December 2016 23:34

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&param=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null
else
echo "$Name" "Offline"
curl -s "http://"$domoticzserverip"/json.htm?type=command&param=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null
fi
fi
sleep 60

done

kinghuzi
Posts: 20
Joined: Tuesday 10 November 2015 12:47
Target OS: -
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by kinghuzi » Monday 12 December 2016 16:26

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.

kinghuzi
Posts: 20
Joined: Tuesday 10 November 2015 12:47
Target OS: -
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by kinghuzi » Sunday 18 December 2016 9:38

Would anyone please assist with above. Really am desperate to get this to work and wife is loosing patience with home automation project :/

sach
Posts: 96
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by sach » Wednesday 21 December 2016 9:43

Thanks for the script. I had it running for a day but found that it was causing major battery drain on my device.

Stewie3112
Posts: 2
Joined: Wednesday 11 January 2017 11:27
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by Stewie3112 » Saturday 21 January 2017 14:58

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?

clearminds
Posts: 4
Joined: Thursday 02 February 2017 22:29
Target OS: Linux
Domoticz version: Beta
Location: Stockholm, Sweden
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by clearminds » Monday 06 February 2017 0:05

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. :D
Hello Ben,

A while since you wrote this - but any progress on your multi system?

Best Regards
Daniel

aee74
Posts: 3
Joined: Saturday 18 February 2017 15:52
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by aee74 » Saturday 18 February 2017 15:56

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
Posts: 3
Joined: Saturday 18 February 2017 15:52
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by aee74 » Sunday 19 February 2017 9:43

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?

User avatar
mlamie
Posts: 153
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by mlamie » Friday 24 February 2017 21:40

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

User avatar
mlamie
Posts: 153
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by mlamie » Tuesday 28 February 2017 18:52

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?

Image
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

pvm
Posts: 952
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by pvm » Tuesday 28 February 2017 20:44

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, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

User avatar
mlamie
Posts: 153
Joined: Friday 25 October 2013 17:12
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: The Netherlands
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by mlamie » Tuesday 28 February 2017 21:43

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

possible
Posts: 18
Joined: Monday 10 October 2016 22:06
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by possible » Thursday 16 March 2017 22:15

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??

hannibal2206
Posts: 16
Joined: Monday 08 August 2016 23:22
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Ultimate Wifi and Bluetooth Presence Detection

Post by hannibal2206 » Wednesday 22 March 2017 13:32

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests