Well blow me down…
I found that I could turn on debug logging, and when I did ‘Download diagnostics’, I found that the JSON payload was followed by a bunch of zeros (check the “payload”, you have to horizontally scroll a bit):
"mqtt_debug_info": {
"entities": [
{
"entity_id": "sensor.retepv_az3166_0",
"subscriptions": [
{
"topic": "RetepV_AZ3166_0/telemetry",
"messages": [
{
"payload": "{ \"pressure\" : 1028.80, \"temperature\" : 27.48, \"humidity\" : 50.61 }\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
"qos": 0,
"retain": false,
"time": "2025-09-30T18:51:12.349134+00:00",
"topic": "RetepV_AZ3166_0/telemetry"
},
{
"payload": "{ \"pressure\" : 1028.78, \"temperature\" : 27.50, \"humidity\" : 50.65 }\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
"qos": 0,
"retain": false,
"time": "2025-09-30T18:51:17.359990+00:00",
"topic": "RetepV_AZ3166_0/telemetry"
},
Those zero’s shouldn’t be a problem, right? Strings are zero-terminated…
But then I had a lightbulb moment. MQTT data is just binary data. And the receiving system can treat it however it likes. So, the zeros are basically treated as part of the message, and of course it’s not valid JSON then.
So I went back to the code to check some suspicions I got, and sure enough, there it was:
status = nxd_mqtt_client_publish(&mqtt_client, MQTT_PUBLISH_TOPIC, STRLEN(MQTT_PUBLISH_TOPIC),
(CHAR *)buffer, sizeof(buffer), 0, QOS1, NX_WAIT_FOREVER);
The code was sending sizeof(buffer) amount of bytes, and not strlen(buffer).
A quick fix fixed it:
status = nxd_mqtt_client_publish(&mqtt_client, MQTT_PUBLISH_TOPIC, STRLEN(MQTT_PUBLISH_TOPIC),
(CHAR *)buffer, strlen(buffer), 0, QOS1, NX_WAIT_FOREVER);
And now it works fine.
So, sorry if people had already started thinking and spending time on my question.
Thank you very much for at least ‘wanting to…’! I really appreciate it!
Should I note that I’m a novice with Home Assistant?
Also maybe that the AZ3166 code is not my code. ![]()
