firmware icon indicating copy to clipboard operation
firmware copied to clipboard

[Bug]: json (payload) utf-8 characters converted to \n0000

Open GerritS76 opened this issue 1 year ago • 2 comments

Category

Other

Hardware

Heltec V3

Firmware Version

at least 2.2.4 and above

Description

When sending a message from my Mestastic node nothing seems to be wrong, the thing that does goes wrong is this. When using a MQTT Broker. As soon as utf-8 characters are used, their converted into \u0000 no matter what letter is beïng used.

Messages do arrive the correct way on other devices, but when using mosquitto_sub or any other sort of script to output the MQTT json data, it's shown as garbage. Example:

mosquitto_pub -h localhost -u {user} -P {pass} -t 'msh/3300-3329/2/json/mqtt/!{1}' -m '{"channel": 0,"from":{2},"type":"sendtext","payload":"äáàéëèóöò etc. etc."}'

Which output:

{"channel":0,"from":{1},"hops_away":0,"id":{2},"payload":{"text":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 etc. etc."},"sender":"!da5c87d4","timestamp":1712428198,"to":{3},"type":"text"}

The sent data via mosquitto_pub is correctly shown on other devices, however... exporting the data from the MQTT broker shows those \u0000's.

Looks as if Mashtastic is converting all json data into unicode (even utf-8 characters) messing the output data up.

Relevant log output

{"text":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 etc. etc."},"sender":"!da5c87d4","timestamp":1712428198,"to":{3},"type":"text"}

GerritS76 avatar Apr 06 '24 19:04 GerritS76

@GerritS76 You have ruined my dreams :) opening it again I am waiting for ages for this fix because in my language it is a lot of ąęść 😃

LOCOSP avatar Apr 26 '24 22:04 LOCOSP

I can confirm this issue also in firmware 2.3.13.83f5ba0 Beta, look like the MQTT JSON text not decode with UTF-8.

cnstudio avatar Jun 30 '24 11:06 cnstudio

Can confirm this issue still exists.

My guess is that something in this function is not quite right -- https://github.com/meshtastic/firmware/blob/master/src/mqtt/JSONValue.cpp#L833

kevinelliott avatar Jul 07 '24 11:07 kevinelliott

Specifically these lines -- https://github.com/meshtastic/firmware/blob/master/src/mqtt/JSONValue.cpp#L854-L863

kevinelliott avatar Jul 07 '24 11:07 kevinelliott

I have this problem too, I'm patiently waiting for this to be taken into account.

kiclaw avatar Aug 09 '24 16:08 kiclaw

The JSON library being used, and the JSON on device in general is limited and does not support special characters. You need to use protobufs and parse json externally for full functionality.

garthvh avatar Aug 13 '24 14:08 garthvh

This issue has been mentioned on Meshtastic. There might be relevant details there:

https://meshtastic.discourse.group/t/sending-json-text-via-mqtt/12030/9

meshtastic-bot avatar Oct 14 '24 19:10 meshtastic-bot