1

我正在尝试连接两个 Mqtt Broker (Mosquitto)。我在云中的服务器上安装了一个,在本地 Raspberry Pi 上安装了另一个。Raspeberry Pi Mosquitto 应该建立与云实例的连接。这是我在 Raspberry 上的配置(/etc/mosquitto/conf.d/bridge.conf):

connection crowdomat-cloud
address <myserver-hostname>
clientid crowdomat
start_type automatic
cleansession false
notifications true

#
# Send all messages from local /sensor topic to remote /sensor topic
#
topic # both 0 sensor/ sensor/

我可以直接连接到代理并发送和接收消息。我还看到在日志文件中建立了连接,但在代理之间没有传递任何消息。

1411577927: mosquitto version 1.3.4 (build date 2014-08-22 06:10:51+0000) starting
1411577927: Config loaded from /etc/mosquitto/mosquitto.conf.
1411577927: Opening ipv4 listen socket on port 1883.
1411577927: Opening ipv6 listen socket on port 1883.
1411577927: Warning: Address family not supported by protocol
1411577927: Bridge crowdomat doing local SUBSCRIBE on topic sensor/#
1411577927: Connecting bridge crowdomat-server (my-server:1883)
1411577927: Bridge crowdomat sending CONNECT
1411577927: Received CONNACK on connection crowdomat.
1411577927: Bridge crowdomat sending SUBSCRIBE (Mid: 466, Topic: sensor/#, QoS: 0)
1411577927: Received PUBACK from crowdomat (Mid: 465)
1411577927: Received SUBACK from crowdomat
1411577986: Sending PINGREQ to crowdomat
1411577986: Received PINGRESP from crowdomat
1411578046: Sending PINGREQ to crowdomat
1411578046: Received PINGRESP from crowdomat
1411578069: Received PUBLISH from crowdomat (d0, q0, r0, m0, '/sensor/data', ... (14 bytes))
1411578106: Sending PINGREQ to crowdomat
1411578106: Received PINGRESP from crowdomat
1411578166: Sending PINGREQ to crowdomat
1411578166: Received PINGRESP from crowdomat
1411578193: mosquitto version 1.3.4 terminating
1411578193: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.

有任何想法吗?

另一个谜团是,只有在 Raspberry Pi 上关闭 mosquitto 进程后,我才能看到日志输出。

此外由 Mqtt Lens 创建的消息:

在此处输入图像描述 在此处输入图像描述

4

2 回答 2

1

我之前在你的问题中错过了这个。

您的网桥正在订阅,sensor/#但您正在发布到/sensor/data. 这些主题彼此不匹配。在 的第一个斜杠之前有一个零长度的层次结构字符串/sensor/data,因此该主题的深度为三个元素:'''sensor''data'''与您订阅的部分不匹配'sensor',因此不会发送任何消息。

长话短说,删除前导斜杠/sensor/data,它应该可以正常工作。

于 2014-09-24T21:51:18.483 回答
1

通过将不同设备桥接到 Google CLoud 虚拟机,我发现您需要在设备(本地)配置文件中设置协议版本参数。

因此,将 bridge_protocol_version 版本添加到 RPi 上的 mosquitto.conf 文件中,像这样用于连接到云的桥接(这个对我有用):

bridge_protocol_version mqttv311

你也可以像这样在 mosquttio 上强制你的配置文件:

mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf

with mosquitto.conf being the valid configuration file. 

如果您有任何问题,请写下我在 mosquitto 和 mqtt 方面做了很多工作。

于 2017-04-10T08:33:41.863 回答