Labels

lego (12) Linux (39) pi (20) Thinkpads (4)

Monday 23 December 2013

Belkin WeMo Switch as a Raspberry Pi Power Switch [day 9 of 20-days-of-posts series]



Recently I purchased a Belkin WeMo Switch.  The switch makes a single electrical outlet become online by putting it on Wifi.  You can then use an iOS 6+ or Android 4+ app to toggle on/off the switch.  I didn't really see to much benefit of the app, as I already use Connected by TCP to control lighting around the home, providing me the ability to dim lights as well.

Of bigger importance to me was the IFTTT capability of the switch.  IFTTT, which stands for If This Then That, is an online service that lets you create recipes that can toggle the WeMo.    Because IFTTT is enabled for many other online services, you can tie the toggle on/off of the WeMo to other events, such as a gtalk or email message.  You could toggle the WeMo by the sending of a message to a IFTTT bot that contains a hash-tag that you assign to toggle your WeMo.  This makes it really easy to control a switch in your home from any device, not just your phone.  Likewise, IFTTT also has scheduled events as an ingredient, so you could use it to control what times your WeMo is on and off for.



There is a newer version, called Belkin WeMo Insight switch that has a much smaller footprint and also monitors and reports the power consumption of the device plugged in.  The Insight switch is about $10 more expensive.  It wasn't carried in any stores in Canada at the time of purchase (Home Depot, Canadian Tire, Future Shop / Best Buy, Amazon)

My particular interest in the Belkin WeMo Switch was as a Raspberry Pi power switch.  It makes a powerful switch for the following purposes:

  1. Serves purposes where something similar to as WOL (Wake on LAN) is needed.  I often use WOL on my systems, so remotely, I can connect to my home network and turn on computers as I need them, but issuing a WOL packet from the router to the PC.  For the Raspberry Pi, the Pi is always on as long as it has power supplied to it, therefore the USB-based ethernet switch doesn't feature the ability to turn the system on by WOL.  To do so, you would need to design and build your own power switch that could intercept the micro USB powered source and also reimplement the ethernet port by intercepting ethernet traffic capturing WOL packets and then controlling the power based on that.  There exists no ready-made logic board, so creating and implementing one would be impractical (and expensive).  With the WeMo, you can the toggle on power command straight to the switch, and anything connected to it will turn on.
  2. Scheduled on/off time.  If you need the system to be powered on during a certain time of the day (scheduled crontab job),  you can schedule the toggle on of the WeMo by a scheduler on  IFTTT.  Likewise, you can toggle it off at a different time.  Therefore, a scheduled crontab entry, I schedule my WeMo to be triggered on 5 minutes before the crontab entry is to run, and likewise, I schedule the WeMo to be triggered off 5 minutes after a matching crontab entry on the Raspberry Pi is scheduled to shutdown the system. Further, because there are three kinds of states you can use (toggle on, toggle off, toggle power state), if you toggle on the WeMo at a scheduled time, if it is already on, it won't be affected (as in, it won't be turned off by accident, unless you use the toggle power state as opposed to toggle on).
  3. Control your USB powered hub.  In my particular application, I'm powering the Pi using a power switch, which is plugged into a hub, where my USB devices are also plugged in (such as hard drive).  So, although I can schedule a shutdown on crontab which actually powers off the Pi with the addon power switch, the USB devices such as hard drive, remain powered on.  With the WeMo, I'm actually powering on/off the USB hub, so it would include automatically powering on/off the Pi itself.
  4. Remote hard-reset.  If (really more of a case of when) the Raspberry Pi becomes frozen or unresponsive where I'm not able to connect to it remotely to perform a reboot command, The WeMo allows me to either use my phone or IFTTT to toggle the power off/on.
Some conditions or other notes:
  • If you are strictly power off using the WeMo, you could corrupt the SD card or USB-based hard drive filesystem if you practice the habit of poweroff by cutting the power as opposed to safely shutting down prior with either a poweroff or shutdown now -h command.  In actuality, you could use a third party, such as Linux-capable router (which is my case), where if I need to perform a safe power down, I have the router issue a shutdown now -h over ssh to the Raspberry Pi, and then issue a #pi-off over email to IFTTT a minute later to actually power off the device.
  • If your Raspberry Pi starts up requiring root login to correct a disk issue, then you have no way around the issue other than to interact with the Raspberry Pi locally.  There is probably some way around this, some setting that lets you disable disk checks on startup, thus avoiding the prompt at startup for a root admin to log on to perform maintenance or CTRL-D to continue.  These prompts are not just tied to real disk corruption.  If I take my USB hard drive offline to sync it with another hard drive using another PC, if I write changes to it's supernode in the process, the next time I boot up on the Rasbperry Pi, it'll see the supernode has a timestamp newer than the system clock and thus refused to boot until a root user takes a course of action.  This nuance is for the fact the Raspberry Pi lacks a realtime clock, so on bootup, the present time will be the time at which the system was last on (stored to the SD card), so the fact the hard disk was updated or had changes to it with timestamps that are newer, it detects this as possible corruption-based issue.  Only after the system is booted up and on the network will the NTP set the time on the Pi to the current one.
  • You need an iOS 6+ or Android 4+ device even if  you intend to only control the WeMo via IFTTT.  The WeMO needs to be setup via the phone app.
The initial setup of the WeMo was fairly simple.  From what I read, the Android version of the app was created more recently and just came out of beta, and tends to have more bugs in it then the iOS version.  Therefore, I decided to dig my iPhone 3GS out of retirement for setting up this device, over the Android.  I plugged it in, then on my iPhone 3GS, I downloaded the WeMo app from the appstore.  As instructed by the app, you then need to change your Wifi access point on the phone to the one broadcasting from the WeMo.  Then at this point, the app will ask about the network setup of the WeMo, for which you provide the network key.  This was fairly simple.  But I did read online that a lot of users had problems at this point as their WeMo didn't accept network passwords with special characters (non-alphanumeric) such as spaces.  I'm not sure if this is resolved with a newer firmware, but if you have a network that uses one, you're out of luck with a out-of-box device until you get it onto a network it will accept.

As part of the setup, you provide it a name for the switch (assuming you may one day have multiples).  In my case, I just called it Raspberry Pi Server.  You can also assign it a user-created PNG graphic to depict the device image in the app.

After I got the device setup, I was prompted by the app to update the firmware on the WeMo as there was a newer one available.  This is where I began to quickly learn how buggy the firmware and app are.  I accepted the app to let the WeMo download the firmware.  At this point it instructs you that you can close the app, that the WeMo is downloading the firmware direct (indicated by flashing blue light) and will take about 10 mins to complete, at which time the WeMo will reboot and be ready for use.  I left the app open just the same, and went off to get a coffee.  When I got back I saw the WeMo was done the firmware upgrade, but instead of a steady blue light (indicating on) or no light at all (indicating off), I was presented with a blinking amber light.  It would seem this may have multiple meanings, but the initial one I found was that the device was not able to conenct to wifi or is still trying.  Checked the router and it confirmed the WeMo was not connected, having been connected and assigned an IP prior (since it had finished setup and had downloaded the new firmware).  I checked the phone app and it indicated the device was "firmware upgrading".  Unplugging it and plugging it back in proved futile.  I quickly learned of the restore procedure to try to trigger the device to restore to factory state.  So, went through the initial setup again, assigning the device a new name, giving it the network password etc.  This time at the completion of the setup, instead of letting me see the state of the switch in the app, it said the device was "firmware upgrading".  I had used a different name the second time, and it was the second named switch that it was in belief was firmware upgrading, whereas looking at the device, no said activity was underway.  Closed the app and started it again, and it was able to see the on/off state of the app correctly.

So, as you can see, both the app and the WeMo firmware are buggy, and I'll be more apprehensive on updating the firmware in the future.  Because it was freshly out of the box, I tend to take on more risky behaviour such as updating firmwares since I can just turn around and head back to the store to return the bricked device.  Had I updated in weeks or months following, I'd be at the mercy of the manufacturer RMA procedure.  

Setup was easier for IFTTT.  Activating the WeMo channel in IFTTT just involved providing it the  unique identifier number that the phone app provided so IFTTT could locate and use the WeMo.  I didn't have to open any firewall ports, etc.  Either the WeMo is pulling the requests or it is opening a port on the firewall itself.  I'll look into the details someday.  I'm interested in seeing what the packets look like going between IFTTT and the WeMo.

Pros:
  • IFTTT support
  • the latency is minimal; within 1-2 seconds of triggering a power toggle on the app or in IFTTT, the WeMo is toggled
  • this speaks more to IFTTT itself, but the time between emailed hash-tag emails to invoke the WeMo are processed usually around 5 seconds after the email request departs
  • survives power failures with settings preserved
Cons:
  • pricey (around $40 - $50)
  • firmware update process is buggy
  • requires the phone app for at least the initial setup
  • users report problems with network passwords with non alphanumeric characters
  • almost guaranteed to have problems with enterprise networks (such as ones that requires LEAP etc)
  • no surge protection; designed to fit outlets, not power-bar friendly, but it contains no surge protection and the huge footprint of the device causes hindrance plugging it into outlet surge protectors
  • unless your outlet plug sits flush with the surrounding wall, or extends out a bit, the overhanging of the switch will cause problems
  • causes havoc with powerbars; the footing is larger than power bricks, so even when a powerbar (or in my case APC UPS) has a "power brick outlet" to eliminate impact of a power brick on adjacent outlets, the footing still causes problems, barely allowing a two prong cable to clear (see picture of my setup)

[There is a newer version, called Belkin WeMo Insight switch that has a much smaller footprint and also monitors and reports the power consumption of the device plugged in.  The Insight switch is about $10 more expensive.]
  • network security issue; network details of the device are not transparent which is probably intentional to obscure security vulnerabilities 
  • it is essentially an embedded computer, so when you first plug it in (or turn a power bar on) it takes about 30-45 seconds for it to boot up (indicated by blue blinking LED) and another 30 seconds for the device to find and connect to the network (indicated by amber blinking LED)
  • consumes power (using a kill-a-watt reader, the device registers at 2 watts when idle and around 2.5 watts at bootup) -- the Raspberry Pi model B rev2 consumes about 2.5 watts, and the Raspberry Pi model A consumes about a constant 1.5 watts, so the WeMo consumes the same or more power than the Raspberry Pi.
Pros as a Raspberry Pi switch:
  • control the power switch remotely
  • lets you perform hard reboots remotely
  • control the power to the USB hub and all your Pi devices with a single switch
  • control the power to your Raspberry Pi using IFTTT, including implementing scheduled activities, activities based on other events
  • home automation necessity -- use in conjunction with motion sensors tied with IFTTT to aid in setting up home automation;  the WeMo switch is only one product available in the WeMo Home Automation category.
Cons as a Raspberry Pi switch:
  • no software shutdown support (need to software shutdown prior to avoid corruption of filesystem)
  • expensive

No comments:

Post a Comment