Skip to content

Allow publishing of bytes messages #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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