0

Please find the script that I am trying to run below:

def initialize(global_listener):
   global MQTT_CLIENT
   global SUBSCRIBERS_ACTIVE_COUNT
   SUBSCRIBERS_ACTIVE_COUNT = 0
   MQTT_CLIENT = setup_mqtt_client()
   global_listener.set_client(MQTT_CLIENT)
   subscribe_and_listen(MQTT_CLIENT)


def subscribe_and_listen(client):
   # Start subscribe, with QoS level 1
   global UUID
   client.subscribe(str(UUID), 1)
   client.subscribe("status_channel", 1)
   client.subscribe("status_channel/"+str(UUID), 1)

   rc = 0
   while rc == 0:
     rc = client.loop()
     handle_exception(client=client, rc=rc)
     LOG.debug("rc: " + str(rc))

 def setup_mqtt_client():
     client = paho.Client(client_id=UUID, clean_session=True, userdata=None,           protocol=paho.MQTTv31)
     # Assign event callbacks
     client.on_message = on_message
     client.on_connect = on_connect
     client.on_disconnect = on_disconnect
     client.on_publish = on_publish
     client.on_subscribe = on_subscribe
     client.on_log = on_log
     client.will_set("status_channel/ws_hot",     payload=get_last_will_payload(UUID), qos=1, retain=False)
     url = urlparse.urlparse(os.environ.get('CLOUDMQTT_URL', 'tcp://<mqtt-server-ip>:1883'))

     # Connect
     client.username_pw_set("<username>", "<password>")
     client.connect(url.hostname, url.port)#, keepalive=20)

     return client

But on running the above script I am getting the following error:

Traceback (most recent call last):
   File "src/mqtt_client.py", line 142, in <module>
     initialize(JOB_HANDLER)
   File "src/mqtt_client.py", line 115, in initialize
     MQTT_CLIENT = setup_mqtt_client()
   File "src/mqtt_client.py", line 106, in setup_mqtt_client
     client.connect(url.hostname, url.port)#, keepalive=20)
   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
socket.error: [Errno 113] No route to host

I couldn't find the answer anywhere. Please help.

P.S. : I have tried disabling firewall and clearing out iptables on raspberry pi to not relief.

  • try url without the tcp:// prefix – Priyank Mehta Mar 09 '17 at 10:50
  • @PriyankMehta Didn't work! – Shikhar Srivastava Mar 09 '17 at 11:22
  • Have you checked that url.host is actually what you expect it to be? Can you ping that address from the command line? – hardillb Mar 09 '17 at 12:56
  • @hardillb I had done the basic debugging only then I posted a question here. I had tried pinging the host using a windows machine using same script and it was working seamlessly. So what I finally figured out that there are some configuration related problems with Pixel, which have been solved in latest release and can be resolved by doing a firmware update. – Shikhar Srivastava Mar 10 '17 at 22:09

1 Answers1

0

There is some issue with Raspberry Pi Jessie distribution with Pixel. Running the following command to update firmware solved my problem

rpi-update

This may take upto 10-15 minutes for full update to complete. Bare with it, and reboot after doing the firmware update