#!/usr/bin/env python3
import paho.mqtt.client as mqtt
client.subscribe("test/#")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_message = on_message
client.connect("localhost", 1883, 60)
client.loop_forever()
When I receive a message it always adds a "b" to the message: test/temperature b 'test'
I got the solution: "bXXX" means bytes. You need to convert this to UTF-8 before using it:
msg.payload = msg.payload.decode("utf-8")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.