I am trying to figure out how to get a JSON payload to properly publish to my MQTT Broker. I am able to generate JSON using the examples from Codesys, but when I send that payload via MQTT there are characters that are extra or not recognized by my MQTT client. Any idea what could be causing it?
your are sending as a WSTRING which is UTF16, but your receiver is interpriting as UTF8. Change the receiver to use UTF16, or better change your sender to convert to UTF8.
You publish the entire storage space (SIZEOF) Instead of the number of bytes of actual text (StrLenA)
Are you able to dynamically change the JSON message? As in, if wsValue or iValue is linked to some real telemetry that varies over time, will the JSON message reflect these changes? I am only able to send the values that I initialize the JSON message to
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to figure out how to get a JSON payload to properly publish to my MQTT Broker. I am able to generate JSON using the examples from Codesys, but when I send that payload via MQTT there are characters that are extra or not recognized by my MQTT client. Any idea what could be causing it?
try using
and change your publish to
Thanks for the help! Everything now works as expected.
Are you able to dynamically change the JSON message? As in, if wsValue or iValue is linked to some real telemetry that varies over time, will the JSON message reflect these changes? I am only able to send the values that I initialize the JSON message to
Thanks for the help! Everything now works as expected.
Thanks for the help! Everything now works as expected.