【发布时间】:2020-02-13 14:09:45
【问题描述】:
我正在尝试通过 websocket 向代理发送消息。该消息包含表示传感器数据的数字,因此该消息可以是整数和浮点数的混合。当我运行代码时,我得到TypeError: payload must be a string, bytearray, int, float or None. 如何更改代码以发送包含整数和浮点数的消息?我使用 CloudMQTT 作为代理。
完整代码:
import paho.mqtt.client as mqtt
import time
client = mqtt.Client()
client.username_pw_set("User", "Password")
client.connect("Server", "Port")
num_one = 5.83
num_two = -12.46
num_three = 2
message = (num_one, num_two, num_three)
while True:
client.publish("topic", message)
time.sleep(1)
【问题讨论】:
标签: python-3.x mqtt