MQTT message publish on topic showing odd data formatting in workflow debug putput

Hello,
I have a device that publishes to a specific MQTT topic using byte encoded binary values (the hex version is this: “7ef455000281c1b160150000002c01000002010101002c01000002010101002c01000000000000002c01000000000000002c01000000000000002c01000000000000002c01000000000000002c010000000000007e”) but in the incoming workflow debug decoding these values I see them reformatted as something I can’t correlate against or understand the formatter being applied by the Losant debugger or payload hander. The payload.data shows as “”~\u00F4U\u0000\u0002\u00C7\u000E\u00B3`\u0012". What is this formatting? I am trying to build a payload decoder for the device, and have it working correctly decoding the hex string above, but I am unclear what JavaScript buffer() encoding should I be using to convert this binary data to hex from this debug representation.

What you’re seeing in the log is how JSON encoding handles unprintable characters in the binary data you are sending up.

Using a Function Node, you should be able to get the readable value on the payload at the property decoded as the following …

payload.decoded = Buffer.from(payload.data, 'binary').toString('hex');

Thanks for the clarification Dylan. I couldn’t find anything in your documentation covering that around the debug display/output formatting.

I’ve modified my decoder to also allow manually posting the device’s hex string payload if need be from an MQTT client as well, and it works well as intended now…

function decode_UC3xxx_modem(buffer) {
if (typeof buffer === “string”) {
buffer = Buffer.from(buffer.replace(/\s/g, “”), “hex”);
}
const reader = new BufferReader(buffer);

return {
    startFlag: reader.readUInt8(),
    type: reader.readUInt8(),
    length: reader.readUInt16LE(),
    version: reader.readUInt8(),
    timestamp: reader.readUInt32LE(),
    mobileSignal: reader.readUInt8(),
    din: reader.readBits(1),
    dout: reader.readBits(1),
    sin: array(8).map(decodeSinValue(reader)),
    endFlag: reader.readUInt8(),
}

}

// Initially convert binary byte values to hex for debugging purposes. This allows us to use any
// MQTT test client to publish a hex string into here to test with as well manually.
payload.payload_raw = Buffer.from(payload.data, ‘binary’).toString(‘hex’);
/// Now decode the hex payload representation
const result = decode_UC3xxx_modem(payload.payload_raw);
payload.payload_decoded = result;