Logic Machine Forum
iPhone presence detection - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: iPhone presence detection (/showthread.php?tid=379)

Pages: 1 2


iPhone presence detection - npinguin - 25.08.2016

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


RE: iPhone presence detection - edgars - 26.08.2016

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)



RE: iPhone presence detection - admin - 29.08.2016

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 Smile

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.


RE: iPhone presence detection - npinguin - 29.08.2016

Perfect, that is the solution I was looking for.

Thanks a lot


RE: iPhone presence detection - managementboy - 01.09.2016

superb! created a user library with the function and a resident for the few IPs I need to check.


RE: iPhone presence detection - Erwin van der Zwart - 02.09.2016

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


RE: iPhone presence detection - rocfusion - 04.09.2016

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


RE: iPhone presence detection - admin - 05.09.2016

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 Smile


RE: iPhone presence detection - andrepneves@gmail.com - 13.09.2017

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


RE: iPhone presence detection - DGrandes - 05.07.2018

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)



RE: iPhone presence detection - adiaz - 09.07.2018

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!


RE: iPhone presence detection - admin - 09.07.2018

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.


RE: iPhone presence detection - Daniel - 09.07.2018

Here is example with Microtik router
https://forum.logicmachine.net/showthread.php?tid=836&pid=7657#pid7657


RE: iPhone presence detection - DGrandes - 11.07.2018

I´ve seen microtic example but I don´t know how to do that with my livebox fibra...


RE: iPhone presence detection - DGrandes - 07.08.2018

(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?


RE: iPhone presence detection - Daniel - 07.08.2018

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


RE: iPhone presence detection - DGrandes - 07.08.2018

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..


RE: iPhone presence detection - Daniel - 07.08.2018

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.


RE: iPhone presence detection - DGrandes - 07.08.2018

(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?


RE: iPhone presence detection - Daniel - 07.08.2018

Beacon Simulator or something like that. I just tried it and uninstalled afterwords.