Skip to main content

Coding for a broken phone

So I've been very slowly working on a project to create a network-based garage door sensor (and possibly opener) which will let me check whether the garage door is open (when I left for a trip and suddenly panic because I can't remember if I closed it), and will also alert me if it's after 10 and I accidentally left it open. (Eventually I'd like to add a controller, so I can open/close it from my phone, but that's a long way off).

The first step was finding an easy way to sense if the door was open, and report that to my home server so it could serve it up to me.  Luckily my office-mate handed me his old android phone with a busted screen. Nothing shows up on the screen, and it the touch sensors don't work. 

Theoretically, I can mount the phone near the top of the garage, and write a program for this phone that will monitor the proximity sensor to tell if the door is open or closed (if I position the phone so that the open garage door will sit right in front of the phone near the ceiling) then report that to the home server over wifi.

So the things I would need to figure out:

  1. Can I even get code running on this thing without ever touching the screen?
  2. Can I get the proximity sensor working?
  3. Can I get the phone onto my wifi without being able to use the wifi configuration UI?
  4. Can I figure out how to physically mount this thing on the ceiling of the garage so it will work?
  5. Can I do all that before getting bored with the project?

1 was easy -- plug in the phone, fire up adb, and go to town. The Android debugging tools work just fine. Luckily Tim had enabled USB debugging before breaking it, or I might have been completely out of luck.

#2 was easy as well. The API for handling the phone sensors is pretty straightforward and easy to work with.

#3 was the most painful. I spent a good while tonight trying to figure out if I could configure the wifi just using adb (the remote debug tool for android). Couldn't figure out how to do it. So then I found the API for doing it programmatically -- so I need to write a program to configure the wifi before doing the rest of the monitoring. The sample code was really simple. Unfortunately it kept not working. And not working. And not working. With no reason reported of why -- either the call to enable my wifi network just failed, or it succeeded, but never connected. *sigh*. Finally figured it out after a ton of mistakes (the most notable, if anyone is here looking for help, being that the SSID and password have to be quoted inside the string, like:  String SSID = "\"myssid\"";, and the Android manifest needs to specify some uses-permissions: CHANGE_WIFI_STATE, ACCESS_WIFI_STATE, and ACCESS_NETWORK_STATE) 

So I finally tonight got that working. Next step: write the code to tie all this together. Then try to figure out how to mount it on the ceiling. Someday I might actually finish this thing.

If anyone tries to do this as well, here's a snippet of code that worked for me:

In the manifest:
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And the code itself:
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"mySsid\"";
conf.preSharedKey = "\"1234567890\""; 
conf.status = WifiConfiguration.Status.ENABLED; 
 
int res = wifi.addNetwork(conf);
wifi.disconnect();
wifi.enableNetwork(res, true);
wifi.reconnect();                
   
wifi.setWifiEnabled(true);

Comments

Popular posts from this blog

Retrospex 32 Review

RetrospexInternational recently sent me a couple units of their new handheld device, the Retrospex 32, a new dedicated GameboyAdvance emulator handheld.  To make the unit playable out of the box, they pre-loaded a handful of homebrew games, including Anguna, which is why they were kind enough to send me 2 of the units to play with.  I was pretty excited to get my hands on the device and try it (I loved my old GBA micro with a good flash cart!), and see Anguna running on it. So here's my thoughts after playing with it.



Their website lists the Retrospex 32 for £59.99, which is around $100 USD. It seems like it's marketed toward people into retro-gaming (which makes sense for a dedicated GBA emulator device). At that price, with that target market, and such a limited set of functionality (why not make it a multi-machine emulator, and emulate all the old consoles?), it would hopefully do a really good job of it.

The short version of my review: it doesn't. It has one job (emula…

Making the game fun

The real trick for Spacey McRacey (as I'm calling it now) is going to be making it fun.  And that's what I'm rather unsure about at this point.

I have a game design that basically works. The technical issues are mostly sorted out, I just need to get a few more implemented before I can seriously play test it.

But fun? It's hard to know if it's actually going to be any fun to play.  With a 4-player party-style game, it's seems like it might be hard to hit that fine line where everyone is close and competing, where everything feels exciting and tense, as opposed to tedious and boring.  And despite envisioning my game as fun, it might just be boring to play.

Some of that comes down to tweaking it. Tweaking the speeds, difficulties, etc, will make a difference. (If it's too easy to shoot people from behind, then it will be nearly impossible to hold a lead for very long, which could ruin it and make it no fun. If it's too hard to kill the guy in front, it wil…

Killer Queen

So at PRGE, I played an arcade game that just left me amazed.  Killer Queen.

It's a 10-player game. You have 2 cabinets linked together, and 5 players huddled on each one. Each one is a team of 5 people, working together to play a simple one-screen 2d platformer.  But what made it work was the high quality game design.

First, the game is relatively simple, yet there is a lot going on at once.  One player plays the queen, the most important and powerful character on the team. The others start as workers, but can become warriors who can fly around and attack in a very joust-like flappy contest of height.  The real trick is that there are three completely different ways to win: either collect a bunch of berries and bring them back to your base, or ride a REALLY SLOW snail across the screen (while other people try to kill you, and you hope your team protects you), or kill the enemy queen 3 times.  There's some other things going on as well (using berries to upgrade, capturing upgr…