尝试创建订阅MQTT代理并处理数据的Python脚本。但是,到目前为止,MQTT代理尚未接收到任何数据,这使得测试变得困难。
我找到了以下脚本来订阅主题并打印出有效内容,但看来我无法连接到测试代理:
import paho.mqtt.client as mqtt
broker_url = "iot.eclipse.org"
broker_port = 1883
def on_connect(client, userdata, flags, rc):
print("Connected With Result Code "+rc)
def on_message(client, userdata, message):
print("Message Recieved: "+message.payload.decode())
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(broker_url, broker_port)
client.subscribe("TestingTopic", qos=1)
client.publish(topic="TestingTopic", payload="TestingPayload", qos=1, retain=False)
client.loop_forever()
因此,我需要一些我可以订阅的MQTT代理和主题才能测试我的脚本。有什么建议可以找到我吗?
答案 0 :(得分:2)
有两种选择: