?

Log in

No account? Create an account
Android Garage Door Opener, part 2 - brad's life [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:

SO. FUCKING. AWESOME.

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

Comments:
[User Picture]From: brad
2008-10-31 10:25 pm (UTC)

Re: WifiManager

There's probably some Android developer forum or mailing list somewhere. I'm really not that great at any of this stuff.

And yeah, I think the emulator doesn't emulate the Wifi stuff.
(Reply) (Parent) (Thread)
From: bennry73
2008-10-31 10:37 pm (UTC)

Re: WifiManager

Yeah. Alright, sorry to bother you. You figured out some things that people on the forums haven't yet, which is how I found this post.

Honestly, It doesn't seem that too many people are all that good at this whole Dalvik thing yet. Did you test the wifi stuff on a device? I have an N810 with android ported, and was thinking about using that. I might just have to get a G1.

The only question I really have is pretty simple, and I think I know the answer. I want to call WifiManager.startScan, but I didn't know how to get the results. Do you do something like this:

0 WifiManager mManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
1 Intent mIntent = new Intent("android.net.wifi.SCAN_RESULTS");
2 setResult(RESULT_OK, mIntent);
3 if(mManager.startScan()){
4 startActivityForResult(mIntent, COMPLETED_SCAN); 5 }

and just override OnActivityResult to read information about access points detected?

I can probably handle the rest. Would you think about releasing your code?
(Reply) (Parent) (Thread)
[User Picture]From: brad
2008-10-31 10:42 pm (UTC)

Re: WifiManager

Sure, I'll post it tonight or this weekend and announce it on this blog.

(Reply) (Parent) (Thread)
From: bennry73
2008-10-31 10:49 pm (UTC)

Re: WifiManager

That's so fucking awesome, thanks.
(Reply) (Parent) (Thread)
From: (Anonymous)
2008-11-08 10:08 pm (UTC)

Re: WifiManager

Did you happen to post it? Didn't see it on the blog.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2008-11-16 07:43 pm (UTC)

Re: WifiManager

It's up now.
(Reply) (Parent) (Thread)