Skip to main content

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


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.

I have tried to redirect the payload into a file, but every time there is a 0x0a, a 0x0d is 
prepended to it. I have tried the switches -N and -F %p. They do not seem to help. Please can 
someone tell me if what I want to do is impossible, or have I missed something in the 

To demonstrate the problem I made a small file (MQTTtest.txt) containing the string "Line 
1\nLine 2" i.e. 13 bytes. Then two small batch files. 

For receiving:

"C:\Program Files (x86)\mosquitto\mosquitto_sub" -t ExampleTopic -C 1 -N -F %%p 1> MQTTrcd.bin 
type MQTTrcd.bin
dir MQTTrcd.bin

Please note that the double %% is required in the batch file to get a single % in the command 

For sending:

type MQTTtest.txt
dir MQTTtest.txt
"C:\Program Files (x86)\mosquitto\mosquitto_pub" -t ExampleTopic -d -f MQTTtest.txt

The "type" and "dir" commands are to confirm the file contents and length.

The sending debug information confirms that 13 bytes are sent. If I turn on the debug in the 
receiver it confirms 13 bytes are received, but the resulting file always has 14 bytes. An 
additional \r is prepended to the \n.

Is there a work-around? Have I missed something in the documentation? Should I report a bug? 

Any advice gratefully received.

Thanks for making the software available. Everything else has been going well.
Steve Mullock

Back to the top