【问题标题】:Node-Red MQTT publish node fails to connect to mosquitto broker when websockets are enabled启用 websocket 时,Node-Red MQTT 发布节点无法连接到 mosquitto 代理
【发布时间】:2021-11-29 15:42:21
【问题描述】:

Mosquitto 配置:

per_listener_settings true
listener 1883
protocol mqtt
listener 9001
protocol websockets
require_certificate false
log_type all
allow_anonymous true

在 Node-Red 中,我有一个 MQTT 发布节点设置为发布到 localhost:1883。

当我在没有 listener 9001protocol websockets 行的情况下运行 mosquitto 时,node-red 成功连接并发布到主题。但是我需要 websockets 来响应应用程序。当我在端口 9001 上使用 websockets 运行它时,我在 mosquitto 中收到以下错误:

New connection from 127.0.0.1:61482 on port 1883.
Sending CONNACK to nodered_7b952a504a975460 (0, 5)
Client nodered_7b952a504a975460 disconnected, not authorised.

我什至尝试使用 websocket 作为 node-red 发布节点的 url,如下所示: ws://localhost:9001ws://localhost:9001/mqtt。两者都不起作用。

我必须做些什么才能通过本地 mosquitto 代理从 node-red 发布到我的 react 应用程序?

【问题讨论】:

  • 你运行的是什么版本的 Node-RED 和 mosquitto?
  • 蚊子 2.0.14。 Node-RED 2.1.3。

标签: websocket mqtt node-red mosquitto


【解决方案1】:

我不得不从配置文件中删除per_listener_settings true。起初我没有意识到我有它。不幸的是,我不知道为什么会这样。

【讨论】:

  • 您必须这样做,因为使用per_listener_settings trueallow_anonymous true 成为每个侦听器的设置(因此您需要包含它两次,直接在listener 1883 下添加第二个条目)。
  • 由于原始配置文件中缺少问题,我们无法回答这个问题。
最近更新 更多