Skip to content

umqtt.simple/umqtt/simple.py MQTTClient.publish() breaks on unicode #1073

@tpbrisco

Description

@tpbrisco

I've been looking over this for a couple of weeks, and I'm struggling to find the underlying issue.

On a live MQTT session (I'm running from a RP2040 to a Mosquitto server), a mq.publish with a unicode character will break the session, eventually resulting in a Errno 104 / ECONNRESET (presumably when the input buffer is full).

The more "obvious" way to observe it is to do a mosquitto_sub on the topic, and the publish method stops transmitting data.

To observe:

mosquitto_sub -h yourserver -t homeassistant/sensor/bedroom/# -v

From a micropython:

mq.publish('homeassistant/sensor/bedroom/mytest', 'F') # works fine
mq.publish('homeassistant/sensor/bedroom/mytest' '°F') # \u0080 followed by F, appears to work
mq.publish('homeassistant/sensor/bedroom/mytest', 'F') # no data is received

subsequent/enough further publish() calls will result in the ECONNRESET

Testing against mosquitto_pub with the same topic and unicode message indicate it all works.

Somehow I think the length calculation is thrown off by the string-vs-bytes-vs-unicode thing, but haven't been able to nail it down yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    unicodeBugs and enhancements related to Unicode/UTF-8 support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions