Tuesday, November 12, 2013

Belkin's Wemo Light Switch Part 1

This is an ongoing project (aren't they all) so I'm calling this part one.

I recently (couple three weeks ago) bought a Wemo Light Switch (link).  I was fascinated by the fact that it runs embedded Linux and could be hacked a bit to do some things I want.  They cost about $50 (US), so they aren't the cheapest devices out there, but have you looked at light switches that can be operated remotely lately?  Fifty bucks isn't that bad, some of the other ones cost a whole lot more and many come in at around the same price.  So, it's not as bad as it sounds.

However, if you scan the web, you'll find a lot of articles that are obviously trying to get hits because all they say is what Belkin already says on their site.  There are also articles that recount how they work; something that you can get from any of the suppliers out there.  But, hidden among the chaff are a few really interesting tidbits.  First, is that the device came out quite a while ago, but only to work with the iphone.  Then they came out with a beta version of an Android app for people to try.  The reviews of the device are mixed.  Some love it and it does exactly what they want, other hate the device and Belkin because the device doesn't work and Belkin support doesn't respond worth a darn.

So, with people being totally disgusted with the device, a marginal (if even that) Android app, and terrible support, I bought one.  Nothing like jumping head first into the shallow end of the pool.

The device came in and I rushed right in to install it to replace one of those X10 switches that are so darn unreliable.  I carefully read the almost non-existent instructions, downloaded the Android app, and sure enough, it didn't work.  The set up is like some other devices, the switch has a Wifi chip in it and it is initialized to set up an ad-hoc network so you can initialize it to your in-house wireless network.  So, you take your phone, connect to the switch's ad-hoc usecured network and configure the chip to talk to your own wireless.  My problem was that the Wemo Android app wouldn't talk to the switch; my phone would, but the app couldn't see it.

I searched the web, Belkin's support site ... nothing.  I did find a number of folk that had hacked into it using some pretty clever techniques, but nothing that I could use.  Finally, I picked up the phone and called Belkin support.  I got the usual (for technical support everywhere) scripted responses and a promise to get a call back from a higher level technician.  That NEVER happened.  So, I thought, "Who has an Android phone near me?"  As you all know by now, I live in the sticks, so I had to do some searching, but I found a neighbor with a phone that would help.  I loaded the Wemo Android app on their phone and tried it again.  It worked!!

Yes, a different phone worked.  The neighbor's phone was running a slightly older version of Android and was of course, a different brand.  So, I set up the switch and tried my phone again since the switch was now talking to my Wifi network.  No luck, the app running on my phone couldn't see the switch.  Fine, there's more than one way to talk over ethernet.  Once again out to the web to see what I could find.

As luck would have it, I found the perfect solution for me, and probably a lot of other people out there.  This guy named Ian McCracken had already messed with the switches and developed a set of tools and API for the Wemo switch.  Bless Him.  He put together a nice python library that supports discovery and use of the switches and documented a ton of the intricacies involved.  Basically, this guy saved my butt on this little switch.  His web page where he describes it is here <link> and his library is here <link>.  Now just to be fair, another great guy: Isaac Kelly did some discovery work that made it pretty clear how to manipulate the Wemo switch.  Isaac's stuff is here <link> and he used a tool called Miranda created by /dev/ttys0 <link>.  But, Miranda had to be patched to support the Wemo switch because it uses a little known technique; of course, Isaac Kelly suggested the patch.  Miranda is here <link> and the patch is described here <link>.

So, with a patched Miranda, and a cool python library, I got the switch to work in my house.  Whew!  I still couldn't operate the switch with my phone, but I could turn it on and off with my Raspberry Pi.  Slick.

This all happened while I was waiting for the return call from Belkin.  That call never happened.  So, I decided to make a butthead out of myself and annoy the heck out of Belkin.  How can a normal person like me annoy a big company?  I went to their support site for the device <link> and nothing there could help me.  Next I went to getsatisfaction.com and found a Wemo forum there.  I posted a couple of times about the problem and how their response took forever and didn't accomplish anything <link>.  When that didn't work, I got a brainstorm.

I looked on Twitter and among all the crap was a Belkin marketing user.  Cool.  Right there in their marketing hype I posted about how I couldn't get any help for a product that they made that didn't work.  That got an immediate response.  I tweeted the forum entry I put up and they got on the stick and sent me mail telling me that they were referring the problem to someone to handle.  After a couple more of these, I actually got a phone call and a contact point at Belkin.

This nice lady tried with me over the phone to get the cell phone to talk to the Wemo, no luck.  She sent me some debugging instructions and I tried them to gather some information to help them diagnose the problem.  Suddenly, my phone started working.  Yep, you guessed it something changed and the Android app started working with the Wemo switch.  The sequence of events that got my phone to work with the switch is too long to go into in this post, but I will post it if anyone is interested.

So, I can turn on a light with a piece of code running on my Raspberry Pi, or over the internet using my cell phone.  I plan on extending this to allow my web interface to operate the switch as well, since that will only be a tiny bit of additional code.  It also opens up the possibility of adding more Wemo devices for things like appliances and other lights.  Belkin is also introducing a device that will control and monitor the power usage of an appliance; bet you know what I'll be ordering soon.

The lesson to be learned here is Legion. First, don't give up too easily.  Second, hit them where they will notice it: their online marketing. Third, expect a fix from the oddest circumstances.  Fourth, there are lots of other folk out there that have the same kind of problem, look for them.  Last, there are technical folk out there that can help with a lot of things; you just have to find them.