Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def on_subscribe(self, unused_client, unused_userdata, unused_mid,

def on_message(self, unused_client, unused_userdata, message):
"""Callback when the device receives a message on a subscription."""
payload = str(message.payload)
payload = message.payload
print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
payload, message.topic, str(message.qos)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you remove the str(message.qos) from this line too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A string formatter will automatically cast it into string. So, it could be an useless casting, but really doesn't matter. (message.qos is an int type, I guess)

The perfect printing might be like

print('Received message \'{}\' on topic \'{}\' with Qos {}'.format(
             payload.decode(), message.topic, message.qos))

But exposing type of payload could be useful to specify that it is a byte type.

Therefore, it just depends on the author's intention, just for logging or providing extra information though the log.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave as-is.


Expand Down