【发布时间】:2019-05-05 22:52:16
【问题描述】:
REVISION:请注意我现在使用的 IP 地址是 10.0.0.15,我发布到 MQTT 代理的设备是 10.0.0.122。这仍然通过终端进行。
我想我正在使用 MQTT 连接器。在遇到以下帖子中描述的问题后,我已经向前迈进了
Can't connect to localhost Mosquitto Broker with Javascript?
我现在看到以下错误。
mqttws31.js:1585 Uncaught Error: AMQJS0013E Invalid argument
169.254.118.199 for host.
at new M (mqttws31.js:1585)
at startConnect (n.js:29)
at HTMLInputElement.onclick ((index):107)
根据js文件表示匹配错误。我尝试将 IP 地址前缀为 wss://169.254.118.199 但这并不能解决问题。你知道是什么原因造成的吗?
我已经尝试了以下
wss://169.254.118.199
ws://169.254.118.199
wss://localhost
tcp://169.254.118.199
tcp://localhost
它们都产生相同的错误
这是错误指向的 mqttws31.js 中的代码。
if (arguments.length == 2) {
// host: must be full ws:// uri
// port: clientId
clientId = port;
uri = host;
var match = uri.match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?
(\/.*)$/);
if (match) {
host = match[4]||match[2];
port = parseInt(match[7]);
path = match[8];
} else {
--> this is where error is pointing throw new Error(format(ERROR.INVALID_ARGUMENT,[host,"host"]));
}
} else {
if (arguments.length == 3) {
clientId = path;
path = "/mqtt";
}
if (typeof port !== "number" || port < 0)
throw new Error(format(ERROR.INVALID_TYPE, [typeof port, "port"]));
if (typeof path !== "string")
throw new Error(format(ERROR.INVALID_TYPE, [typeof path, "path"]));
var ipv6AddSBracket = (host.indexOf(":") != -1 && host.slice(0,1) != "[" &&
host.slice(-1) != "]");
uri = "ws://"+(ipv6AddSBracket?"["+host+"]":host)+":"+port+path;
}
编辑:在打印输出中,我看到以下内容正在我的网页上发送到 Paho 客户端:
Connecting to: 10.0.0.122 on port: 8083
Using the following client value: clientID-64
我希望成功连接到 IP 地址并获取 MQTT 负载
【问题讨论】:
-
eth0 似乎有问题,当我通过可以连接的终端运行 Mosquitto 时,当我在此代码中运行时,它将连接到我的设备。设备IP其实是169.254.84.122,真的没有任何意义。此外,当我尝试在 eth0 上设置静态 ip 时,pi 不会接受它。我当时就被难住了。
-
编辑代码以将您输入
Paho.MQTT.Client(host, Number(port), clientID);的内容准确地打印到控制台,并将其添加到问题中,以便我们可以准确地看到您传递给代码的内容。 -
@hardlib 我在原始问题的底部附近添加了一个 *EDIT,显示正在发送到 Paho.MQTT.Client(host,Number(port), clientID);
-
我再次测试了,我现在解决了这个主机名错误,我现在一直有连接超时? mqttws31.js:977 WebSocket 连接到“ws://10.0.0.15:8083/mqtt”失败:连接建立错误:net::ERR_CONNECTION_TIMED_OUT
标签: javascript websocket mqtt mosquitto paho