Smartphone Radar - Smartphone presence detection (Locked)

Posted on
Tue Dec 13, 2011 12:55 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Smartphone Radar - Smartphone presence detection (Update

Sweet - that would make the plugin even more useful (lots of Airports out there).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 13, 2011 1:07 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Smartphone Radar - Smartphone presence detection (Update

travisc wrote:
@bluenoise

bluenoise wrote:
I just got this working (I think) under Lion, but I have some questions.

It created variables as described, but those variables don't seem to reflect what is really happening. Currently, for instance, my iPhone (of three being tracked) is home. In the device list, mine is "home" while the other two are "away." But, in the variable list, all three <iPhoneName>Home variables are "true." Additionally, until just a moment ago, AllPhonesAway was true, in spite of mine being known as "home" in the device list. Lastly, though it says all three phones are home (according to the variable list), AllPhonesHome is "false." Is there something I need to do to ensure those variables are updated properly?


I tested this today before I uploaded v1.0.0, I can't reproduce it. Are you sure "Create Variables" was still checked in the config? If you uncheck it the variables will not be deleted, but they won't be updated. If you see this popup again and can reproduce it let me know and I'll check it out.

Travis


Thank you, Travis. I will update to the latest and see how it goes. I've not unchecked the "Create Variables" checkbox, so I'm not sure what is happening. I will do a "clean install" of the plugin.

Posted on
Tue Dec 13, 2011 1:14 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Smartphone Radar - Smartphone presence detection (Update

BeNoOne wrote:
Oké, just came accross this thread en was very interested what solution was being used to detect an iPhone/iPad. I already used some proximity detection in the past, but this was via Bluetooth. Although this was working fine, the range was very limited. Also the application (Salling Clicker) I used doesn't support iOS devices.

So in my search for alternatives I wanted to use WiFi.
At the moment I'm using a very simple Python script to do just that. Only I do it the other way around. I'm pulling the info from my 2 Airports with a snmpwalk command.

In the past, pre iOS5, this resulted sometimes in false aways on my iPhone, but worked flawless on my iPad if I turned my 3G radio off. Now I have a new iPhone and iOS5, and as of yet haven't had a false away. And I'm not using any time filtering or other trickery to keep the connection alive. Also this method doesn't need any configuration of ports of some sorts. U only need to turn allow snmp on in your Airport.

I don't know if this helps to build a better plugin, but below U see a snippet of my code.

Code: Select all
"""
MAC adres iPhone  : 00:00:00:00:00:00 hex = 000.000.000.000.000 decimal
"""
import subprocess

myVar = indigo.variables[123]

def mySnmp(adr='Primair-eXtreme.local', pwd='######'):
   cmd = 'snmpwalk', '-m', 'AIRPORT-BASESTATION-3-MIB', '-Os', '-v', '2c', '-c',    '%s' % (pwd), '%s' % (adr), '1.3.6.1.4.1.63.501.3.2'
   try:
      p = subprocess.Popen(cmd, stdout= subprocess.PIPE, stderr= subprocess.STDOUT)
      return p.stdout.read()
   except:
      indigo.server.log("********Airport Down********")
      return 'something'

if '"00:00:00:00:00:00"' in mySnmp():
   indigo.variable.updateValue(myVar, "true")
elif '000.000.000.000.000.000' in mySnmp('AirPort-Express.local', '######'):
   indigo.variable.updateValue(myVar, "true")
else:
   indigo.variable.updateValue(myVar, "false")


I wanted to use subprocess.check_output(cmd), but Indigo uses an old version of Python.

Grts,


This looks very promising. Thank you very much for posting this!

I don't know Python, yet, but this appears to work for one iDevice. Can someone tweak this a bit to highlight the parts that need to be customized? For example, highlight the Airport name in purple with a note outside the code box saying, "Replace the purple text with the exact name of your Airport network," but do this with different colors for the various parts that are unique to each user.

Posted on
Tue Dec 13, 2011 2:26 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Smartphone Radar - Smartphone presence detection (Update

I posted the code so I will try to explain.
Please note: although this code is very basic it was not meant for end users. It was meant as an idea to simplify the configuration for Airport users in the "Smartphone Radar" plugin. If U are looking for multiple users I'm afraid U have to turn to travisc to implement this in his plugin.

Code: Select all
import subprocess

myVar = indigo.variables[123]

def mySnmp(adr='Primair-eXtreme.local', pwd='######'):
   cmd = 'snmpwalk', '-m', 'AIRPORT-BASESTATION-3-MIB', '-Os', '-v', '2c', '-c',    '%s' % (pwd), '%s' % (adr), '1.3.6.1.4.1.63.501.3.2'
   try:
      p = subprocess.Popen(cmd, stdout= subprocess.PIPE, stderr= subprocess.STDOUT)
      return p.stdout.read()
   except:
      indigo.server.log("********Airport Down********")
      return 'something'

if '"00:00:00:00:00:00"' in mySnmp():
   indigo.variable.updateValue(myVar, "true")
else:
   indigo.variable.updateValue(myVar, "false")


123 your Indigo variable ID number. This code does not create this variable.
Primair-eXtreme.local Your bonjour Airport name. Or IP address.
###### Your Airport password in plain text. Default for extreme is 'public'.
00:00:00:00:00:00 Your MAC address of your iPhone/iPad

I changed the code to scan just one Airport. U have to turn on "Allow snmp" in your Airport via the Airport utility program.

Posted on
Tue Dec 13, 2011 2:46 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Smartphone Radar - Smartphone presence detection (Update

Thanks, BeNoOne.

How does this work with Smartphone Radar? Does this script get called periodically by a Timer Action? What variable is being updated? It looks like it sets a variable, such as "MyPhoneIsHome" to true when it finds it in the base station's list of associated MAC addresses. If that's the case, how does Smartphone Radar make use of that variable?

I don't mean to be such a rookie with this, but I'd really love to get all this working. :)

Posted on
Tue Dec 13, 2011 3:08 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Smartphone Radar - Smartphone presence detection (Update

This script doesn't work with Smartphone Radar at all. As I said before it's only an idea that could or could not be implemented by travisc, the plugin maker. It's not meant for end users.
But if U want to use it, the script only says iPhone true for Home or false for Away. Nothing more nothing less. The rest is up to U.

Posted on
Tue Dec 13, 2011 3:16 pm
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Smartphone Radar - Smartphone presence detection (Update

Ah, all right. I have some ideas of how to use this.

Thanks again! :)

Posted on
Tue Dec 13, 2011 3:26 pm
travisc offline
User avatar
Posts: 346
Joined: Sep 07, 2010
Location: Toronto, Canada

Re: Smartphone Radar - Smartphone presence detection (Update

@BeNoOne

Thanks for sharing! We may have no choice but to go the snmp route for the Airport base stations. I'll look into implementing something based on this when I get some time.

How long after the iOS device leaves until the snmpwalk no longer contains the MAC?

Posted on
Tue Dec 13, 2011 3:44 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Smartphone Radar - Smartphone presence detection (Update

In the past it lingered for a few minutes. But lately, I think after initializing a wds network, it's immediately gone.

The script hase to run at set intervals. Stick it to a schedule that runs every so minutes. So it wil take 0 to max the time you set the interval.

The Smartphone Radar plugin has a timed filter my script hase none. You could build one in Indigo if you need one, I have no use for it at the moment.

edit
Sorry travisc I thought I was answering someone else. I think you know your own plugin :)

Posted on
Tue Dec 13, 2011 7:13 pm
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: Smartphone Radar - Smartphone presence detection (Update

Travisc and BeNoOne,

I think the snmp data coincides with the associated and disassociated entries in the Airport base station log file. I am running a test to see if my iPhone 4S stays associated the whole time I am home and always reports disassociated when I am gone. If it does, then a plugin that set a variable "Home" with Associated log entries and set it "Away" with Disassociated entries would be pretty nice.

Example log entries:
Dec 13 19:11:02 BaseStationName 80211: Associated with station d0:23:db:68:ea:a6
Dec 13 20:15:34 BaseStationName 80211: Disassociated with station d0:23:db:68:ea:a6

Posted on
Wed Dec 14, 2011 1:13 am
bluenoise offline
Posts: 143
Joined: Aug 23, 2008

Re: Smartphone Radar - Smartphone presence detection (Update

travisc wrote:
@BeNoOne

Thanks for sharing! We may have no choice but to go the snmp route for the Airport base stations. I'll look into implementing something based on this when I get some time.

How long after the iOS device leaves until the snmpwalk no longer contains the MAC?


I got this working with our iPhones. With our two iPhone 4 phones, the MAC address disappears and reappears nearly instantly (I tested by toggling Airplane Mode). Those phones stay in the list, even when asleep, but our one iPhone 3 drops off the list shortly after going to sleep only to pop right back up when woken up.

I'll have to watch to see if the two iPhone 4 phones stay in the list, even when asleep for an extended period of time.

Here is what is pasted into a Schedule that executes every five minutes:

Code: Select all
import subprocess

aaa_iphone = '"AA:AA:AA:AA:AA:AA"'
bbb_iphone = '"BB:BB:BB:BB:BB:BB"'
ccc_iphone = '"CC:CC:CC:CC:CC:CC"'

aaa_iPhone_home = indigo.variables[123]
bbb_iPhone_home = indigo.variables[234]
ccc_iPhone_home = indigo.variables[345]

# adr = Bonjour name, as shown in Airport Utility
# pwd = SNMP Community String, shown under the Advanced Tab in Airport Utility
# Enable 'Allow SNMP' under the same tab in Airport Utility

def mySnmp(adr='xxxxx.local', pwd='xxxxx'):
   cmd = 'snmpwalk', '-m', 'AIRPORT-BASESTATION-3-MIB', '-Os', '-v', '2c', '-c', '%s' % (pwd), '%s' % (adr), '1.3.6.1.4.1.63.501.3.2'
   try:
      p = subprocess.Popen(cmd, stdout= subprocess.PIPE, stderr= subprocess.STDOUT)
      return p.stdout.read()
   except:
      indigo.server.log("******** Airport Down ********")
      return 'something'

if aaa_iphone in mySnmp():
   indigo.variable.updateValue(aaa_iPhone_home, "true")
else:
   indigo.variable.updateValue(aaa_iPhone_home, "false")


if bbb_iphone in mySnmp():
   indigo.variable.updateValue(bbb_iPhone_home, "true")
else:
   indigo.variable.updateValue(bbb_iPhone_home, "false")


if ccc_iphone in mySnmp():
   indigo.variable.updateValue(ccc_iPhone_home, "true")
else:
   indigo.variable.updateValue(ccc_iPhone_home, "false")



Posted on
Wed Dec 14, 2011 11:16 am
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Smartphone Radar - Smartphone presence detection (Update

Please note:
The information snmp returns is mostly the same Smartphone Radar is getting out of the logging.
So it's not more or less reliable. It's only another (simpler) way to get the same information.

Posted on
Wed Dec 14, 2011 11:26 am
snowjay offline
Posts: 274
Joined: Aug 09, 2006

Re: Smartphone Radar - Smartphone presence detection (Update

loafbread wrote:
Travisc and BeNoOne,

I think the snmp data coincides with the associated and disassociated entries in the Airport base station log file. I am running a test to see if my iPhone 4S stays associated the whole time I am home and always reports disassociated when I am gone. If it does, then a plugin that set a variable "Home" with Associated log entries and set it "Away" with Disassociated entries would be pretty nice.

Example log entries:
Dec 13 19:11:02 BaseStationName 80211: Associated with station d0:23:db:68:ea:a6
Dec 13 20:15:34 BaseStationName 80211: Disassociated with station d0:23:db:68:ea:a6



I am finding this to be true as well with my 4S and Time Capsule.

Jason

Posted on
Wed Dec 14, 2011 11:31 am
travisc offline
User avatar
Posts: 346
Joined: Sep 07, 2010
Location: Toronto, Canada

Re: Smartphone Radar - Smartphone presence detection (Update

@bluenoise
Nice script, that would be fairly easy to incorporate into the plugin, see my question below.

BeNoOne wrote:
Please note:
The information snmp returns is the same Smartphone Radar is getting out of the logging.
So it's not more or less reliable. It's only another (simpler) way to get the same information.


I was just going to ask that question, thanks BeNoOne.

I'm curious how long the iPhone's are listed in the snmp output in various situations.

i.e.:
- If the iPhone is asleep, connects to the network, checks it's email.
- If the iPhone is on charge and asleep.
- If the iPhone goes out of range of the base station.

It seems there's some persistence to the data as your script only runs every 5 minutes. I'm curious if that's often enough to not miss any activity.

Posted on
Wed Dec 14, 2011 12:30 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Smartphone Radar - Smartphone presence detection (Update

I'm requesting only a small part of the snmp output, hence the "1.3.6.1.4.1.63.501.3.2" part. I don't know what else is in there but I'm guessing it would be the same as the log stream.

The part that I'm requesting doesn't hold the mac address for any amount of time. The phones disappear almost immediately out of the list if the connection is lost or the phone is out of range. It doesn't matter what state the phone is in. I think that there is some sort of low power function in the WiFi radio that keeps it polling for the base station and keeps the phone associated with it. I can also see this in the Airport utility the client stays visible in the client list. But pre iOS5 my iPad only worked reliable with the 3G radio off, now with iOS5 it also seems to be working with the 3G radio on. I'm still testing but up until now it is working out for me.

Page 7 of 23 1 ... 4, 5, 6, 7, 8, 9, 10 ... 23

Who is online

Users browsing this forum: No registered users and 2 guests