A tiny program that reads the room's temperature (or, in this case, generates a random one), and publishes it to the Adafruit MQTT broker.
Adafruit IO has been chosen because it's free (up to 30 messages per minute) and
it provides easy to set up dashboards to visualize the data.
Except for minor changes, the program should equally work with other MQTT brokers, such as HiveMQ or Cedalo.
-
Create a new account at
io.adafruit.com
-
Create a new Feed named
temperature
-
Get your AIO key (you'll need it to run the program)
-
Open the
.env
file and adjust the variablesADAFRUIT_USERNAME
andADAFRUIT_KEY
Refer to the top-level README for instructions on building.
Run:
# (on the VM) sftp the executable and the .env file into the BBB
sftp-bbb
> put build/bin/mqtt
> put .env
# (on the BBB) run
./mqtt
Before trying to publish data to adafruit.io
, it might be useful to try the program locally.
In that case, simply adjust the .env
file to look like:
ADAFRUIT_ADDRESS=tcp://localhost:1883
ADAFRUIT_USERNAME=
ADAFRUIT_KEY=
Then install a local Mosquitto server and the Mosquitto client applications:
sudo apt update
sudo apt install mosquitto
sudo apt install mosquitto-clients
Finally, start the subscriber client on a terminal, and run the program on a different one:
# on terminal A
mosquitto_sub -v -t "user/feeds/temperature"
# on terminal B
./mqtt
Instead of generating a random temperature each time the program is run, you could easily use the SHT21 sensor to measure the real one.
Check the i2c
directory for details on setting it up.
This project relies on the [Eclipse Paho MQTT client library}(https://github.com/eclipse/paho.mqtt.c),
which is installed through Conan.