"Streaming" MQTT Sensor Data into TempoDB
We want to store sensor data from Arduino or any other device in a time-series database like TempoDB. TempoDB offers ReST APIs that we could use to write the data series from Arduino directly into TempoDB. But that would be too easy ;)
In fact, we don't want each and every device to directly access the database. Instead, want a more generic solution that leverages the MQTT messaging protocol and the concept of message brokers.
Our Arduino publishes its sensor values already to an MQTT broker.
So how do we get the time series from CloudMQTT (or any other MQTT broker) into TempoDB?
As TempoDB does not provide a native MQTT interface (yet?), we will build a listener that is subscribed to a MQTT broker, and upon receipt of a new message, it simply writes the message into TempoDB.
The listener is based on the Ruby MQTT pub/sub client and the Ruby TempoDB client (clients for other languages are available, too):
https://gist.github.com/6790192
Deployed to Heroku as a web app:
Clone the listener web app from GitHub to your local machine.
Follow the Getting Started with Ruby on Heroku instructions to install the necessary gems and familiarize yourself with app deployment to Heroku.
Deploy the web.rb app from the cloned Git repository with git push heroku master
Start the app with heroku open
Publish MQTT messages and use TempoDB's console to verify that the values are indeed stored.
Note: In Heroku's free plan, the Dyno starts hibernating after 2 hours of inactivity (the listener's activity does not count as it is not receiving HTTP requests). As you want the sensor values to be continuously stored, you would need to make sure to keep the Heroku app alive. One way is to add a second web dyno (monthly charges). Another one is to be a bit creative (hint: cron, curl)