0
import sys
import paho.mqtt.publish as publish

publish.single("paho/test/single", "boo", hostname="iot.eclipse.org")

I am using the above Python code to publish to a topic. The error I am getting is:

Traceback (most recent call last):
  File "/home/pi/bgvf.py", line 8, in <module>
    publish.single("paho/test/single", "boo", hostname="iot.eclipse.org")
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/publish.py", line 223, in single
    multiple([msg], hostname, port, client_id, keepalive, will, auth, tls, protocol, transport)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/publish.py", line 174, in multiple
    client.connect(hostname, port, keepalive)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 686, in connect
    return self.reconnect()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 808, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused

What can be the reason?

zondo
  • 19,901
  • 8
  • 44
  • 83
sam
  • 33
  • 1
  • 8

1 Answers1

-1
mqc = mqttc.Client()

mqc.on_connect = on_connect
mqc.on_message = on_message
mqc.on_publish = on_publish
mqc.connect('localhost',1883,60)

Add this code. hope this will helpfull

Robiul Islam
  • 95
  • 1
  • 2
  • 9
  • This does not answer the question, it sets up a client for sending multiple messages, the question is explicitly using the helper methods to publish 1 message (hence the method name `single`) – hardillb May 10 '18 at 16:41