Data Broker
![]() |
![]() |
|---|---|
| Adafruit IO | Adafruit IO Arduino Library |
Locus Pocus Data Broker - Adafruit IO + Arduino
A stream of actionable location events can be made available as a data source for use in applications, but there needs to be a reliable way to distribute the data. The distribution is often handled by a "data broker," which specializes in collecting and publishing streams of data from different sources. Other applications can then subscribe to the published data streams. So, an application could subscribe to a stream of location-entered events for the person with the device & App.
Presuming a stream of location events, such as entering a location or leaving a location is available, the data needs to be reliably distributed as a feed of event messages. For IoT and smart device applications, a standard messaging protocol for data exchange is Message Queuing Telemetry Transport (MQTT).
The primary application functionality is to:
- Set up a data broker service
- Set up a data feed that can be subscribed to
- Connect to the data broker, check subscribed feed(s) in real time for events
- Make an application response to the events
Research
I considered several different data broker services. There are a variety that have been used in previous projects.
- Adafruit IO - provides a free-tier MQTT service with specific library code for connecting to the serivce
- HiveMQ Cloud - provides a free-tier MQTT service, can use general Arduino MQTT libraries
- Home Assistant - self-hosted service - can set up your own Home Assistant broker, often using a small compute platform such as Raspberry Pi
What Others Have Done Beforehand
In considering potential data broker services, I reviewed the data brokers used in some of the previous related projects.
| Project | Data Broker |
|---|---|
| Modern Weasley Clock | Adafruit IO |
| Weasley Clock | Home Assistant |
| Where'sLy Clock Project | HiveMQ Cloud |
| Magic-Clock | Home Assistant |
Data Broker Selection for Locus Pocus
In general, for managing privacy, I would gravitate toward the self-hosted Home Assistant broker. But the additional setup and management time was not on the cards. I selected Adafruit IO as the data broker - it provides a free usage tier and specific libraries. Also, my global evaluator (Iván Sánchez Milara) had created a tutorial on using the service, and I thought it was an interesting connection: Sending events to ESP8266 using Adafruit IO and IFTT .
Locus Pocus Data Broker Setup with Adafruit IO
Setup with Adafruit IO is fairly straightforward. An account with Adafruit is needed to get started. I already had an account with Adafruit, and that provides access to the free tier of Adafruit IO.
Moving to the Adafruit IO Dashboard, you can see information about status, data feeds and usage.

Adafruit IO Dashboard
In order to manage feeds, you select the Feeds View. This provides an overview of available feeds, activity, and enables creation of new feeds.

Adafruit IO Feeds
Creating a new data feed is straightfoward. Use the "New Feed" button and provide a name for the feed, with optional description.

Adafruit IO Create New Feed
The Feed dashboard provides information on feed activity. It enables you to view recent data events, as well as to download historical feed data. If you have numerical data, such as sensor readings, the graph will display the values over time. For non-numerical data, such as for Locus Pocus, the values for each event are listed below the graph area.

Adafruit IO Feed Data
An important part of this for setup is that you can directly add data to the feed from the interface, which was very helpful for testing.

Adafruit IO Adding Feed Data
Connecting to Location Activity Data Provider - IFTTT
Adafruit IO has an integration available for receiving data from IFTTT - the selected locaton data provider for Locus Pocus. Adafruit IO has a dashboard for setting up integrations, called "Power-Ups". IFTTT connectivity was configured by selecting the IFTTT power-up on the Adafruit IO side, providing IFTTT account detail, and confirming the connection while logged in to the IFTTT account. Setting up the integration made the IFTTT data available via an Adafruit IO feed.

Adafruit IO IFTTT Integration
Locus Pocus Application Connection to Adafruit IO
The Locus Pocus system uses the Adafruit IO Arduino library to connect with and use the data broker service. This generally involves 2 main steps
- Configuring the connection - specifying credentials for WiFi access and Adafruit account
- Using the data service - connecting to the Adafruit IO and accesing data feeds
Configuring Adafruit.io
In order to receive data feeds from Adafruit IO, 2 connections are needed.
- Connect to WiFi - for general internet / cloud network access
- Connect to Adafruit IO Service - to access Adafruit IO data feeds
In order to connect to WiFi, it is necessary to provide WiFi credentials to your local network. In order to connect to Adafruit, it is necessary to provide Adafruit IO credentials - these are your username and a special key for data access, which is available in your Adafruit IO account dashboard.
The ArduinoAdafruit IO Arduino library provides a set of code examples. The examples use a common pattern, where configuration / credentials are entered in a "config.h" file, which is then imported into the application code.
The config.h file does several primary things:
- Specifies WiFi access credentials - ssid and password for the WiFi access point
- Specifies Adafruit IO access credentials - username and access key for connecting to Adafruit IO services
- Configures WiFi library setup for the type of embedded computing board you are using
- Created the "io" object - which is the main way of interacting with Adafruit IO in the application code
The example config.h file for the "adafruitio_01_subscribe" example is shown below.
Connecting / Using Adafruit IO Data Broker Service
Once configured, the application code can connect to Adafruit IO in order to receive data feeds. Here, I hightlight the main touchpoints in the application code for interacting with Adafruit IO. The detailed application code is documented in the Primary Control section.
The following code excepts show the following main steps for connecting and using the Adafruit IO service. The code presumes the overall Adafruit IO service object - "io" - has been set up in config.h, as noted above. The steps are:
- Clock feed is set up
- MQTT connection is set up
- MQTT connection is started
- Message handler is set up for what to do when data is received on the feed
- function to handle messages is defined later on
- Application setup waits until there is both a WiFi connection and an Adafruit IO service connection
- Application contiually checks for feed data activity

