MQTT publish payload as binary data

I have a requirement to publish MQTT payload as binary.

The incoming parse(String message) message payload is base64 and then I am able to decode fine back to binary, but the

> interfaces.mqtt.publish(String topic, String payload)

does not seem to allow any method to notify the mqtt client to change the payload to binary before it sends.

Any help on this?

Maybe change the payload to a byte array and then send it ...

Yea, tried that and everything else like casting (String) or 'as String' on the byte array that I need to send. The publish method forced the type as String which I would think would need to know it was base64 or some other protocol to move binary via String type.

SOOOOO close to having a working native solution for Roborock and this is the last step. I managed though all the user log in stuff, tokens, subscriptions, AES encryption to get stuck here. :frowning:

1 Like

I would think UTF-8

Tried it and all of these:

   byte[] message = my binary message that is encypted.  
   String payload = new String(message, "UTF-8")
   String payload = message.encodeAsBase64()
   String payload = message as String
   String payload = (String)message
1 Like

Doesn't seem to be any tricks available in the methods provided unless "publishMqttMessage" has something hidden.

@bravenel @bobbyD any thoughts or help moving binary via mqtt publish?

Found the answer. Probably good to read the documents. You need to set the connect() to byteInterface to true and then pass the as message.encodeHex().toString()

2 Likes