0

I am trying out MQTT for the first time using Python and the mosquitto library. My client program is below. I'm trying to use the public demo MQTT server at http://www.mqtt-dashboard.com/subscribe. However the client code is failing, see error below. Any ideas on what's going on?

#!/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()

Error message:

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
fred basset
  • 9,774
  • 28
  • 88
  • 138
  • 4
    As a by-the-by, you should use the Paho Python client instead of mosquitto.py. The Mosquitto Python code was donated to Paho, so it's the same thing but with a very slightly different name space. Fixes and features will only go into Paho now. It's on pypi as paho-mqtt, or see http://eclipse.org/paho – ralight May 02 '14 at 21:43

1 Answers1

2

I'm not currently able to connect any client to broker.mqttdashboard.com:1883 - so this probably isn't an issue with your code.

To sanity check, have you tried connected to another broker, such as iot.eclipse.org:1883 ?

knolleary
  • 9,777
  • 2
  • 28
  • 35
  • You are correct! I could connect to the Eclipse server. Is there any way to easily view messages published by the client on that server? – fred basset May 02 '14 at 22:42
  • you could subscribe to the topic you are publishing to with another app, and see the messages that way? – Andy Piper May 07 '14 at 13:26