Page 3 of 7

Re: Yet another presence detection method

Posted: Wednesday 15 February 2017 1:39
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

Re: Yet another presence detection method

Posted: Wednesday 15 February 2017 9:57
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'?

Re: Yet another presence detection method

Posted: Wednesday 15 February 2017 14:19
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.

Re: Yet another presence detection method

Posted: Wednesday 15 February 2017 22:29
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 :)

Re: Yet another presence detection method

Posted: Sunday 19 February 2017 19:41
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.

Re: Yet another presence detection method

Posted: Monday 20 February 2017 13:40
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

Re: Yet another presence detection method

Posted: Monday 20 February 2017 14:05
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.

Re: Yet another presence detection method

Posted: Monday 20 February 2017 15:16
by Racierox
Thanks for the replies. This is unfortunately not the solution for me then.
I'll look into the Bluetooth Beacon, looks promising!

Re: Yet another presence detection method

Posted: Tuesday 21 February 2017 17:54
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

Re: Yet another presence detection method

Posted: Tuesday 21 February 2017 19:10
by mayyam
Two androids (marshmallow, and lolipop) are working great for me.

____
may

Re: Yet another presence detection method

Posted: Tuesday 21 February 2017 20:46
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

Re: Yet another presence detection method

Posted: Wednesday 22 February 2017 20:23
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 5668 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 5668 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

Re: Yet another presence detection method

Posted: Saturday 18 March 2017 15:13
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

Re: Yet another presence detection method

Posted: Saturday 18 March 2017 21:54
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

Re: Yet another presence detection method

Posted: Sunday 19 March 2017 8:20
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!

Re: Yet another presence detection method

Posted: Sunday 19 March 2017 9:03
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

Re: Yet another presence detection method

Posted: Sunday 19 March 2017 20:56
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

Re: Yet another presence detection method

Posted: Friday 16 June 2017 22:23
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?

Re: Yet another presence detection method

Posted: Tuesday 20 June 2017 14:17
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

Re: Yet another presence detection method

Posted: Thursday 22 June 2017 7:31
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