Saturday, April 21, 2012

The Fonera Plugstrip

The Fonera Plugstrip is a gadget I made to be able to power ON and OFF some home appliances wherever and whenever I want. This device is always connected to The Internet, and can be controlled by any device with an Internet connection and a browser. There are already commercial devices like this, but they are very expensive, and I had a Fonera lying around and wanted to use it for something useful. The control is made using a simple CGI. In this video you can watch the device in action (skip to 1:40 if you don't want to hear how the system has been constructed).

The system has three elements:

In this figure you can see a schematic representation of the elements and the connections among them (clic to make it bigger). The status LEDs and the relay optocouplers have been omitted.

The power entering the plugstrip is routed to the gray box only when the power switch is on. Then it's routed to the 5V power source (that powers the Fonera) and to the relay switches. When the relay switches are closed, power is routed to the sockets in the plugstrip, and devices plugged to these sockets are powered.

Each relay switch is independently controlled by a GPIO pin inside the Fonera. So the Fonera controls when a socket has power or not. A CGI inside the Fonera is in charge of rendering a web page that serves as a control panel for each socket in the plugstrip. The user can interact with this web page, and the CGI will power ON/OFF the sockets accordingly.

The Fonera is a closed platform, so to be able to control the GPIO pins and install software inside it, you have to hack it first. You can find instructions here. Once hacked, it's not necessary, but it's recommended to install OpenWRT, a GNU+Linux distro designed mainly for routers and other similar small systems. Info about OpenWRT and the installation process, here.

And finally we get to code something. I have created an init script that configures the GPIO pins and the default status of the sockets. I have also coded a CGI in Linux shell script that renders the control panel and controls the sockets in the plugstrip. Both of them share a configuration file (/etc/plugstrip.conf) that can be used to map GPIO pins to the sockets, to change the text labels in the web page, to set the default socket status, etc. Grab the sources and installation instructions (including how to set up basic HTTP authentication) here.

This project is almost finished, but I want to add a new feature: the ability to configure time trigged events to power ON/OFF the sockets. I'll update this entry if I get some time to code it.


  1. How is it possible with DD-WRT?

  2. Yes, definitely it's possible with DD-WRT, but you will have to install gpioctl or to do small modifications to the script, because IIRC by default GPIO is accessed in DD-WRT in a different way (using sysfs).

  3. Gpioctl in ddwrt is called gpio, what changement at the script?

  4. I have done how it's write in but I open only webpage in format *.html, I have dd-wrt v24-sp2

  5. I have installed openwrt 8.09.2, can you done a guide step to step?

  6. ¿Have you downloaded the sources? Inside the tarball, there's a INSTALL file, with the installation instructions step by step.

    Some steps are not detailed, so if you need help for example to copy the files to the fonera (step 3), then feel free to ask here, but please refer to specific steps in the INSTALL file.

    Also if you need help in making the hardware, I can give you also more details about the build process.

  7. I have an old unused Fonera and I would like to build your plugstrip. Have you a precise scheme ? What electronic parts did you use ? where to connect on the Fonera ?

    Building a 5V power should not be a problem.

    At least, my idea is to be possible to start 1 or 4 PC : to connect the GPIO to the PC push button with an optocoupler for example.

    Many thanks for help and answer.

    Best Regards

    1. The only parts I have used are:
      - A Fonera
      - A Plugstrip
      - A 5V Power source. I used one salvaged from my Guruplug, but if like mine, your Fonera is a 5V-powered one, you don't even need to build one, the Fonera already comes with it.
      - An optocoupled relay board. The link I provided is broken, but you can use for example this one:
      - And of course, wire and solder.

      To control the board, I used some available GPIO pins. These GPIO pins are easily reachable inside the Fonera, because they are connected to the pads of the unpopulated connector SW1. I used GPIO pin 1, 2, 5 and 6. The pins used are easily configurable, just by editing the provided config file.

      Unfortunately, I don't have a more detailed schematic. I built the device on the go, and later drawed the block schematic you can see in this entry. But you can find a more detailed schematic in this similar build:

      It uses solid state relays instead of standard ones, and dd-wrt instead of Open Wrt. But it's almost the same build.

      If you build a plugstrip like mine, you don't need to access the inside of the computers to reach the power button. You can just plug the computers to the plugstrip, and configure them to automatically boot when they are powered (search the BIOS for this option).

    2. Thanks for answer !

      I will try to find such a relay board :)

  8. Hi! All works great, just one question: during the boot the state of the gpio change from off to on and then finally off do you have the same behavior and do you know how to keep the gpio on the same state during all the boot time?
    Thank you

    1. Hi. I have the same behaviour. I think the only way to avoid this would be modifying and rebuilding the bootloader (might also need to modify and rebuild the kernel). Unfortunately, the Fonera uses RedBoot, and I have never tried building it from sources (I don't even know if it is possible to build it for the Fonera, or maybe it depends on some binary blobs).