0

I want to use hivemq as an online broker for my IOT projects BUT the problem is I am unable to connect with hiveMQ from my raspberry pi. I am even unable to open hiveMQ website from my raspberry pi.

I tried subscribing to hiveMQ broker using this basic python script


import paho.mqtt.client as mqtt

MQTT_HOST = "broker.mqttdashboard.com"

MQTT_PORT = 1883

MQTT_KEEPALIVE_INTERVAL = 5

MQTT_TOPIC = "testTopic"

def on_connect(mosq, obj, rc):
    mqttc.subscribe(MQTT_TOPIC, 0)

def on_subscribe(mosq, obj, mid, granted_qos):
    print("Subscribed to MOTT Topic...")

def on_message(mosq, obj, msg):
    print(msg.payload)

mqttc = mqtt.Client()

mqttc.on_message = on_message

mqttc.on_connect = on_connect

mqttc.on_subscribe = on_subscribe

mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL)

mqttc.loop_forever()

BUT IT IS THROWING AN ERROR:

Traceback (most recent call last):

File "subscriber.py", line 23, in <module>
    mqttc.connect(MQTT_HOST, MQTT_PORT, MQTT_KEEPALIVE_INTERVAL)

File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 686, in connect
    return self.reconnect()

File "/usr/local/lib/python3.4/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/python3.4/socket.py", line 509, in create_connection
    raise err

  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)

OSError: [Errno 113] No route to host

on the other hand i also subscribed to my local MOSQUITTO broker using the same python script just by changing the HOST to the ip of my local machine and it was working fine...

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
  • The fact you can't reach the website and that you are getting `No route to host` errors implies you have more serious network issues than anything to do with MQTT specifically – hardillb Aug 17 '16 at 15:35
  • @hardillb other than hivemq all other websites are reachable – aman sharma Aug 17 '16 at 15:46
  • Could also be related to DNS, can you try: broker.hivemq.com or broker.mqtt-dashboard.com ? – Dominik Obermaier Aug 17 '16 at 15:58
  • yes i tried that too didn't work. Isn't it some problem related to ports. I saw a blog where they ask to modify your ip table but not sure enough @DominikObermaier – aman sharma Aug 17 '16 at 16:02

0 Answers0