Hi!
For the last 2 days I’ve been experimenting with reliable network detection for our iphones using arping. This thread documents my findings and will result in some pull requests and/or requests for @David_Graeff probably :-). It’s not easy to just open an issue for this, I think it needs some discussion. I found a way changing the code that should make arping 100% reliable, using arping as follows:
arping -I eth0 -C 1 -c 100 -W 0.1 192.168.1.60
This will basically spam the IP for arp requests and immediately exits when the iphone responds, or exits with exit code 1 after 10 seconds. When my iphone is in deep sleep, this reliably works 100% of the time.
OK great, on to changing the actual binding code. Note that I’m running everything in Docker. The first thing I found was that ping isn’t installed in the Openhab container. I’ll make a PR afterwards to get this added, as I found absolutely no issues to work with ping. The second thing I found was that auto-discovery for the network binding doesn’t work. Looking at the code, this doesn’t even seem Docker related. Looking inside the class NetworkDiscoveryService in the startScan method, there is
final ExecutorService service = executorService;
if (service == null) {
return;
}
...
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
This code never allows service to become non-null, so “startScan” would never work. Simply flipping the statement into
service != null
makes auto-discovery suddenly work perfectly, also inside my docker container.
Next up, changing the arping call. As inside the Docker container ARPing 2.14 is installed, the binding uses the following arping cmd:
arping -c 1 -i interfaceName ip
So I changed that to
arping -c 100 -C 1 -W 0.1 -i interfaceName ip
Then, performed a mvn clean install, uninstalled the existing binding from my setup, pasted the .jar in the /addons folder, this works perfect. For a while…
Thanks to my additional logging, I suddenly see a lot of InterruptedException logs from performARPping. Thinking this was due to my change, I reverted everything but only added a logging statement in the catch (InterruptedException e) statement. This also shows that the normal implementation is constantly throwing InterruptedExceptions.
Let’s try to beat this thing together, we could have perfect presence detection and the forum would be less bloated with arping configuration issues. Why is ProcessBuilder.waitFor() throwing these exceptions?. I don’t have enough OpenHAB knowledge to reason about the threading constraints or when threads in specific bundles are interrupted.
It would be great if others could confirm their network binding is also throwing these InterruptedExceptions. I made a new network binding jar that is exactly the same as the normal 2.4.0 one, but with added error logging:
https://drive.google.com/open?id=1lcZd-E3rAoBrVeQjQSCwpLl0XiHA_HWM
After placing this .jar in your /addons folder, and you start seeing things like
it confirms that there’s currently a threading issue with this binding, also preventing my fix for reliable arping