首页 文章

为什么这个MQTT客户端示例失败?

提问于
浏览
0

我是第一次使用Python和mosquitto库尝试MQTT . 我的客户端程序如下 . 我正在尝试在http://www.mqtt-dashboard.com/subscribe使用公共演示MQTT服务器 . 但是客户端代码失败,请参阅下面的错误 . 关于发生了什么的任何想法?

#!/usr/bin/env python

import mosquitto

client = mosquitto.Mosquitto("fredtest", clean_session=True)
client.connect("broker.mqttdashboard.com", 1883)

client.publish("fred.test", "hello world", 1)

client.loop_forever()

错误信息:

C:\tmp>python mqttclient.py
Traceback (most recent call last):
  File "mqttclient.py", line 6, in 
    client.connect("broker.mqttdashboard.com", 1883)
  File "build\bdist.win-amd64\egg\mosquitto.py", line 582, in connect
  File "build\bdist.win-amd64\egg\mosquitto.py", line 657, in reconnect
  File "c:\python27\lib\socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 10060] A connection attempt failed because the connected pa
rty did not properly respond after a period of time, or established connection f
ailed because connected host has failed to respond

1 回答

  • 2

    我目前无法将任何客户端连接到broker.mqttdashboard.com:1883 - 所以这可能不是您的代码的问题 .

    要进行健全检查,您是否尝试连接到其他经纪人,例如iot.eclipse.org:1883?

相关问题