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...