Skip to content

Adjust MQTT5 samples to output JSON #434

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 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion samples/mqtt5_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
from concurrent.futures import Future
import time
import json

TIMEOUT = 100
topic_filter = "test/topic"
Expand Down Expand Up @@ -131,7 +132,7 @@ def on_lifecycle_connection_failure(lifecycle_connection_failure: mqtt5.Lifecycl
print("Publishing message to topic '{}': {}".format(message_topic, message))
publish_future = client.publish(mqtt5.PublishPacket(
topic=message_topic,
payload=message_string,
payload=json.dumps(message_string),
qos=mqtt5.QoS.AT_LEAST_ONCE
))

Expand Down
3 changes: 2 additions & 1 deletion samples/mqtt5_shared_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import threading
from concurrent.futures import Future
import time
import json

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