Network Binding

I am very new to Openhab so I started out with Openhab2. I am trying to detect presence using the network binding to detect android phones coming on and off the wifi network. I looked at the github binding page Openhab2 Network binding and see that the channels are set up with the individual devices IP address thus:
network:device:devicename [ hostname=“192.168.0.64”, port=“0”, retry=“1”, timeout=“5000”, refresh_interval=“60000”, use_system_ping=“false”, dhcplisten=“true” ]
network:device:devicename [ hostname=“192.168.0.21”, port=“0”, retry=“1”, timeout=“5000”, refresh_interval=“60000”, use_system_ping=“false”, dhcplisten=“true” ]

What I am confused about is how in the items file if I use:
Switch MyDevice { channel=“network:device:devicename:online” }
Switch MySecondDevice { channel=“network:device:devicename:online” }

How does this device know which channel to use, will it use the one for IP 192.168.0.64 or the channel for IP 192.168.0.21 ?
What am I missing in the configuration?
Should the devicename be set somewhere?

I can say that the presence works but I am not sure how each of the switches would know which channel to use.

Any/all help is welcome.

First you need to define things for all network devices (phones) that you want to monitor, using unique device names (the example of using “devicename” is just that; an example).

Something like this (for simplicity I removed the part within the brackets):

network:device:phone_1 [...]
network:device:phone_2 [...]

etc.

Then you create items mapping to the things, like this:

Switch Phone_1 { channel="network:device:phone_1:online" }
Switch Phone_2 { channel="network:device:phone_2:online" }

Obviously the item does not have to use the same name as the device name that you use for the thing, but I usually find this to be the simplest way of doing it.

OK, that makes sense. I will give it a go and see how it works. Thanks! - I will come back with the result.

I just tried it but now it’s not seeing the devices at all. I used the network:device:phone_1:online it just appears to be always offline now. I can ping the IP address from the machine and when I had it as network:device:devicname:online it was seeing it and switching offline when I removed the phone from the network. I will test further tonight but I am stumped at the moment.

I stopped everything and reset then tried this again, now it seems to be working, sort of.
I set one to an IP address that is not on my network and it kept popping in and out online, offline, online. Not sure why. When I ICMP ping it I get address unavailable. However, for the most part it seems to be working now. - Thanks for the help.

In case anyone is interested I added the switches to my sitemap simply by adding a line
Switch item=Phone_1
Switch item=Phone_2

Hello!
When starting OpenHAB2 in the log began to appear such events:

2016-12-27 08:32:27.435 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.io.monitor.internal.EventLogger@34afbb90’ takes more than 5000ms.
2016-12-27 08:32:27.435 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.core.thing.link.ThingLinkManager@16107f29’ takes more than 5000ms.
2016-12-27 08:32:27.436 [WARN ] [ome.core.thing.internal.ThingManager] - Initializing handler for thing ‘network:device:ip_10_2_63_10’ takes more than 5000ms.
2016-12-27 08:32:27.436 [WARN ] [ome.core.thing.internal.ThingManager] - Registering a handler for thing ‘network:device:ip_192_168_0_13’ takes more than 5000ms.
2016-12-27 08:32:32.436 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.io.rest.sse.internal.listeners.SseEventSubscriber@3f0c38c9’ takes more than 5000ms.
2016-12-27 08:32:32.436 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.io.monitor.internal.EventLogger@34afbb90’ takes more than 5000ms.
2016-12-27 08:32:32.437 [WARN ] [ome.core.thing.internal.ThingManager] - Registering a handler for thing ‘network:device:ip_192_168_213_15’ takes more than 5000ms.
2016-12-27 08:32:42.372 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.core.thing.link.ThingLinkManager@16107f29’ takes more than 5000ms.
2016-12-27 08:32:42.386 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber ‘org.eclipse.smarthome.core.thing.link.ThingLinkManager@16107f29’ takes more than 5000ms.

This is normal? Previously, this was not.
Tanks!