Yet another presence detection method

Moderator: leecollings

mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post by mayyam »

MAC is present or not. There is no other way.
So if its not present, its because phone is not in the wifi/LAN, or phone have another MAC.
And that another MAC is our "virtual" MAC. Usually that MAC have 3 segments of its oryginal MAC.
You can try arp -a, maybe it shows refreshed list of MACs?

Or maybe its not an AP, but its another router connected as client with his own DHCP server? But then the MAC should not be visible in the first LAN after hi connects to "AP". Maybe You can see him because of lease time, but its just the record of that MAC for given time.
____
may
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by BaliBiker »

MAC is present or not. There is no other way.
So if its not present, its because phone is not in the wifi/LAN, or phone have another MAC.
And that another MAC is our "virtual" MAC. Usually that MAC have 3 segments of its oryginal MAC.
You can try arp -a, maybe it shows refreshed list of MACs?

Or maybe its not an AP, but its another router connected as client with his own DHCP server? But then the MAC should not be visible in the first LAN after hi connects to "AP". Maybe You can see him because of lease time, but its just the record of that MAC for given time.
Thanks May, your reaction made me think of the following.

Although my phone is connected to the AP (wich is a router with disabmled DHCP), the phone is listed in my router as connected device. But it shows up as wired. The command

Code: Select all

arp -a
gives the following result.

Code: Select all

undefined (192.168.1.71) at 60:f1:89:87:68:fd [ether]  on br0
Would it an idea to ad the wired connection to the script as well?
Can I do this by adding the following to the scripr?

Code: Select all

# look in wired (ether) network for device
for x in `wl -i ether assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done
Or should it not be 'ether' but 'br0'?
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by Mooseknuckle »

Hi,
You can try and change this:

Code: Select all

for x in `wl -i ether assoclist | awk '{print $2}'`; do
into this:

Code: Select all

for x in `arp -a | awk '{print $4}'`; do
But if you change this I honestly don't know what the difference is (except location of script) between this solution and this snmp script:
https://www.domoticz.com/wiki/Presence_detection_(SNMP)
I use this with iso.3.6.1.2.1.4.22.1.2.7 and don't have the device status update problem Surroot had. I have an Asus RT-AC66U.
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
BaliBiker
Posts: 11
Joined: Saturday 30 January 2016 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by BaliBiker »

I still got no luck in presence detection while my phone is connected to the AP. The suggestion of Mooseknuckle didn't do the trick.
I still think if I'am adding the driver adapter for the wired connection (instead of eth0/eth1) to the script it should work.
Does anyone know the correct adaptor name for this? Or any other suggestion to get this working :)
Racierox
Posts: 6
Joined: Sunday 19 February 2017 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by Racierox »

Thanks for this guide, I got it working, sort of....

The switch for my phone turns on automatically after a while.
When i disconnect from wifi it stays connected however.
It seems it doesn't update regularly, is there a way to check this and a way to change this?

My wife's phone also connected automatically, but disconnected after a while when the phone was still in the network.
Edit: after she unlocked her phone and used the wifi it connected again.
Is there a solution to keep it connected in sleep mode?

Can somebody help me? Do I need to post some log or something?
We both have iPhones and I have an Asus RT-AC68U router flashed with the latest version of Merlin and the latest Domoticz beta.
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Yet another presence detection method

Post by PeGe »

Racierox wrote:Thanks for this guide, I got it working, sort of....

The switch for my phone turns on automatically after a while.
When i disconnect from wifi it stays connected however.
It seems it doesn't update regularly, is there a way to check this and a way to change this?

My wife's phone also connected automatically, but disconnected after a while when the phone was still in the network.
Edit: after she unlocked her phone and used the wifi it connected again.
Is there a solution to keep it connected in sleep mode?

Can somebody help me? Do I need to post some log or something?
We both have iPhones and I have an Asus RT-AC68U router flashed with the latest version of Merlin and the latest Domoticz beta.
No matter what solution you try to implement, don't ever expect your iPhone to constantly "stay awake". It simply won't, unless you have it plugged into a charger at all times.

The decision to put the interface to sleep after a pre-defined time, is sadly not yours. Apple has already made the decision for you!

This dirty trick they implemented several years ago, for sure causes less battery drain. Which is obviously something highly desirable from a product marketing perspective, so I wouldn't expect it to ever change.

Over the years, there have been a few workarounds published on the net, to force the iPhone to stay awake. One such method was to configure it to always use a "dummy" VPN. But as soon as that little trick was published, that back door was also nailed shut in the next update...

/P-G
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by Mooseknuckle »

Maybe this is a nice alternative solution?
https://www.domoticz.com/wiki/Presence_ ... gy_Beacon)
I just ordered a beacon to give it a try.
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Racierox
Posts: 6
Joined: Sunday 19 February 2017 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by Racierox »

Thanks for the replies. This is unfortunately not the solution for me then.
I'll look into the Bluetooth Beacon, looks promising!
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post by Surroot »

PeGe wrote: No matter what solution you try to implement, don't ever expect your iPhone to constantly "stay awake". It simply won't, unless you have it plugged into a charger at all times.

The decision to put the interface to sleep after a pre-defined time, is sadly not yours. Apple has already made the decision for you!

This dirty trick they implemented several years ago, for sure causes less battery drain. Which is obviously something highly desirable from a product marketing perspective, so I wouldn't expect it to ever change.

Over the years, there have been a few workarounds published on the net, to force the iPhone to stay awake. One such method was to configure it to always use a "dummy" VPN. But as soon as that little trick was published, that back door was also nailed shut in the next update...

/P-G
Hey there!
Yes the wifi goes into sleep mode, but is still detectable by this method. This method works for me for over a month without problems! My girlfriends (Android) and my phone (iPhone) are detected when we arrive at home and stay "detected" until we leave. So that this method does not work is simply not true.
Maybe some other users, who already implemented it, could give feedback?
Best regards,
Surroot
mayyam
Posts: 47
Joined: Saturday 14 January 2017 11:29
Target OS: Linux
Domoticz version: 4.11333
Location: Poland
Contact:

Re: Yet another presence detection method

Post by mayyam »

Two androids (marshmallow, and lolipop) are working great for me.

____
may
_______________
- Dell FX-160 / Ubuntu 16.04
- RFLink 433Mhz / NRF 2.4GHz
- 2x Xiaomi Gateway
- different species of ESP8266
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: Yet another presence detection method

Post by PeGe »

mayyam wrote:Two androids (marshmallow, and lolipop) are working great for me.
But of course they do! - Neither Androids nor Windows(Nokia) phones will put the wifi interface to sleep. I was discussing iPhones specifically.
Surroot wrote:... So that this method does not work is simply not true...
OK, but I actually didn't criticize your method. What I did criticize was Apple, for once introducing the non-configurable "go-to-sleep" feature, that was forced upon the users. If you have really found some strange way to detect a sleeping wifi interface, all I can do is congratulate you!

What I stated was: "don't ever expect your iPhone to constantly 'stay awake'. It simply won't, unless you have it plugged into a charger at all times."

Well, there is obviously one more exception: Keep some app constantly running on your iPhone, and the wifi interface will of course stay active and awake. But if you have nothing running in the background, just letting the iPhone silently go to rest, the wifi interface WILL definitely go to sleep after a short time. At least, that part seems like something we can agree on.

And honestly, from a purely technical perspective, if the router still "sees" a device with a sleeping interface, I would actually have to consider that being a router bug. Although a very beneficial bug that would clearly be useful in this case! - Still; I wouldn't place my bets on some bug that might be "fixed" in the near future... :(

/P-G
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post by Surroot »

Hey!
PeGe wrote:OK, but I actually didn't criticize your method.
I'm sorry, I didn't want to sound that rude... :?
PeGe wrote:What I did criticize was Apple, for once introducing the non-configurable "go-to-sleep" feature, that was forced upon the users.
Well, I never had the problem, that my iPhone went to sleep when it's screen was off. I researched a bit on google and found some threads of people who tell, that they also have this problem.
I'm interested in this wifi stuff and therefore investigated a little further:
I turned off "Background app refresh" and turned on "Wifi-Assist" in settings and monitored the state of the iPhone-wifi on the router with this command for about 30 minutes:

Code: Select all

while true; do wl -i eth1 sta_info AA:BB:CC:DD:EE:FF; sleep 1; done;
The phone definitely went into sleep mode, but it did not disconnect from the router (at least as far as I can see from the constant logging on the router).
Here you can see a picture with the interesting parts marked:
WifiLog.jpg
WifiLog.jpg (72.33 KiB) Viewed 5450 times
- The first thing the picture shows is the current idle time, which I think is the time no packet has been transmitted to or from the phone. When it reached 59 seconds it reset to 0.
- The second thing marked is "PS" in the "flags" line. It states, that the radio of the iPhone is in "Power Safe" mode at the moment. I googled again and stumbled across these power safe mechanism descriptions from the IEEE 802.11-standard.
tl;dr you can look them up here, here or here.
The standard power safe mode PSM seems to use so called beacons, which is like a heartbeat signal transmitted every few 100ms. The device turns the radio off and checks every few beacons if there are new packets waiting for it.
I even found the settings for these beacons in my ASUS RT-AC68U in Wireless->Professional.
RouterSettings.jpg
RouterSettings.jpg (101.9 KiB) Viewed 5450 times
Racierox wrote:Thanks for the replies. This is unfortunately not the solution for me then.
I'll look into the Bluetooth Beacon, looks promising!
Racierox: Maybe you should have a look in those settings and compare with the picture, maybe it's different on your router.

- The third thing is the RX and TX-rate of the last packet. TX even dropped to 1Mbps after a few seconds/minutes.

I use the latest iOS 10.3 beta.
It would be interesting if the problem is related to iOS devices or misconfigured/buggy routers, as I also read in one of the links above. Maybe it is also related to Wifi-sync, iCloud, Find my iPhone, etc. settings from iPhone (things which could prevent the phone from disconnecting from the router). Even if I have disabled background app refresh, maybe these are things which cannot be disabled to transmit their data in the background.
Maybe someone else with an iOS device has this set up already?

Best regards,
Surroot
RogerFart
Posts: 2
Joined: Saturday 18 March 2017 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by RogerFart »

Hi. I am new to Domoticz and I have got stuck. I think I´ve tried "everything" but I always get the message:


admin@RT-AC66U-9A08:/jffs/scripts# ./presence_detection 34:A3:95:7B:1D:84 127
[: Off: unknown operand

This is my "presence_detection". What is wrong?

#!/bin/sh

mac=$1
idx=$2
device_present=Off
domoticz_status=`curl -s "http://192.168.0.213:8080/json.htm?type ... s&rid=$idx" | grep Status | awk '{print $3}' | sed 's/[",]//g'`

# look in 2.4GHz (eth1) network for device
for x in `wl -i eth1 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done

# look in 5GHz (eth2) network for device
for x in `wl -i eth2 assoclist | awk '{print $2}'`; do
if [ $x = $mac ]; then
device_present=On
fi
done

# tell domoticz the new device status
if [ $domoticz_status != $device_present ]; then
if [ $device_present = "On" ]; then
curl -s "http://192.168.0.213:8080/json.htm? type=command&param=switchlight&idx=$idx&switchcmd=On" > /dev/null
else
curl -s "http://192.168.0.213:8080/json.htm? type=command&param=switchlight&idx=$idx&switchcmd=Off" > /dev/null
fi
fi
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Yet another presence detection method

Post by Calzor Suzay »

My wife and I both use iPhones and have (touch wood) never had a problem with it sleeping and dropping off the network.
Maybe we use them too often but I doubt it. :D
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post by Surroot »

RogerFart wrote:Hi. I am new to Domoticz and I have got stuck. I think I´ve tried "everything" but I always get the message:


admin@RT-AC66U-9A08:/jffs/scripts# ./presence_detection 34:A3:95:7B:1D:84 127
[: Off: unknown operand

This is my "presence_detection". What is wrong?
Hey!

I'm sorry, I can't find an error in your script...
You can only try recreating it.

Best regards!
RogerFart
Posts: 2
Joined: Saturday 18 March 2017 14:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Yet another presence detection method

Post by RogerFart »

Hi Surroot and thanks for the reply.
I´ve receated it so many times and it doesn´t help.
Do you know where the "Off" comes from.
Regards
User avatar
lemassykoi
Posts: 15
Joined: Saturday 11 March 2017 23:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: France
Contact:

Re: Yet another presence detection method

Post by lemassykoi »

The "Off" comes from the switchcmd which is not recognized because of your idx variable.
I had to play with quotes to get it to work : (both methods are ok for me)

Code: Select all

 if [ $device_present = "On" ]; then
        urlOn="http://192.168.2.31:8080/json.htm?type=command&param=switchlight&idx="$idx"&switchcmd=On"
#        echo "URL On : "$urlOn
        /tmp/home/root/curl -s $urlOn
 else
        /tmp/home/root/curl -s "http://192.168.2.31:8080/json.htm?type=command&param=switchlight&idx="$idx"&switchcmd=Off" > /dev/null
 fi
fi

My router is Linksys E2500, with Tomato Shibby 1.28, I had to download http://files.lancethepants.com/Binaries ... .40.0/curl
Fleshi
Posts: 14
Joined: Tuesday 23 May 2017 21:18
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Yet another presence detection method

Post by Fleshi »

I am a little bit of a noob with Linux.

I installed dd wrt on my router but when I try to install this script my router keeps forgetting the jffs folder. Does anybody have this script working on a dd wrt router?
User avatar
Surroot
Posts: 31
Joined: Wednesday 18 January 2017 11:28
Target OS: Linux
Domoticz version: beta
Location: Vienna
Contact:

Re: Yet another presence detection method

Post by Surroot »

Fleshi wrote:I am a little bit of a noob with Linux.

I installed dd wrt on my router but when I try to install this script my router keeps forgetting the jffs folder. Does anybody have this script working on a dd wrt router?
Hey there!

Maybe this page has an answer for you. Especially the "Directions for (normal) users: using Web-GUI Interface"-chapter.

Best regards
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Yet another presence detection method

Post by R0yk3 »

Thank you! This works great for me fight out of the box. R7000 with Merlin.
Only itch was the copy paste into nano, and the break it created.

Verstuurd vanaf mijn SM-G955F met Tapatalk
Raspberry PI 3, raspbian, ZwaveMe, RFLink
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest