Log in

No account? Create an account
Android Garage Door Opener, part 2 - brad's life — LiveJournal [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Android Garage Door Opener, part 2 [Oct. 26th, 2008|12:06 pm]
Brad Fitzpatrick
[Tags|, , , ]

This is a follow-up to my previous post to say:


I got it all working. I now have an Android Activity (GarageDoorActivity) which interacts with an Android Service I wrote (InRangeService), letting me start and stop the service's wifi scanning task. The service gets the system WifiManager, holds a WifiLock to keep the radio active, and then does a Wifi scan every couple seconds, looking for my house.

When my house is in range, it does the magic HTTP request to my garage door opener's webserver (HMAC-signed timestamped URL, for non-replayability/forgeability if sniffed) and my garage door opens. Complete with a bunch of fun Toast notifications (like Growl) and Android Notifications (both persistent ongoing notifications for background scanning, and one-time notifications for things like the garage door actually opening).

I just threw on some shoes and hopped on my motorcycle to do a test lap around the neighborhood. When I got to the corner, I pulled up the activity and press "Start" (aka "Going home now"). A lady on the corner saw me playing with my phone on my motorcycle and said, "The reception's not so good up here." I thanked her, not wanting to explain what I was actually doing.

I then finished the lap around the block and the garage door started opening a few houses away. By the time I pulled up, I could already back the bike into the garage. HELL YES.

Update 2008-11-16: The source code is now available.

[User Picture]From: ciphergoth
2008-10-26 07:46 pm (UTC)
Does stopping the bike, getting your phone out, finding the activity, pressing the button, putting your phone away, starting up the bike again and putting it in the garage actually save you any time over driving to your home, dismounting in front of the door, opening the garage door and wheeling your bike in?

Of course, that's not entirely the point, but still...
(Reply) (Thread)
[User Picture]From: mart
2008-10-26 07:56 pm (UTC)

Presumably in practice this would be activated before Brad heads home from somewhere else, so the extra stop wouldn't be necessary. I assume he did it this way for the test just because home was both the source and the destination.

(Reply) (Parent) (Thread)
[User Picture]From: ciphergoth
2008-10-26 08:02 pm (UTC)
But that means the door sits open throughout his journey, which seems to defeat the purpose...
(Reply) (Parent) (Thread)
[User Picture]From: mart
2008-10-26 08:06 pm (UTC)

The previous version was as you describe; you had to pull the phone out while near the house and explicitly open the door. The thing that's new about Brad's Android app is that it figures out using wi-fi signals when Brad is approaching his house, so even if he turns it on an hour before it won't actually open until he's close by. This isn't possible on other phones because they don't let you get access to the wi-fi bits to do AP scanning.

(Reply) (Parent) (Thread)
From: (Anonymous)
2008-11-19 03:36 am (UTC)

Re: Purpose

I think you're misunderstanding... The service automatically checks for his wifi, and only after it finds his house's wifi does it connect and send the request... Unless someone deviously places an access point spoofing his AP's MAC address somewhere on his way home, he's reasonably safe.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2008-10-26 08:22 pm (UTC)
No, like Mart said below, starting the service just means starting the search for my house, not opening the garage door immediately.

And now the next step (briefly alluded to in the previous LJ post) is to automatically start the background service based on conditions, such as my common case:

-- I come home sitting on the Google shuttle for 30-60 minutes, with the Google shuttle's Wi-Fi in range. this is between, say, 4pm and 8pm.
-- Suddenly the Google shuttle wifi disappears, so I must be off the shuttle now and walking a half block to where I park my motorcycle.
-- The service turns on now, at least for 10 minutes (it takes about 5 minutes to motorcycle home), assuming I'm heading home

So in that common case, I do nothing: my phone notices my common case (going home) and opens it when I approach.

In the lesser common case, like I just did now: I met a friend for brunch. When I was putting on my helmet, I pushed the "Start" button on my phone before I put on my gloves. When I got home in 10 minutes, the garage opened.

(Reply) (Parent) (Thread)
[User Picture]From: ciphergoth
2008-10-26 08:25 pm (UTC)
ooooh! OK, yes, that is super neat :-)
(Reply) (Parent) (Thread)
[User Picture]From: jwz
2008-10-26 08:26 pm (UTC)
This is kind of awesome.

I love the idea of this expert system tracking you: "you appear to be on a bus in the evening. Would you like to go to DEFCON GARAGE DOOR now?"
(Reply) (Parent) (Thread)
[User Picture]From: bandicoot
2008-10-26 08:50 pm (UTC)
Can't you combine it with GPS data so the garage door just opens when you get close enough?
(Reply) (Parent) (Thread)
[User Picture]From: brad
2008-10-26 08:51 pm (UTC)
In theory, but the GPS kinda blows even with a direct view of the sky. I don't trust it to work in my pocket at all.
(Reply) (Parent) (Thread) (Expand)
(no subject) - (Anonymous) Expand
[User Picture]From: mart
2008-10-26 10:18 pm (UTC)

Does Google really only have one vehicle, or do all of them have something in common that you can use to recognise them?

(Reply) (Parent) (Thread) (Expand)
[User Picture]From: ellenlouise
2008-10-27 10:10 am (UTC)

ohmygod you get to go home at 4pm sometimes?

i assume you can also do this the old fashioned way in case there's a blackout?
(Reply) (Parent) (Thread)
From: (Anonymous)
2008-10-28 12:38 am (UTC)

What about more?

You could add another layer of geekiness just to make sure: (assuming you could have automatic pick-up when it's from your server and that you have an earpiece)
when you approach your house, your webserver gives you a call to ask confirmation with a nice sexy voice, a little bit of voice recognition for "yes", "no" and/or a password and you're good to go, no?

Maybe too far :)

But good job otherwise! I really love the multiple steps involved in doing it.

Question though: couldn't you do it only on the server's side by catching when your phone's MAC address is connecting to your WAP? I know it's missing the point of the Android app, but for people who don't have an Android phone, I suppose that could be another way of doing something similar.
(Reply) (Parent) (Thread)
[User Picture]From: alcarilinque
2008-11-19 03:19 am (UTC)
Another option still would be to use the internal GPS to begin the process. When Brad comes within say, a 300 meter range of his home or something (the GPS seems to be slow at updating location) the process could automatically be triggered. Thus, all he'd have to do is hope wherever his phone is is in a good enough position to be able to get GPS info.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2008-11-19 08:50 am (UTC)

Re: Use GPS to auto-start the InRangeService

Assuming the GPS worked.
(Reply) (Parent) (Thread)