Skip to content

Commit 7b8fea6

Browse files
Adjust MQTT5 samples to output JSON (#434)
1 parent ff03e54 commit 7b8fea6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

samples/mqtt5_pubsub.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
from concurrent.futures import Future
88
import time
9+
import json
910

1011
TIMEOUT = 100
1112
topic_filter = "test/topic"
@@ -131,7 +132,7 @@ def on_lifecycle_connection_failure(lifecycle_connection_failure: mqtt5.Lifecycl
131132
print("Publishing message to topic '{}': {}".format(message_topic, message))
132133
publish_future = client.publish(mqtt5.PublishPacket(
133134
topic=message_topic,
134-
payload=message_string,
135+
payload=json.dumps(message_string),
135136
qos=mqtt5.QoS.AT_LEAST_ONCE
136137
))
137138

samples/mqtt5_shared_subscription.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import threading
88
from concurrent.futures import Future
99
import time
10+
import json
1011

1112
# For the purposes of this sample, we need to associate certain variables with a particular MQTT5 client
1213
# and to do so we use this class to hold all the data for a particular client used in the sample.
@@ -199,7 +200,7 @@ def on_lifecycle_disconnection(self, disconnect_data: mqtt5.LifecycleDisconnectD
199200
publish_message = f"{input_message} [{publish_count}]"
200201
publish_future = publisher.client.publish(mqtt5.PublishPacket(
201202
topic=input_topic,
202-
payload=publish_message,
203+
payload=json.dumps(publish_message),
203204
qos=mqtt5.QoS.AT_LEAST_ONCE
204205
))
205206
publish_completion_data = publish_future.result(60)

0 commit comments

Comments
 (0)