我正在尝试将本地 mqtt 代理连接到 DIoTY 云代理。我参考了 https://www.losant.com/blog/how-to-configure-mosquitto-bridge-to-losant 并根据需要完成了所有配置文件更改。我的 /etc/mosquitto/mosquitto.conf 看起来像
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
我在 conf.d 中创建了单独的 cloud.conf 文件
# Config file for mosquitto
# See mosquitto.conf(5) for more information.
user mosquitto
max_queued_messages 200
message_size_limit 0
allow_zero_length_clientid true
allow_duplicate_messages false
listener 1883
autosave_interval 900
autosave_on_changes false
persistence true
persistence_file mosquitto.db
allow_anonymous true
connection dioty
address mqtt.dioty.co:1883
bridge_attempt_unsubscribe false
remote_username *******
remote_password *******
start_type automatic
bridge_protocol_version mqttv311
notifications false
try_private true
bridge_insecure false
cleansession false
topic # in 0
启动broker后的Mosquitto日志如下
1608537228: mosquitto version 1.6.12 starting
1608537228: Config loaded from /etc/mosquitto/mosquitto.conf.
1608537228: Opening ipv4 listen socket on port 1883.
1608537228: Opening ipv6 listen socket on port 1883.
1608537228: mosquitto version 1.6.12 running
1608539039: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
我认为我的本地 mqtt 没有读取 .conf 文件。我该如何解决这个问题?
答案 0 :(得分:0)
您正在使用 Losant 配置来配置 DIOTY brokert,这将不起作用,因为两者是不同的 broker。
要在 mosquitto
配置中保存凭据,首先,您必须使用 mosquitto_passwd
mosquitto_passwd -c /etc/mosquitto/passwd USER PASSWORD
然后将密码文件位置添加到 mosquitto
配置并设置 allow_anonymouse=false
allow_anonymous false
password_file /etc/mosquitto/passwd
就是这样,您现在只需要使用
发布或订阅mosquitto_pub -h localhost -t "test" -m "hello world
mosquitto_sub -h localhost -t test