【发布时间】:2022-02-05 18:49:28
【问题描述】:
客户端
当我尝试将运行 ngx-mqtt 的 Angular 应用程序连接到具有公共 IP 地址的 mqtt 代理时,我最终在浏览器 (Firefox) 控制台日志中收到这些错误:
这是使用 ngx-mqtt 在我的 Angular 应用上设置连接详细信息的方式:
export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions =
{
hostname: '<BROKER IP ADDRESS>',
username: '<BROKER USERNAME>',
password: '<BROKER PASSWORD>',
port: 9001,
// protocol: 'ws',
// path: '/mqtt'
};
它们与我在 mqtt 代理电脑上创建的详细信息相匹配。
代理/服务器端
在我使用的 mqtt 代理上mosquitto
我已经配置了 mosquitto.conf 文件,确保 websockets 已启用,并且正确的端口 9001 作为额外的侦听器与默认的 mqtt 侦听器和端口 1883 一起打开。
# 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
allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
listener 9001
protocol websockets
保存 mosquitto.conf 文件并重新启动 mosquitto 后,我运行 mosquitto 命令并得到以下输出,它只说默认 1883 端口是打开的:
根据this blog 运行命令 mosquitto -c /etc/mosquitto/mosquitto.conf 应该给我输出,告诉我端口 9001 已打开并正在侦听,并且是从 mosquitto 加载的。 conf文件。
但是当我运行该命令时,我没有得到任何输出。
我什至尝试确保为端口 9001 启用了防火墙和端口转发。
我也尝试过in this question 建议的一些事情。但无论我尝试什么,我都无法让 websockets 在这个面向公众的 IP mqtt 代理上工作。
奇怪的是,如果我尝试通过本地网络 mqtt 代理执行此操作,它工作正常,只有当我尝试连接到公共 IP mqtt 代理时,我才会遇到这些问题。
如果它有助于运行的 LAN mqtt 代理是运行 raspberry pi os 的树莓派 3,而公共 IP WAN mqt 代理在英特尔 nuc 上运行 ubuntu。
如果有人可以提供帮助,将不胜感激。
【问题讨论】:
-
请不要发布文字图片,始终发布实际文字,然后使用工具栏对其进行格式化。图片无法搜索,通常难以阅读,对需要使用屏幕阅读器的用户来说毫无用处。
标签: angular mqtt mosquitto messagebroker mqtt.js