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

"Steve Mullock" <sjmeclipse@xxxxxxxxxx> writes:

> 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 
> documentation?

> 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? 

My guess is that mosquitto_sub, essentially a C/C++ program written to
the POSIX interface, is calling the stdio equivalent of write(2) with
the 13 bytes, and the operating system is doing some sort of CRLF
processing, perhaps in an attempt to bridge between Unix conventions in
the POSIX world and Windows conventions.

So you might write a simple C program that does

  s = [array with the bytes you want]
  printf("%s", s);

and see what you get in the file.


It's possible that some Windows-specific calls might be able to
configure the stdio layer to not do this processing, although others
might like it.  Whether this translation happens depends on whether the
payload is binary or text, and mosquitto_sub doesn't know that.

While MQTT doesn't require any payload format, the mosquitto_{pub,sub}
world and many uses tend to having payload be text and often JSON, so I
think you are operating on a path that is not well trodden.

(I don't use Windows at all.)

Greg

Attachment: signature.asc
Description: PGP signature


Back to the top