Introduction: Smart Power Strip Based on Beaglebone Black and OpenHAB

!!!!! Playing with mains (110/220V) is dangerous, please be VERY VERY careful !!!!!

There are some existing smart power strip designs based on "Raspberry Pi" and two Arduinos, which is shown in the picture "Old design".

This new design differs from these old ones in two ways:

  1. Since Raspberry Pi can control nRF24 by using its own SPI, it is not efficient to put an Arduino in between. Also I prefer Beaglebone Black board since it is cheap and powerful, and especially it has more available peripherals (like GPIO, SPI) than Raspberry Pi.
  2. In old designs, the only way to control the power strip is through the web interface (i.e. OpenHAB). However, it is very inconvenient to do so if the power strip is at hand. Therefore in this design, the power strip has individual switch for every outlet, and people can turn ON/OFF each outlet with or without OpenHAB (if with OpenHAB, the status on OpenHAB will get updated whenever the physical switch is toggled).

Step 1: Demo

Step 2: Overview

My smart power strip is composed of two parts: gateway and power strip (shown in the picture "My design").

The gateway side includes:

  1. A Beaglebone Black board
  2. A nRF24L01+ module
  3. OpenHAB + MQTT (message bus)

The power strip side includes:

  1. Three standard switch+outlet combos (w/ a 3-gang box)
  2. An Arduino pro mini board
  3. A nRF24L01+ module
  4. Three relay modules

The details will be covered in following steps.

Step 3: Gateway - Hardware

Materials:

A Beaglebone Black board

A nRF24L01+ module

A 10uF capacitor (RadioShack, ebay etc.), for improving the reception reliability.

Here I show the connection between the Beaglebone Black and the radio module. I also show my circuit for it, but a breadboard will do the job as well.

To use the SPI and nRF24 module in Bealebone Black, two steps are needed.

  1. Enable SPI on Beaglebone Black
  2. GET NRF24L01+ RADIOS WORKING ON BEAGLEBONE BLACK

Step 4: Gateway - Software

In terms of software on the Beaglebone Black, the overall structure is shown in picture 1.

Since there is a Debian running on it, it is very easy to install software using apt-get command.

OpenHAB is Java based, so it is necessary to install Java VM. Please refer to OpenHAB installation for details (it is for Raspberry Pi, but apt-get works for both boards). To enable MQTT for OpenHAB, the file "org.openhab.binding.mqtt-x.y.z.jar" needs to be put into the "addons" folder in the OpenHAB source folder. Three configuration files are needed (attached below), where "openhab.cfg", "test.sitemap" and "test.items" should be put into the "configurations", "configurations/sitemaps" and "configurations/items" folder, respectively. Then, the OpenHAB can be launched by typing "./start.sh".

For the MQTT bus, I use Mosquitto which is an open source MQTT broker. The Mosquito version on apt-get is pretty old, so I download the source code to compile and install.

  1. Get the source code from the official site above.
  2. In the source code folder, create a new folder called "build".
  3. Go into "build", type "cmake .."
  4. Then go back to the upper folder, type "make" and "make install"

Lastly, the gateway program is the bridge between MQTT bus and nRF24 module, and the architecture is shown in picture 2. There are two queues, each for one direction (i.e. one for the control CMD from OpenHAB to the power strip, one for the reverse direction). Basically it is a simple producer/consumer logic implementation. The source code of gateway can be found here, it uses some C++11 features (to install newer GCC on Beaglebone Black, refer to this article) and assumes the nRF24 lib is installed (refer to the previous Step).

Step 5: Power Strip - Hardware

Materials:

An Arduino pro mini board.

A nRF24L01+ module.

A 10uF capacitor (RadioShack, ebay etc.), for improving the reception reliability.

Three 10K resistors (RadioShack, ebay etc.), for switch.

Three Relay modules.

Three standard switch/outlet combo and a box, I bought them from Lowe's.

A 110vac to 5vdc module, to power the Arduino and relays.

A 5vdc to 3vdc step-down, to power the nRF24.

The connection is shown in picture 1.

!!!!! If you want to use same switch/outlet combo as me, please make sure you cut the "breakoff" on it (see picture 2) !!!!! This is extremely important or you may destroy your entire circuit !!!!!.

Picture 3 shows the finished power strip, as you can see, it is pretty mess in the box (since I cannot find any big enough off the shelf power strip with individual switch to use), but it works ^_^!

Step 6: Power Strip - Software

I use the same nRF24 library for Arduino as for Beaglebone Black (here, librf24-bbb folder is for Beaglebone Black, while the one in the root folder is for Arduino), but you can also use a more robust/powerful version for Arduion in here.

My source code for power strip side is attached here, please use Arduino IDE (or any other alternatives) and a correct programmer to install it on the Arduino pro mini.

Step 7: Conclusion

Enjoy!!!