Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send binary data?

Tags:

mqtt

mosquitto

I am using Mosquito MQTT server to broadcast messages.

How can I send a binary data (not text)?

Example:

mosquitto_pub -t test -m 0x452343

Should be received as:

0100 0101 0010 011 0100 0011
like image 984
Mercury Avatar asked May 10 '16 21:05

Mercury


2 Answers

If you literally want to send that binary sequence of characters, then you can use echo to convert from a string to binary using:

echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s

This also works for the output of binary commands, such as capturing an image on a Raspberry Pi:

raspistill -o - | mosquitto_pub -h test.mosquitto.org -t 'webcam/' -s
like image 95
njh Avatar answered Oct 04 '22 18:10

njh


You could put your binary data in a file, then send the file as a message:

mosquitto_pub -t test -f file

Or you could write your own client using libmosquitto or another MQTT client library.

like image 27
ralight Avatar answered Oct 04 '22 20:10

ralight