A MQTT client which will send configured MQTT messages to keen IO as events for later analysis.
IoT data platforms are often a big investment in time and sometimes money, so often a simple MQTT set up is used. This should not prevent one from being able to perform historical analysis of data points.
See the blog article with a live example.
keenmqtt is a simple bridge which will listen for specified MQTT messages and log them on your KeenIO project. This complete history of events will allow you to:
- Create graphs of old data, such as temperature.
- Use this data to refine your system.
- Display this data to your users.
keenmqtt can be run as a standalone daemon, or used in a python program.
pip install keenmqtt
Or clone/download the repo, run python setup.py install
in the root.
Running the stand alone package requires a config file, see example/config.yaml
for a template. The CLI currently assumes that the MQTT system uses JSON messages and that all fields will be logged in the keenIO event.
After installing, run the following to log events:
keenmqtt -c config.yaml
A config file contains connection details for the MQTT broker, as well as a mapping of MQTT topic patterns to keenIO collections. For example, if you are publishing temperature events:
collection_mappings:
'temperature/+': temperature
Any number of mappings can be added.
keenMQTT has been specifically designed so that almost any part of the pipeline can be overriden or customised.
The source is well documented, see readthedocs
Example: Custom payload formats As an example; if you had a sensor which publishes an ascii format sensor reading, you can define a custom payload decoder for topics which match that sensor value as follows:
from keenmqtt import KeenMQTT
class CustomDecoder(KeenMQTT):
def decode_payload(self, topic, payload):
"""Decode a plain ASCII format sensor reading"""
if 'humidity' in topic:
event = {
"value": int(payload)
}
else:
#Assume default JSON encoding
event = KeenMQTT.decode_payload(self, topic, payload)
return event
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
0.0.1: Working version of the CLI app.
Written by Ben Howes & Richard Webb of Zoetrope
With thanks to:
- KeenIO for a super service.
- Eclipse Paho for a great MQTT client.
MIT Licence