Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Hi
I am looking for an iPhone presence detection solution.
I found many iPhone detection bash scripts like this one
Code: script (/opt/openhab/iphonedetect.sh)
#!/bin/bash
MAC=${2//-/:}
declare -a DEVICES
hping3 -2 -c 10 -p 5353 -i u1 $1 -q >/dev/null 2>&1
DEVICES=arp -an | awk '{print $4}'
CHECK=$MAC
if [[ ${DEVICES[*]} =~ $CHECK ]]
then
echo "ON"
else
echo "OFF"
fi
[*]
But nothing in lua.
Did anyone over here already implemented a script and wants to share this?
Thanks
Nicky
Posts: 429
Threads: 100
Joined: Jun 2015
Reputation:
45
Here is Bluetooth device presence script which changes value of respective grp addresses based on Bluetooth device appearance.
Code: require('ble')
-- enable ble
ble.up()
list = {}
-- mac -> group address mapping
known = {
['88:0F:10:10:F2:8A'] = '1/1/1',
['88:0F:10:4A:2C:36'] = '1/1/2',
}
ctime = os.time()
function callback(addr)
local now, delta
now = os.time()
delta = now - ctime
if addr then
if not list[ addr ] then
log('BLE found ' .. addr)
if known[ addr ] then
grp.write(known[ addr ], true, dt.bool)
end
end
list[ addr ] = now
end
-- check for missing devices each 5 seconds
if delta < 0 or delta > 5 then
for addr, time in pairs(list) do
delta = now - time
if delta < 0 or delta > 60 then
log('BLE missing ' .. addr)
list[ addr ] = nil
if known[ addr ] then
grp.write(known[ addr ], false, dt.bool)
end
end
end
ctime = now
end
end
ble.scan(callback)
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
That shell solution assumes that your iOS device has a fixed IP, you can do in Lua like this. I cannot guarantee that this code will work, you have to try and debug it yourself
Code: function checkiosdev(ip)
local sock, res
sock = require('socket').udp()
for i = 1, 10 do
sock:sendto('123', ip, 5353)
os.sleep(1)
end
res = os.execute('ping -c 2 -W 10 ' .. ip)
return res == 0
end
seen = checkiosdev('192.168.1.10')
grp.update('1/1/1', seen)
When phone/tablet is locked (in sleep state) sending UDP packets to port 5353 causes it to wake for a short period. During that period device can be pinged to check if it's in the network or not.
Posts: 87
Threads: 13
Joined: Oct 2015
Reputation:
6
Perfect, that is the solution I was looking for.
Thanks a lot
Posts: 82
Threads: 29
Joined: Jul 2015
Reputation:
2
superb! created a user library with the function and a resident for the few IPs I need to check.
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi Admin,
I tested this script, created a log on the output and i see that there is a lot of toggle (on/off) even when the phone is all the time in the network.
Could it be that the wake-up methode by udp is not stable? You send it 10 times now for a special reason?
BR,
Erwin
Posts: 200
Threads: 60
Joined: Jun 2015
Reputation:
7
Hi,
i found a useful app, https://packetsender.com/download, used this to send to port 5353. Then I had used a command prompt with ping -t to my iphone. I noticed that if you try to send multiple times the iphone would not respond to the ping.
Thanks,
Roger
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Well, I don't have a device to test this script so any corrections are welcome. Another approach is to get DHCP client list from a router, then you don't have to set static IP and there's no need for UDP quirks
Posts: 41
Threads: 13
Joined: Dec 2016
Reputation:
0
Hi,
I tried the Bluetooth device presence script but I have some problems.
- I can only find BLE devices (watches and bands). I'd like to use it to detect smartphones (Android/Iphone).
- The grp.write function doesn't work. I'm having trouble debugging this. I tried putting log('debug') in many places and never get results...
Thank you in advance,
André Neves
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
05.07.2018, 13:05
(This post was last modified: 05.07.2018, 13:24 by DGrandes.)
Hello,
I´ve tried this script but it doesn´t work if iphone is locked. When I unlock if work perfectly.
With android devices it works perfectly.
Any Idea?
Thanks
Code: function checkiosdev(ip)
local sock, res
sock = require('socket').udp()
for i = 1, 10 do
sock:sendto('123', ip, 5353)
os.sleep(1)
end
res = os.execute('ping -c 2 -W 10 ' .. ip)
return res == 0
end
seen = checkiosdev('192.168.1.10')
grp.update('1/1/1', seen)
Posts: 58
Threads: 17
Joined: May 2017
Reputation:
1
09.07.2018, 07:17
(This post was last modified: 09.07.2018, 07:17 by adiaz.)
Hi,
When iphone is locked the system turns off wifi. I think each 5min the system turns on wifi to search new inputs and then turns off again.
I was trying this. You can try it doing an infinite ping with cmd and lock/unlock the iphone. You will see!
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
There's no 100% correct way of doing this, the best approach is to get DHCP lease list from router and check if certain MAC is present or not.
Posts: 4660
Threads: 24
Joined: Aug 2017
Reputation:
212
------------------------------
Ctrl+F5
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
I´ve seen microtic example but I don´t know how to do that with my livebox fibra...
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
(26.08.2016, 06:14)edgars Wrote: Here is Bluetooth device presence script which changes value of respective grp addresses based on Bluetooth device appearance.
Code: require('ble')
-- enable ble
ble.up()
list = {}
-- mac -> group address mapping
known = {
['88:0F:10:10:F2:8A'] = '1/1/1',
['88:0F:10:4A:2C:36'] = '1/1/2',
}
ctime = os.time()
function callback(addr)
local now, delta
now = os.time()
delta = now - ctime
if addr then
if not list[ addr ] then
log('BLE found ' .. addr)
if known[ addr ] then
grp.write(known[ addr ], true, dt.bool)
end
end
list[ addr ] = now
end
-- check for missing devices each 5 seconds
if delta < 0 or delta > 5 then
for addr, time in pairs(list) do
delta = now - time
if delta < 0 or delta > 60 then
log('BLE missing ' .. addr)
list[ addr ] = nil
if known[ addr ] then
grp.write(known[ addr ], false, dt.bool)
end
end
end
ctime = now
end
end
ble.scan(callback)
Where should i put that code? In Common Functions or in Resident script?
This code is executed once or like resident script?
Posts: 4660
Threads: 24
Joined: Aug 2017
Reputation:
212
Hi
If you have BLE then just use general profile for presence. LM will see only broadcast messages but not every mobile is sending them.
If it does then you will see your device on the list. Works well with all the wearables.
BR
------------------------------
Ctrl+F5
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
I have a LM5 Power with Trust 18187 and I´ve done this tutorial:
http://openrb.com/lm-as-bluetooth-4-0-gateway/.
I've imported General Profile but Ble tab only discover 1 device. A TV but nothing with iphone ore android phones..
Posts: 4660
Threads: 24
Joined: Aug 2017
Reputation:
212
This is because smartphones usually do not send anything only want to receive. On android I found an app which can generate beacon and then it worked on LM. Probably you can find something like that for iPhone.
------------------------------
Ctrl+F5
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
(07.08.2018, 14:37)Daniel. Wrote: This is because smartphones usually do not send anything only want to receive. On android I found an app which can generate beacon and then it worked on LM. Probably you can find something like that for iPhone.
what is the application for android?
Posts: 4660
Threads: 24
Joined: Aug 2017
Reputation:
212
Beacon Simulator or something like that. I just tried it and uninstalled afterwords.
------------------------------
Ctrl+F5
|