I am developing a Dashboard on Node-Red. I am receiving MQTT messages
This is an example of the message I can receive :
There is a field _name that I cannot control and that can contain extended UTF8 characters (as é, ê, à, ... )
in that case, Node Red provides me this :
and is not able to filter on payload keys, etc...
I am using the MQTT node-red node in version 3.0.2
I have tried all the Output options of the MQTT node without success
Do you have an idea on how I could receive MQTT messages with extended UTF8 characters and having Node Red able to decode them as UTF8 ones ?
Many thanks in advance
When this happens, could you copy the payload as JSON by using the copy value button that appears over the payload when you hover over it in the debug panel AND tell us what that value should be?
When I try to expand the msg, I have this :
When there is no special character (UTF8 only) in the field _name
Here is the full buffer :
As you can see in the buffer, I have :
the _name field contains : "Porte Entrée". The "é" is not a character in UTF8 standard. So the encoded value is 233 (Caractères ASCII)
The encoding for extended characters is most commonly
unicode which is a bit of a dogs breakfast since each character can, as I understand it, take between 1 and 4 bytes instead of the fixed 1-byte for UTF8. I think that character can also be represented in UTF16 though as well (2-bytes) as it is one of the extended latin characters.
Hmm, it IS listed in the UTF8 character set however as
c3a8. Not sure how that works to be honest.
Yes, it is defined in the ISO/IEC 8859-1 extended ASCII code page.
And here is the extract of the MQTT standard:
- Topic Names and Topic Filters are case sensitive
- Topic Names and Topic Filters can include the space character
- Topic Names and Topic Filters are UTF-8 encoded strings, they MUST NOT encode to more than 65535 bytes
And this seems to do the job for you. In a function node:
msg.payload = msg.payload.toString("latin1") return msg
It converts the input buffer to a latin1 (ISO/IEC 8859-1) encoded string.
Thanks a lot !!!!