Presence arrival using DHCPlisten possible?

It’s Android so my first approach would be to set up Tasker to turn ON/OFF an OH Item through the OH REST API when Tasker sees the home wifi.

I do not know if it is possible to completely turn off the ping behavior of the Network binding.

That being said, I agree with Garry. The whole point of arping is to detect the phone even when it has gone to sleep. I use an old hping3 script upon which the arping capability in the binding is based and it detects all our phones reliably enough that I’ve turned off all the BT detection stuff and just depend on that.

1 Like

If you’ve not got arp working, I’d certainly try that first. Been rock solid and 100% accurate for me once I set this up.

I’m running OH on Ubuntu, and I needed to get arping working outside of OH first, then it worked perfectly from within OH.

Here’s a screenshot from Grafana of my presence over the last 14 days.

Can you guess when I got arping working right??

@rlkoshak - ah, I hadn’t given a thought to pushing from the phone rather than looking for it. I’d rather not have to install anything on the phones involved, but this does look like it would solve the problem nicely. Thanks for the idea and link

@rlkoshak @Confused - I thought the hping3 thread was iOS specific so will re-read that and also look more closely at how arp actually works. Pretty clear that if you get it set up right, it does seem to work based on that graphic!

Thanks for the info guys.

ARP stands for Address Resolution Protocol. When a device on the network wants to connect to another device on the network that it hasn’t connected to very recently it sends out a “Who has IP address 192.168.1.123?” request. This goes out to everyone and if necessary the router forwards the request to its router. The device who has that IP address, or if the router knows that a specific device has that address, it responds with “MAC address blah blah blah has address 192.168.1.123.”

What the hping3/arp and Network binding does is first send a specially crafted packet to the phone that causes it to partially wake up, and then it sends an arp “Who has” message and because of that first packet, the phone responds with “I have blah blah blah” and you know the phone is on your network. I’m pretty certain that specially crafted packet is a standard thing (like the WOL packets) which is why it works across iOS and Android.

But I have to say, it has been quite awhile since the last time I studied this stuff in depth. I may have said something wrong.

1 Like

As an update/info for anyone coming across this thread later:

I now have stable presence detection of android devices running Nougat 7.1.1, and LineageOS 14, and Apple devices on iOS 10.3.3 using the network binding. As pointed out by @rlkoshak and @Confused, arp just needs to be correctly configured.

Setup is on a Rpi3 using the openhab(2.2) image.
The installed arping tool did not wake the 7.1.1 or iOS devices, but did wake the LineageOS. The iputils-arping tool woke one of the 7.1.1 but not the other or the iOS device. This was based on ping and arping tests from the command line.

Updated the arping tool to v2.19-3 (was 2.14) - tested again, and all devices responded to arping after going into sleep mode, despite not responding to ping (as expected).

For network binding to work:
Added sudo nopasswd permissions using “su visudo” then "chmod u+s /usr/sbin/arping"
On the network things, increased retry value to 10, and timeout value to 20000.

Tested overnight and all devices stayed active for 12+hours. Based on the logs, it looks like the 7.1.1 devices can stop responding for 4-6 mins so a retry value of 10 looks reasonable.

Thanks for the pushing me in the right direction guys,much better solution.

7 Likes

Does anybody use the network binding successfully under Windows? Unfortunately there seems to be no recent arping implementation for windows and the current version of the network binding under Windows produces only wild fantasy states in OH (devices online which are not online for 2 days, devices offline which run 24 hours and so on).
My impression is that the network binding is at the moment useless in a Windows environment. Or has anybody better news and useful hints for me?

Updated the arping tool to v2.19-3 (was 2.14) – warcom

It sounds simple, but it took me a while to figure out how to do this. The thing is, the current stable version of openhabian (raspbian) has arping 2.14, and there is no simle way to upgrade to a newer version. So, for those who want to install arping v2.19-3, here’s how to do that:

  1. The *.deb package can be found at the Launchpad website. If you’re on a Raspberry Pi (like me), you’ll need the armhf build of the package. Download it to your Raspberry Pi like this:
    wget https://launchpad.net/ubuntu/+source/arping/2.19-3/+build/13766203/+files/arping_2.19-3_armhf.deb
    
  2. Once downloaded, the package can be installed as follows:
    sudo dpkg -i arping_2.19-3_armhf.deb
    
  3. That’s it, you can verify the version of arping by executing
    arping -v
    
    The output will be something like:
    ARPing 2.19, by Thomas Habets <thomas@habets.se>
    usage: arping [ -0aAbdDeFpPqrRuUv ] [ -w <sec> ] [ -W <sec> ] [ -S <host/ip> ]
              [ -T <host/ip ] [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]
              [ -C <count> ] [ -i <interface> ] [ -m <type> ] [ -g <group> ]
              [ -V <vlan> ] [ -Q <priority> ] <host/ip/MAC | -B>
    For complete usage info, use --help or check the manpage.
    

Goog luck!

4 Likes

Exactly my issue right now… Did you (or anybody) solve the Network Binding issue for Windows? I’m running OH on Win 10.

Hello, I have the same problem with my presence detection in openhab and tried the above steps to install the arping package. But I got an error while trying to install. Being a total noob in linux :blush: I don’t know how to proceed. Is it safe to uninstall the conflicting package? Don’t know how but i can google how to uninstall.

This is the output from the terminal:

[11:22:31] openhabian@openHABianPi:/sbin$ sudo dpkg -i arping_2.19-3_armhf.deb
Selecting previously unselected package arping.
dpkg: regarding arping_2.19-3_armhf.deb containing arping:
 arping conflicts with iputils-arping
  iputils-arping (version 3:20161105-1) is present and installed.

dpkg: error processing archive arping_2.19-3_armhf.deb (--install):
 conflicting packages - not installing arping
Errors were encountered while processing:
 arping_2.19-3_armhf.deb
[11:22:43] openhabian@openHABianPi:/sbin$

I would really like to get this presence detection working, kinda is essencial in any home automation :sweat_smile:

EDIT:
Got it installed, I just went for it and removed the conflicting package. Then followed the rest of the steps. Now my onePlus stays online as long as i’m at home. :star_struck: But for some reason my wife’s samsung galaxy S5 doesn’t. Any ideas why?

EDIT: and just as i hit save edit my phone goes offline again :disappointed:

Modern phones will go to sleep and don’t even respond to arp pings for a few minutes. You need a bigger timeout window on your Things (like 5 mins or so). Or use a dedicated device, like a BLE enabled one.

The network binding is not the best presence detection anymore nowadays I guess.

Hy David,

Thanks i will try that.

Can you suggest a better strategy for presence detection? I plan to use motiondetectors based on “mysensors” that report to openhab via the serial binding, but I still have to develop these.

Either a BLE device, motion sensors or camera object/person recognition with openCV

Guess i better get working on those motion detectors
:wink:

@jimmyalias if you have SNMP support on your network equipment it is possible to query the SNMP for network connectivity of your phone.

I have older Cisco equipment my work was going to throw out, but it should work for any SNMP network device it is just a matter of hitting the correct OID.

Wow, thats chinese to me. :laughing:

I will have to do a whole lot of reading and get back to you, but thanks for the suggestion

iPhone Presence Detection with hping3 and ARP might work for you. It uses a special ping to wake up the phone and cause it to respond with an arp.

I was under the impression that arping in the Network binding does the same but perhaps not. I use something like this and it has worked with iPhones, Pixel 2 XL and Pixel 3 XL.

Does it allso work with android phones? :thinking:

it has worked with iPhones, Pixel 2 XL and Pixel 3 XL.

Ok thanks, I will take a look at it tomorrow, its been a long day of programming and trying things out :sleepy: