10

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
Lii
  • 11,553
  • 8
  • 64
  • 88
Mercury
  • 1,886
  • 5
  • 25
  • 44

2 Answers2

11

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
njh
  • 783
  • 3
  • 15
10

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.

ralight
  • 11,033
  • 3
  • 49
  • 59