Does mosquitto_pub convert a binary file to ASCII?

2,139 views
Skip to first unread message

Nirupama Rachuri

unread,
Mar 23, 2016, 8:34:19 PM3/23/16
to MQTT
I am quite new to MQTT protocol and I am sorry if my question sounds stupid. I am publishing an image from a device and when I subscribe to it on CLI I can see some characters which are not in the binary format. So my question is when the image is published does it by default get converted to ASCII format and then sent or is it received in the ASCII format or some other format?
The command I am giving is: 
mosquitto_pub --cafile /home/pi/nirupama/rootCA.pem --cert /home/pi/nirupama/certificate.pem --key /home/pi/nirupama/private.pem -h xxxxxxxxxxxxxx.iot.us-west-2.amazonaws.com -p 8883 -q 1 -d -t $aws/things/raspberry-pi/shadow/update -i mqtt_test -f /media/webcam/picture.jpg

Jan-Piet Mens

unread,
Mar 24, 2016, 2:20:38 AM3/24/16
to mq...@googlegroups.com
> I am publishing an image from a device and when I subscribe to it
> on CLI I can see some characters which are not in the binary format. So my
> question is when the image is published does it by default get converted to
> ASCII format and then sent or is it received in the ASCII format or some
> other format?

MQTT does no conversion on payloads, so the binary data you add to a
message will be transported in binary.

On the CLI you should probably subscribe and use output redirection to
store the received payload into a file; you can then verify you actually
got 'picture.jpg'.

-JP

Nirupama Rachuri

unread,
Mar 24, 2016, 12:46:23 PM3/24/16
to MQTT
Thank you for answering my question. Is it only by some program I will be able to receive the image. I checked the documentation wherein there's command to send a file but none to receive one. Isn't it possible to save it in a file by giving the path in the CLI?

Nicholas J Humfrey

unread,
Mar 25, 2016, 6:53:54 PM3/25/16
to mq...@googlegroups.com, Nirupama Rachuri
Hello,

No, mosquitto_sub does not have a command line option for writing to a
file. However it can be achieved by redirecting STDOUT to a file, using
the shell:

mosquitto_sub -t 'foo/bar' -C 1 -N > file.out

The -C 1 option causes the command to exit after a single message (to
avoid writing multiple images to the file).

The -N option causes the command to not append an end of line character
to the payload


nick.
> --
> To learn more about MQTT please visit http://mqtt.org
> ---
> You received this message because you are subscribed to the Google
> Groups "MQTT" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mqtt+uns...@googlegroups.com.
> To post to this group, send email to mq...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mqtt.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages