The Right Way to Have Built This!

I started out this tutorial by admitting I didn't build it in the best possible way. There are two ways I could have done it better.

  1. Send the light sensor data directly from the Feather ESP8266 to using the MQTT library and skipped the intermediate MQTT infrastructure altogether. This is probably the simplest option.
  2. Change the local MQTT topic to include subtopics, then directly bridge the local and MQTT queues.

Send directly to from the ESP8266.

I don't have the Lua code written and tested for doing this, but I know that Lua supports direct MQTT interactions. After all, that's how I get the data into the local MQTT queue. The trick is to use your Adafruit.IO key as the password when you configure the MQTT connection in Lua. Without testing this I can't guarantee it would work, but it should be ok. I'll get a couple more Feather Huzzah! ESP8266 modules and test both of these alternative configurations. I'm actually most interested in the next option

Broker-to-Broker Bridging

This is an intriguing possibility. According to the documentation, it should (again) work. The trick, once you have the local feed set up, is to modify your /etc/mosquitto/conf.d/mosquitto.conf file to append this section to the example I already provided::

Download: file
# Bridge to Adafruit.IO
connection adafruit-light-sensor
bridge_atetempt_unsubscribe false
cleansession false
notifications false
remote_username CHANGE_TO_YOUR_USER_NAME
remote_password CHANGE_TO_YOUR_AIO_KEY
start_type automatic
topic /sensors/lightsensor  out 0 lightsensor

Restart mosquitto with this command:

Download: file
sudo systemctl restart mosquitto.service

Once this is done the lightsensor data should be flowing automatically from your local MQTT instance into, where you can configure dashboards as before.

As I noted, I have NOT tried these two techniques yet, though I plan to do so.

This guide was first published on Aug 20, 2016. It was last updated on Aug 20, 2016. This page (The Right Way to Have Built This!) was last updated on Jun 25, 2019.