mqttshot is a versatile little program for publishing and receiving images over MQTT.
Offer flexible image acquisition from different sources. You can currently choose from File, URL and STDIN.
Use base64 for encoding the image, it feels safer than "just binary" and can be used to encapsulate the image into a message container.
Use JSON as message container format, as you usually want to send more data along. In the current implementation, the message structure is very simple and not restricted by any schema:
{ "text": "The car is on fire!", "image": "/9j/4AAQSkZJRgAB ... JooA/9k=", "alert": true }
Please consider this as a proposal about a simple convention of how to send basic messages containing images over MQTT. We will be happy if this of any interest for you and love to hear back from you.
This was built to support the creation of a new feature for mqttwarn, namely Add support for Pushover image attachments.
$ mqttshot --help Usage: mqttshot --topic= --image= [--broker=] [--text=] [--alert] mqttshot --example [--broker= --topic= --text= --image= --alert] mqttshot --version mqttshot (-h | --help) Examples: # Run example out of the box: Publish a message with an image # to a MQTT broker running on "localhost" to the topic "testdrive" mqttshot --example # Publish image acquired from filesystem with text from command line argument # to specified topic and also raise the "alert" flag mqttshot --topic='testdrive/home' --text='The house is on fire!' --image='/var/spool/house-on-fire.jpg' --alert # Publish image acquired from STDIN cat test.jpg | mqttshot --topic='testdrive/pipe' --image=- # Publish image acquired from HTTP URL mqttshot --topic='testdrive/url' --image='https://images.unsplash.com/photo-1503022932596-500eb8cca2d8?w=100&q=10'
Get source code:
git clone https://github.com/daq-tools/mqttshot cd mqttshot
Create and activate a Python virtualenv:
virtualenv .venv27 source .venv27/bin/activate
Install mqttshot in development mode:
python setup.py develop
There are other discussions and projects about sending and receiving images over MQTT.
- https://github.com/suknuk/MQTT-Images
- https://play.google.com/store/apps/details?id=it.barbaro.zanzito
- How to Send a File Using MQTT Using a Python Script
Node-RED
Home Assistant
Hortonworks