无法从raspberry pi访问hivemq代理

时间:2016-08-17 15:29:54

标签: python linux raspberry-pi mqtt hivemq

我想使用hivemq 作为我的IOT项目的在线经纪人,但问题是我无法从我的覆盆子pi连接到hiveMQ。我甚至无法从我的覆盆子pi打开hiveMQ网站。

我尝试使用这个基本的python脚本订阅hiveMQ代理

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()

但是它出现了错误:

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

另一方面,我也使用相同的python脚本订阅了我的本地MOSQUITTO代理,只需将HOST更改为我本地机器的ip,它工作正常......

0 个答案:

没有答案