我正在尝试在一台 Linux 设备上运行两个单独的代理。
我使用以下小脚本设置了两个代理(为了便于阅读,省略了第二个脚本,因为它是相同的,除了结尾的 IoT 更改为 HA 并且端口为 1884):
temp_file=/tmp/mosquittoIoT.conf
cat <<EOF > $temp_file
listener 1883
allow_anonymous false
password_file /etc/mosquitto/conf.d/brokerIoT/credentialsIoT
connection bridge_to_target
address 192.168.0.2:1884 # Assuming the target broker is running on port 1884
topic cmnd/# both 0
log_dest file /var/log/mosquitto/mosquitto.log
log_type all
EOF
sudo mv $temp_file /etc/mosquitto/conf.d/brokerIoT/mosquittoIoT.conf
temp_file=/tmp/mosquittoIoT.service
cat <<EOF > $temp_file
[Unit]
Description=Mosquitto MQTT Broker IoT
[Service]
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/conf.d/brokerIoT/mosquittoIoT.conf
[Install]
WantedBy=multi-user.target
EOF
sudo mv $temp_file /etc/systemd/system/mosquittoIoT.service
我正在尝试同步两个经纪人之间的
cmnd
主题和所有子主题,但我不断收到错误
1726351450: Sending SUBACK to 65bBPKjODcW8Zcq1BtKjiL
1726351453: Bridge local.piserver.bridge_to_target doing local SUBSCRIBE on topic cmnd/#
1726351453: Connecting bridge (step 1) bridge_to_target (192.168.0.2:1883)
1726351453: Connecting bridge (step 2) bridge_to_target (192.168.0.2:1883)
1726351453: Bridge piserver.bridge_to_target sending CONNECT
1726351453: New connection from 192.168.0.2:58414 on port 1883.
1726351453: Sending CONNACK to 192.168.0.2 (0, 5)
1726351453: Client <unknown> disconnected, not authorised.
1726351453: Received CONNACK on connection local.piserver.bridge_to_target.
1726351453: Connection Refused: not authorised
1726351453: Client local.piserver.bridge_to_target closed its connection.
1726351453: Sending PUBLISH to mqtt-explorer-5de5cf70 (d0, q0, r0, m0, '$SYS/broker/connection/piserver.bridge_to_target/state', ... (1 bytes))
1726351455: Received PUBLISH from 65bBPKjODcW8Zcq1BtKjiL (d0, q0, r0, m0, 'homeassistant/status', ... (6 bytes))
1726351455: Sending PUBLISH to mqtt-explorer-5de5cf70 (d0, q0, r0, m0, 'homeassistant/status', ... (6 bytes))
1726351457: Bridge local.piserver.bridge_to_target doing local SUBSCRIBE on topic cmnd/#
1726351457: Connecting bridge (step 1) bridge_to_target (192.168.0.2:1884)
1726351457: Connecting bridge (step 2) bridge_to_target (192.168.0.2:1884)
1726351457: Bridge piserver.bridge_to_target sending CONNECT
1726351457: New connection from 192.168.0.2:52406 on port 1884.
1726351457: Sending CONNACK to 192.168.0.2 (0, 5)
1726351457: Client <unknown> disconnected, not authorised.
1726351457: Received CONNACK on connection local.piserver.bridge_to_target.
1726351457: Connection Refused: not authorised
1726351457: Client local.piserver.bridge_to_target closed its connection.
我不明白为什么会出现授权问题。两个经纪商使用相同的用户名和密码。我可以与 MQTT Explorer 连接,并且我的设备正在成功向两个代理发送数据。这似乎只是桥上的问题。
有人看到我做错了什么吗?
谢谢大家 亚历克斯
您需要在配置文件中指定
local_user
、local_password
、remote_user
和 remote_password
,以便代理知道在桥的两端使用哪些凭据。