In this post you’ll find instructions for using a Raspberry Pi to wirelessly control Etekcity power outlets using 433MHz RF.
- Etekcity Wireless Remote Control Electrical Outlet Switch for Household Appliances
- Raspberry Pi ( I’ve used new Raspberry Pi zero $5 computer board)
- Wireless Adapter (for getting internet in pi using wi-fi)
- Alternate to Wireless Adapter, you can use Ethernet Adapter to get direct internet
- RF Transmitter & Receiver kit
- Jumper Wire set
Other Required Items:
- Soldering iron
- 12″ strand of wire (for antenna)
- Install Raspbian from Raspberrypi.org. You can download “Noobs” and extract it to folder. Later you have to copy that extracted folder to SD Card.
- Full instruction on how to install Raspbian
WiringPi is a prerequisite package required by RFSniffer and codesend.
The source files for the software can be pulled using git.
git clone git://git.drogon.net/wiringPi git clone https://github.com/bapatel1/WiringPi // (alternate link if above doesn't work)
Execute the build script to compile the code.
cd wiringPi ./build
To confirm that the build process was a success you can issue the following command.
You will see copyright message and few raspberry pi details.
Finally you can issue the command below to confirm that wiringPi can read from the GPIO pins.
If successful you’ll see a listing for all of the gpio pins and their values…
The Apache web server is used to serve the toggle.php page which will provide a web interface for controlling the wireless outlets.
Use the command below to install Apache with the php modules.
sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5 -y
To confirm that Apache is working put the IP address of your Pi into your web browser, you should see the default Apache test page.
e.g. Run http://192.168.1.128 on Pi’s browser and you will see test page from Apache2 and see some message like “It works”.
Without an antenna the transmitters range is extremely limited, mine wasn’t able to reach outside the room without one. I took Tim’s recommendation and used a 12″ piece of wire.
You should see a hole with “ATN” label or something on small transmitter module (which will have 3 pins). Attach one wire to it and that will be your Antena for your transmitter.
- The transmitter module is the smaller module which has 3 pins, VCC, data, and ground.
- The receiver is the larger of the two modules with 4 pins, VCC, 2 data pins, and ground. Only one of the data pins on the receiver is used for this project.
Transmitter Module ******************* DATA (left pin) -> GPIO #17 VCC (center pin) -> +5VDC GND (right pin) -> Ground Receiver Module **************** VCC (left pin) -> +5VDC DATA (2nd pin from left) -> GPIO 21/27 GND (far right pin) -> Ground
In this step you’ll use a program called RFSniffer and the 433MHz wireless receiver to read the on and off codes for each pair of buttons.
git clone email@example.com:bapatel1/rfoutlet.git /var/www/html/rfoutlet
Set the appropriate ownership and permissions on the codesend executable.
sudo chown root.root /var/www/html/rfoutlet/codesend sudo chmod 4755 /var/www/html/rfoutlet/codesend
To sniff the codes run the RFSniffer program.
You won’t see any output on the console when you run the program but if everything is connected properly you should see output after pressing some of the buttons on your remote.
Each press of a button on the remote should produce something like this:
Received 21811 Received pulse 192
What you’re looking for is the longer number, not the short 3 digit pulse. In the example above 21811 would be the code you’re looking for. Record the code for each of the on and off buttons on the remote.
Here are a few of my notes about reading the codes:
- The receiver is not very sensitive so make sure you have the remote nearby when reading the codes.
- I found that sometimes I had to press a button multiple times before a code was received, it’s not a 100% reliable process.
- If it’s not working, double check the wiring of the receiver module (the longer board with 4 pins)
- For further troubleshooting try connecting an LED to the data pin of the receiver, it should blink when receiving data.
Using your preferred text editor edit /var/www/html/rfoutlet/toggle.php with the codes you recorded in step 5. You will also need to update $rfPath to point to the correct path which in my case was /var/www/html/rfoutlet/codesend.
Testing the Web Outlet Controls
At this point everything should be done and ready to be tested. The php based web control page can be accessed by visiting the http://<your-pi-ip>/rfoutlet in your browser.
The on and off buttons on the page should function just as they would on your physical remote.
If the buttons on the web page don’t work then try manually sending a code using the command line.
root@raspberrypi:/home/pi# /var/www/html/rfoutlet/codesend 21820 sending code
If sending a code manually works then the transmitter is functioning but there is an issue related to the web setup. Make sure that you made the correct modifications to toggle.php, specifically the $rfPath variable is pointing to the correct path.
You can also check the apache server logs to see if there is a syntax error in the toggle.php file.
tail -100 /var/log/apache2/error.log
If the manual code send isn’t working then check to make sure the transmitter is wired properly. You can also connect an LED to the data pin of the transmitter to confirm that it is receiving output from the Pi, it should blink when you send a code.
Referred Blog Post: