Skip to content

Commit

Permalink
Merge pull request #84 from PhearZero/patch-1
Browse files Browse the repository at this point in the history
Allow publishing of bytes messages
  • Loading branch information
brentru authored Jul 7, 2021
2 parents 3c82dda + 58a4421 commit eccc36f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def ping(self):
def publish(self, topic, msg, retain=False, qos=0):
"""Publishes a message to a topic provided.
:param str topic: Unique topic identifier.
:param str,int,float msg: Data to send to the broker.
:param str,int,float,bytes msg: Data to send to the broker.
:param bool retain: Whether the message is saved by the broker.
:param int qos: Quality of Service level for the message, defaults to zero.
Expand All @@ -572,6 +572,8 @@ def publish(self, topic, msg, retain=False, qos=0):
msg = str(msg).encode("ascii")
elif isinstance(msg, str):
msg = str(msg).encode("utf-8")
elif isinstance(msg, bytes):
pass
else:
raise MMQTTException("Invalid message data type.")
if len(msg) > MQTT_MSG_MAX_SZ:
Expand Down

0 comments on commit eccc36f

Please sign in to comment.