presence detection - wifi via arping
Okay heres my first attempt, just add the names and mac addresses into the table and your good to go. tested on Rasp PI after installing arping (sudo apt-get install arping)
lets see if this works for the apple stuff..I suspect they will stop responding on standby but time will tell!
Garry.
-- Presence detection via wifi
module(...,package.seeall)
require("xap")
require("xap.bsc")
require("string")
info={
version="1.0", description="Presence Detection via Wifi"
}
local endpoints = {GarryPhone = "xx:xx:xx:09:33:1B", GarryIpad = "xx:xx:xx:xx:82:BA"}
function Detection(timer, self)
local msg = "arping -c 1 -i eth0 -q "..self.address
-- print("msg"..msg)
retval = os.execute(msg)
if (retval == 0) then state = "on" else state = "off" end
self:setState(state)
self:sendEvent()
timer:reset()
end
function init()
for k,v in pairs(endpoints) do
k = bsc.Endpoint{instance="Presence:"..k, direction=bsc.INPUT, type=bsc.BINARY, address=v}
xap.Timer(Detection, 60, k):start(true)
end
end
Garry what type of iPhone do you have?
As I said in the other thread, my wife's 4S responds to WiFi pings when asleep but my 3GS does not. I use both arp-scan and l2ping in a python script to detect presence and switch on bluetooth on the 3GS.
Incidentally, I use the return code to increment an absence counter or reset it to 0 if a zero return code is received. This works OK-ish for longer absences but I don't think it's ever going to be able to switch a light on when I return home because it's just too slow a respone.
Because I use the raspi to do the detection at the moment and then fire the result off in a UDP packet I don't bother with actual times. I just increment a tick on the HAH and reset it to 0 if I get a hit on WiFi (or bluetooth on my 3GS). As you say OK for detecting longish absences for dealing with heating etc. but not much use for lights.
I was going to play with geofenced reminders on SWMBO's iPhone to see if I could generate anything useful (perhaps via IFTTT) but I'm not sure she's too happy with me knowing when she's arriving and leaving!! I'll have to wait a while until I inherit her phone :-( so it probably won't be anytime soon!
Garry
I had to use the IP rather than MAC address and use arping rather than arp-scan but working fine here.
Thanks for the code
Mark
well I shouldnt be surprised!. iphone doesnt respond to arping on standby.
have installed arp-scan (sudo apt-get install arp-scan) on the Pi and modded the scripts as follows to see if this is any better? NOTE HEX mac address needs to be lower case.
-- Presence detection via wifi
module(...,package.seeall)
require("xap")
require("xap.bsc")
require("string")
info={
version="2.0", description="Presence Detection via Wifi"
}
local endpoints = {GarryPhone = "xx:xx:xx:09:33:1b", GarryIpad = "xx:xx:xx:xx:82:ba"}
function Detection(timer, self)
local msg = "sudo arp-scan 192.168.0.3-192.168.0.20 |grep "..self.address
-- print("msg"..msg)
retval = os.execute(msg)
if (retval == 0) then state = "on" else state = "off" end
self:setState(state)
self:sendEvent()
timer:reset()
end
function init()
for k,v in pairs(endpoints) do
k = bsc.Endpoint{instance="Presence:"..k, direction=bsc.INPUT, type=bsc.BINARY, address=v}
xap.Timer(Detection, 60, k):start(true)
end
end