![](/img/trans.png)
[英]Mosquitto broker setup bridge in Raspberry Pi to IoT Hub SAS token
[英]MQTT Mosquitto in bridge mode fails to deliver messages between Raspberry and Cloud
我正在尝试连接两个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上的灭蚊过程后,才能看到日志输出。
此外,Mqtt Lens创建的消息:
我以前错过了您的问题。
您的网桥正在订阅sensor/#
但是您正在发布到/sensor/data
。 这些主题彼此不匹配。 在/sensor/data
的第一个斜杠之前有一个长度为零的层次结构字符串,因此该主题深三个元素: ''
, 'sensor'
和'data'
。 ''
与您订阅的'sensor'
部分不匹配,因此不会发送任何消息。
长话短说,删除/sensor/data
中的前导斜线,它应该可以正常工作。
通过将不同的设备桥接到Google CLoud虚拟机,我发现,您需要在devices(local)配置文件中设置协议版本参数。
因此,将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做了很多工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.