I have extended the network binding to be able to use arping. Additionally I send an empty packet to udp port 5353, as suggested here in this thread. I do not own an iPhone though, so cannot test if it actually works. The device presence detection for my android 6 phone works now, thanks to arping.
I need to know which parameters need to be configurable as apparently different parameters worked for different phones. At the moment it works like this:
Repeat the following every REFRESH_TIME in ms (default 60000):
Increase attempt by one
Send one empty packet to port 5353
Wait 50ms
Perform some arp pings with ARPING, but don’t wait longer than TIMEOUT in total
A device is deemed offline if attempt >= MAX_ATTEMPTS.
All uppercase parameters are configurable.
Is there a reason why the preferred solution here is to flush the arp table + use arp later instead of using the arping tool?
@David_Graeff I’m really looking forward to the arping patch landing, is there an ETA? This would help dramatically with cross platform (i.e. Mac) support
The test suite does not run with the maven configuration on the test server (travis) and stalled the whole merge. Someone with maven knowledge need to have a look. The binding is working though, but I do not have time to manually generate jar files.
The ETA is: As soon as someone else than me understood the maven problem, the binding will be merged. Might be tomorrow or next year
I’ve added the intValue and that did take care of the error in Eclipse.
However, I think I may have a permissions issue because I’m now seeing the errors/warning below in FrontTail:
2017-08-28 21:05:00.146 [WARN ] [lipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "/etc/openhab2/scripts/iphone.sh" (in directory "."): error=2, No such file or directory)
2017-08-28 21:05:00.153 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Find My iPhone: The argument 'state' must not be null or empty.
and this one too
2017-08-28 21:28:05.771 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'iphone.sh' has errors, therefore ignoring it: [1,1]: missing EOF at '#'
I checked the directory listed above via Putty and the iphone.sh file is there.
I copied the code from the comments above, but here is what I have in my iphone.sh file:
#!/bin/bash
# v1.1 2017-04-11: VARIATION WITH LOGGING INCLUDED
# detect iphone by IP and MAC address.
# use MAC address too, to prevent false positives if IP might change
# return ON or OFF so output can be directly bound to a switch item
# number of retries, less is faster, but less accurate
MAXRETRIES=20
# path to log file - to use logging, uncomment all lines containing 'echo >> logfile'
LOGFILE=/etc/openhab2/scripts/iphone.log
# exit immediately if no parameters supplied
if [ $# -lt 2 ]
then
# echo `date '+%F %T'` - Required parameters not specified >> ${LOGFILE}
echo "UNDEF"
exit 1
fi
# Set variables
IP=$1
MAC=$2
# echo `date '+%F %T'` - Script started for ${IP} and ${MAC} >> ${LOGFILE}
COUNT=0
while [ ${COUNT} -lt ${MAXRETRIES} ];
do
# echo `date '+%F %T'` - Try ${COUNT} >> ${LOGFILE}
# Change dev and eth0 if needed
sudo ip neigh flush dev eth0 ${IP}
sudo hping3 -q -2 -c 10 -p 5353 -i u1 ${IP} >/dev/null 2>&1
sleep .1
# Only arp specific device, grep for a mac-address
STATUS=`arp -an ${IP} | awk '{print $4}' | grep "${MAC}"`
if [ ${#STATUS} -eq 17 ]; then
# exit when phone is detected
# echo `date '+%F %T'` - Phone detected >> ${LOGFILE}
echo "ON"
exit 0
fi
let COUNT=COUNT+1
sleep .1
done
# consider away if reached max retries
# echo `date '+%F %T'` - Phone not detected >> ${LOGFILE}
echo "OFF"
The /etc/openhab2/scripts folder is intended for openHAB scripts, not shell scripts that one would execute with the exec binding. When OH starts up it changes the permissions on all the files in /etc/openhab2 and strips off the execute permissions.
Move this file somewhere else (e.g. /var/lib/openhab2/scripts which is equivalent to ~openhab I believe) and make sure it has exec permissions.
Does one need to run OH as root for the arping to work? If not do you have any idea whether this might work with OH running in Docker? I’ve never been able to get the dhcplisten to work from Docker so am not hopeful.
The binary arping needs to be installed as explained in the snapshot readme. The executable needs suid permission to be usable for OH.
Dhcplisten always starts now. But without the setcap permissions it runs on port 6767 and needs port forwarding.
Just to be clear, you moved the file, and made sure it has read and execute permissions for the openhab user. And you updated the path in your rule that calls the script. After all that it gives the same error?
rule "Find My iPhone"
when
Time cron "0 */5 * * * ? *" // every 5 minutes
then
val Number timeout = 10*1000 // give the script some time to finish, to capture the result
// replace 0.0.0.0 with your ip address
// replace 00:00:00:00:00:00 with your mac address
var String result1 = executeCommandLine('/var/lib/openhab2/scripts/iphone.sh@@<192.168.2.117@@B8:53:AC:8D:33:33', timeout.intValue)
var String result2 = executeCommandLine('/var/lib/openhab2/scripts/iphone.sh@@192.168.2.132@@4C:74:BF:68:7B:A1', timeout.intValue)
Venice.postUpdate(result1)
Peggy.postUpdate(result2)
end