MQTT: Failed to publish message: rc=4

userHead Matha.Goram 2024-08-26 16:24:42 147 Views1 Replies

My simply Python script running on UNIHIKER can publish to another MQTT broker on the LAN. But it cannot publish to the local UNIHIKER MQTT broker! The code fails with the following error messages (my custom debugging messages):

 

INFO:root:Connected to broker

                client.username_pw_set(username, password)

               client.connect(<unihiker FQDN>, 1883, 60)

ERROR:root:Failed to publish message: rc=4

                       result, mid = client.publish("topic", payload=message, qos=1
 

result == 4
BAD CREDENTIALS: <default values as in json file>
 

I've checked and convinced myself that I haven't fat-fingered the credentials from the config.json file in my Python script. Something is being published, but not my message. The published messages are a series of integers (when I subscribe with topic="#" either with a Python script or Node-RED as well as the command line output) but it is not the message string defined in my Python script.

 

Is there any other reason for the result error code = 4 to be returned by the publish function? Thanks.

 

Regards.

 

P.S.

I've looked at the following debug steps, but I could not spot my mistake:

- Used Wireshark but could not identify any connection failure because request/response does occur- Tested with a Different Broker on the LAN and was successful- Don't expect any Rate Limiting for single publish requests- Verified topic: assuming that there are no limitations on UNIHIKER for this except that the syntax for the topic string has to be MQTT compliant
2024-08-26 17:36:27

RESOLVED:

 

Callback differences between MQTT v3.1 and MQTT v5.0 caused the issue.

 

These challenges owing to buster will persist, IMHO.

userHeadPic Matha.Goram