You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have noticed that received payloads are consistently corrupted with an extra byte at the front, when certain message properties are set on the publishing side. It seems to be related to the total length of the attached properties. I have verified that the bug is on the receiving side rather than the sending side, because other MQTT clients subscribed to the topic do not see any problem with the received payloads.
I'm using the latest release in PyPI.
The following code demonstrates the problem:
import logging
from typing import List
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
import paho.mqtt.client as mqtt
from paho.mqtt.packettypes import PacketTypes
import uuid
import json
import sys
port = 1883
host = 'mqtt.eclipse.org'
username = None
password = None
id = str(uuid.uuid4())
req_topic = "%s/req" % id
resp_topic = "%s/resp" % id
payload: bytes = '{"value": "this is just a test request #0"}'.encode('utf-8')
n_received: int = 0
def on_connect(client: mqtt.Client, userdata, flags, rc: mqtt.ReasonCodes, properties: mqtt.Properties):
logger.debug("on_connect: Connected with result code %s" % rc.getName())
client.subscribe(req_topic)
def on_subscribe(client: mqtt.Client, userdata, mid, rc: List[mqtt.ReasonCodes], properties: mqtt.Properties):
logger.debug("on_subscribe: subcription acked with mid=%s, rc=%s" % (mid, [x.getName() for x in rc]))
client.publish(req_topic, payload=payload, qos=1)
properties = mqtt.Properties(PacketTypes.PUBLISH)
properties.ContentType = 'application/json'
properties.ResponseTopic = resp_topic
properties.CorrelationData = b' 0'
properties.UserProperty = [('ts', '2021-07-14T07:09:40.365778Z'), ('start_ts', '2021-07-14T07:09:40.208527Z'), ('seq', '2')]
client.publish(req_topic, payload=payload, qos=1, properties=properties)
def on_message(client: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
global n_received
logger.info("on_message %s: props=%s: [%s]" % (msg.topic, str(msg.properties), str(msg.payload)))
n_received += 1
if repr(msg.payload) != repr(payload):
logger.error("Data Corruption! Received payload %s does not match published payload %s" % (msg.payload, payload))
if n_received == 2:
client.disconnect()
client = mqtt.Client(protocol=mqtt.MQTTv5)
client.on_connect = on_connect
client.on_message = on_message
client.on_subscribe = on_subscribe
client.enable_logger()
if not username is None:
client.username_pw_set(username, password=password)
logger.info('Connecting to MQTT broker at %s:%d' % (host, port))
client.connect(host, port=port)
client.loop_forever()
The text was updated successfully, but these errors were encountered:
I have noticed that received payloads are consistently corrupted with an extra byte at the front, when certain message properties are set on the publishing side. It seems to be related to the total length of the attached properties. I have verified that the bug is on the receiving side rather than the sending side, because other MQTT clients subscribed to the topic do not see any problem with the received payloads.
I'm using the latest release in PyPI.
The following code demonstrates the problem:
The text was updated successfully, but these errors were encountered: