diff --git a/samples/pubsub.py b/samples/pubsub.py index a1aad6d4..1d1a4d27 100644 --- a/samples/pubsub.py +++ b/samples/pubsub.py @@ -8,6 +8,7 @@ import threading import time from uuid import uuid4 +import json # This sample uses the Message Broker for AWS IoT to send and receive messages # 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): while (publish_count <= args.count) or (args.count == 0): message = "{} [{}]".format(args.message, publish_count) print("Publishing message to topic '{}': {}".format(args.topic, message)) + message_json = json.dumps(message) mqtt_connection.publish( topic=args.topic, - payload=message, + payload=message_json, qos=mqtt.QoS.AT_LEAST_ONCE) time.sleep(1) publish_count += 1