Technical tags

Hobby Project IoT Wireless Security USRP Raspberry Pi Linux C Language PHP Apache HTTP Server HTML JavaScript JQuery Vim Editor

Presentation and Source code

Introduction

In this personal project, I developed a couple of prototypes and designed a simple circuit board that supported Raspberry Pi to control different brands of wireless outlets. These are the ordinary wireless outlets that can be bought from online stores or local markets. The developed applications have these features:

  1. An intuitive web interface with some buttons to control the ON/OFF statuses of outlets.
  2. Supporting voice commands to turn on/off an outlet.
  3. Setting timers to control outlets.

This is a brief video presentation to show the result of the project.

The motivation of the project is to use Raspberry Pi to control outlets. There are already some similar projects using the Raspberry Pi for remote control. However, those are using existing switches of the wireless controllers. It means that you need to know some basic functions on the circuit board. Then you hack some circuits to use Raspberry Pi replacing the manual pressing on the buttons of these switches. Doing things of these like reverse engineering of circuits, that is not an easy way. Specifically, if you want to control outlets from different manufactures designed different structures of remote switches, you need to hack all of them. That is not practical, error-prone, and time consuming.

In this project, I used a more convincing way in building a Raspberry Pi to simulate signals of remote controllers. The idea was to use a software defined radio device, such as USRP, to capture genuine signals from switches. Then we use Raspberry Pi to simulate these signals. This method is easier than previous methods, and it is more general. You can use it to simulate all kinds of outlet remote switches.

Method

Step 1: Use USRP to capture signals transmitted from original switches.

USRP is an advanced software-defined radio platform. You can also use some other similar but cheaper solutions to finish the step as the USRP here.

This is the USRP platform I used to capture signals in the air.

A simple GNU-radio graph to capture the signals at channel 315MHz, that is the carrier frequency of outlet switches.

Step 2: Analyze the signals, and encode them into binary codes.

Use one outlet as an example, we get its signal of open command as a wave file. Use an audio editor to open the wave file. We can decompose the signal into some simple binary codes. The narrow square wave is coded as 0, the wide square wave is coded as 1. You are free to use other coding methods to make it easier to be interpreted. In this case, we can use the code as shown in the following figure to denote the message signal of open command.


An example of an outlet for the signal analysis here.

Translate the original signal into a binary sequence.

Step 3: Set Raspberry Pi as a transmitter.

By investigating the radio chip used in the wireless switch, we can figure out the carrier frequency is 315MHz. We use the chip that can transmit the same frequency, and connect the chip to the GPIO of Raspberry Pi. Then we change the voltage on GPIO to modulate the carrier signal with the message signal.

Step 4: Design a more convenient user interface to control outlets.

The c programming language with library "wiringPi" is used for the implementation of the transmitter. The binary sequences of signals to control ON/OFF statuses of outlets are listed here:
int g_signal_switch[]=
	{1,0,1,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,1,0,0,1,0,0,0};

int g_signal_1_open[]=
	{0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0};

int g_signal_1_close[]=
	{0,1,1,0,1,0,0,0,0,1,0,0,0,0,0,0};

int g_signal_2_open[]=
	{0,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0};

int g_signal_2_close[]=
	{0,1,1,0,1,0,0,0,0,0,0,1,0,0,0,0};

int g_signal_3_open[]=
	{0,1,1,0,1,0,0,1,0,0,0,0,0,0,0,0};

int g_signal_3_close[]=
	{0,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0}; 
We define the time interval for setting high/low voltage on the pin of GPIO as:
#define SEND_LOW_SWITCH	digitalWrite(PIN,1);delayMicroseconds(600);	\
    digitalWrite(PIN,0);delayMicroseconds(1200);
#define SEND_HIGH_SWITCH	digitalWrite(PIN,1);delayMicroseconds(1200);	\
    digitalWrite(PIN,0);delayMicroseconds(600);
#define SEND_LOW_SIGNAL	digitalWrite(PIN,1);delayMicroseconds(600);	\
    digitalWrite(PIN,0);delayMicroseconds(1800);
#define SEND_HIGH_SIGNAL	digitalWrite(PIN,1);delayMicroseconds(1800);	\
    digitalWrite(PIN,0);delayMicroseconds(600);

Using the above information, we complete an executable file that can attach parameters to specify which outlet will be turned on/off. Then we establish a web application on Raspberry Pi. The client with a browser can visit the web application to control outlets. To make things fancier, we introduced voice recognition feature, that can control an outlet by voice command. Besides, the web application supports to set timers to trigger some controls, this is a particular feature that is hard to be implemented on the original wireless switch. On Raspberry Pi, we can take advantage of Linux system to program these functions.

Conclusion

As we see from the project, Raspberry Pi has a lot of potentials in controlling home appliances as a simple solution to support the study in Internet of Things.