MySQL for the Internet of Things

(Steven Felgate) #1

ChapTEr 8 ■ DEmonsTraTion of high availabiliTy TEChniquEs


On the I2C bus, one device is designated as a write and the other a reader. The code therefore uses the
master as a writer and the slave as a reader, passing a simple message from the master to the slave. We will
use this configuration to construct a simple heartbeat algorithm whereby the master sends a short message
at a specific interval. This is sometimes called a pulse to complete the simile.
Thus, we can detect when the master is no longer communicating when the heartbeat does not occur
for a span of pulses. This can be detected by allowing a certain amount of time to expire without a pulse
or heartbeat message. We can use this event to trigger the failover to the slave for data collection. More
specifically, a timeout is used on the slave to wait for a certain amount of time to pass before declaring the
master dead. If the master does not send its message after a predetermined time, the slave takes over and
starts reading data and saving it to the database server. Thus, we can create a simple automatic failover using
redundant data collectors.


Assemble the Hardware


The hardware for this example requires two Arduino boards wired together via the I2C bus. We add an LED
to each for visual confirmation of messages sent and received. I used a red LED on the master and green
LED on the slave, but use whatever you have on hand—color is not important. Figure 8-4 shows how to wire
the hardware.


Figure 8-4. Redundant data collector (master/slave)

Free download pdf