The switch — more specifically, the relay
— is inserted in between one of the wires on
the extension cord. The switch then
connects the broken wire on the extension
cord when the relay coil is powered and
then magnetized. Take a closer look at the
switch in Figure 3.
This was the very first prototype. I plan
to create a custom PCB (printed circuit
board) through Kicad and OSHPark for the
third revision. I will then dress up the switch
with a custom 3D printed box that can be
ordered from a local Staples after I make it
look professional. Although the wireless
switch is where the bulk of my interest and
fascination lies, I can’t help but be
impressed with the real time button state
synchronization for the Android application.
Real Time Button State
I ran into an issue after I finished building the switch
and writing the Android app on my Linux machine. The
toggle button on my wife’s and my phone was not
synchronizing each time one of us pressed it. This was not
a huge inconvenience, but it was a problem that I felt I
needed to solve. It also seemed like it would be a really
cool feature to have integrated into the project.
Unfortunately, the synchronization only works while
on the LAN at the moment. This means that if someone
leaves the house and they disconnect from the Wi-Fi, their
toggle button will not synchronize with everyone else’s
button once someone turns the lights on or off.
I’m working on a queuing system to fix this problem
which will store the signal (on or off, in this case) and
continue trying to send this signal to the IP address every
few minutes until the user re-connects to the LAN.
To achieve this general concept of a centralized brain
or system that could handle all of the signaling, I would
need a Raspberry Pi. This is where the signals would be
sent to once the toggle button is pressed on any one
phone, and this is also where the signals would be
distributed from and sent to all phones connected on the
LAN who have my Android app installed.
The first thing I did was install a Rails server and
MySQL database on the Raspberry Pi 3. The reason I
chose Ruby on Rails is that the framework will allow me to
permanently store each individual phone’s toggle button
state, IP address, and any other relevant information I
need to keep track of in a MySQL database. I can also
send and receive POST (see sidebar) requests, and
manipulate the incoming and outgoing data as well as the
local database easily with the Ruby programming
language, which is a favorite of mine!
January 2018 25
Post comments on this article and find any associated files and/or downloads at
The POST request method “requests” that a web server
accept the data enclosed in the body of the request
message; most likely for storing it. It is often used when
uploading a file or when submitting a completed web form.
In contrast, the HTTP GET request method retrieves
information from the server.
■ FIGURE 2. The new switch design.
■ FIGURE 3. The Raspberry Pi and switch connected to