Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] mosquitto_sub with binary payload

On Wed, 09 Jun 2021 14:24:21 +0100, you wrote:

> I am trying to use mosquitto_sub as a diagnostic tool to monitor binary data from a simple 
> MQTT publishing program I am working on. I am using Windows 10 and I downloaded the 32 bit 
> Windows binary.

If not told otherwise MSWindows treats files as text, and try to
use cr/lf as line ending.
Also, the ^Z (0x1a) character will often be treated as
end-of-file marker, and possibly close the pipe.

> Is there a work-around? 

1) You can use mosquitto_sub -F %x, so the pipe doesn't have to
process binary data at all. The receiving program can easily
convert that back into binary.

2) Encode the binary payload with something like base64 before
passing it to mosquitto_pub, so mosquitto_sub receives a text

3) Let the publisher provide the payload in text format, e.g.
json or xml or some other form of structured text.

4) Avoid the pipe altogether by linking the mosquitto_sub client
library into your monitoring program. It doesn't have to be C,
there are client libraries for many languages available (Python,
PHP, ...)

> Have I missed something in the documentation?

Binary payloads are allowed.

> Should I report a bug? 

Maybe. To output in binary mode on MSWindows, mosquitto_sub
should open its output file in binary mode 'bw'. I don't know if
it does that now. 
Before you submit a bug, you have to make sure the MSWindows
pipes can handle binary data properly with a small test program.
Compare mode 'w' and mode 'bw'.

Kees Nuyt

Back to the top