Skip to content

Commit f107ecf

Browse files
authored
Json message (#214)
If the MQTT payload is a string the AWS MQTT test client shows a "Message cannot be displayed in specified format." warning. Description of changes: Changed the payload to json to prevent the aforementioned warning/error.
1 parent 0450ce6 commit f107ecf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

samples/pubsub.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import threading
99
import time
1010
from uuid import uuid4
11+
import json
1112

1213
# This sample uses the Message Broker for AWS IoT to send and receive messages
1314
# through an MQTT connection. On startup, the device connects to the server,
@@ -155,9 +156,10 @@ def on_message_received(topic, payload, dup, qos, retain, **kwargs):
155156
while (publish_count <= args.count) or (args.count == 0):
156157
message = "{} [{}]".format(args.message, publish_count)
157158
print("Publishing message to topic '{}': {}".format(args.topic, message))
159+
message_json = json.dumps(message)
158160
mqtt_connection.publish(
159161
topic=args.topic,
160-
payload=message,
162+
payload=message_json,
161163
qos=mqtt.QoS.AT_LEAST_ONCE)
162164
time.sleep(1)
163165
publish_count += 1

0 commit comments

Comments
 (0)