The next step was setting up the registration system.
The registration system works by sending the phone’s IP
address to the Rails server (via POST request) once the
phone initially installs my application while on the LAN.
This keeps track of who has the application installed, but
more importantly it allows the RPI to receive a signal and
to traverse its database for registered IP addresses, then
send a signal to whoever is connected to the LAN without
an issue. So, when someone presses their toggle button to
turn the lights on or off from the app, the Rails server will
synchronize everyone up if permitted.
The POST request sent from the application when
toggling the lights on or off is comprised of the user’s IP
address and button state. Let’s have a look at the
flowchart in Figure 4 to get a better picture of the
synchronization flow of my framework.
The flowchart makes the concept of my framework
seem straightforward, but it was a bit more complicated to
achieve programmatically. The phone turning the lights on
or off will send that signal to the Pi first. We already know
that the Rails framework will then traverse the database
and find all connected devices by IP address, but I feel I
should reiterate to cover the full flow of my framework.
The RaspPi 3 then sends out that same signal it received
to a server running on the phones, which are constantly
listening for incoming connections and
Once the phone receives a signal, it
then sends an intent to a private
BroadcastReceiver class inside of the main
Activity class. This is where the state of the
toggle button is changed by updating the
local SQLite3 database according to the
signal it received. Figures 5 and 6 show
some code samples to give you a better
idea of what this looks like. The full code is
available with the article downloads.
The voice recognition is something I
decided to do at the last minute. When I
start a project that I really enjoy, I get so
wrapped up in it that I just keep adding
features and functionality until I get bored
or I finish. (I have a lot of unfinished
projects and I’m sure a lot of you readers
The voice recognition was a bit tricky to
get working on the ARMv8 Raspbian device
though, solely because the Pi 3 does not
come with analog audio input. So, you are
forced to buy an external audio USB
adapter; so far, they have been hit or miss.
26 January 2018
■ FIGURE 4. Real time button state synchronization
■ FIGURE 6.
■ FIGURE 5.