1

嗨,我也在使用 Hivemq (windows) 并且有一个问题!

websocket 已打开,我收到一些信息:

2017-01-19 11:05:27,065 INFO  - Starting HiveMQ Server
2017-01-19 11:05:27,070 INFO  - HiveMQ version: 3.2.1
2017-01-19 11:05:27,074 INFO  - HiveMQ home directory: C:\hivemq-3.2.1
2017-01-19 11:05:27,115 INFO  - Log Configuration was overridden by C:\hivemq-3.2.1\conf\logback.xml
2017-01-19 11:05:31,533 INFO  - Loaded Plugin HiveMQ JMX Metrics Reporting Plugin - v3.0.0
2017-01-19 11:05:31,534 INFO  - Loaded Plugin HiveMQ JVM Metrics Plugin - v3.1.0
2017-01-19 11:05:31,535 INFO  - Loaded Plugin HiveMQ MQTT Message Log Plugin - v3.0.0
2017-01-19 11:05:31,551 INFO  - JMX Metrics Reporting started.
2017-01-19 11:05:31,574 INFO  - Starting TCP listener on address 127.0.0.1 and port 1883
2017-01-19 11:05:31,701 INFO  - Starting Websocket listener on address 127.0.0.1 and port 9001
2017-01-19 11:05:31,705 INFO  - Started TCP Listener on address 127.0.0.1 and on port 1883
2017-01-19 11:05:31,706 INFO  - Started Websocket Listener on address 127.0.0.1 and on port 9001
2017-01-19 11:05:31,707 INFO  - Started HiveMQ in 4637ms
2017-01-19 11:05:31,708 INFO  - No valid license file found. Using evaluation license, restricted to 25 connections.
2017-01-19 11:05:46,058 INFO  - Client mosq/@IL\R8\7_1OBQj3hs@ connected
2017-01-19 11:05:46,138 INFO  - Subscribe from client mosq/@IL\R8\7_1OBQj3hs@ received: domoticz/in QoS: 0
2017-01-19 11:05:49,867 INFO  - Client mosq/@IL\R8\7_1OBQj3hs@ sent a message to topic "domoticz/out": "{
   "Battery" : 100,
   "RSSI" : 7,
   "description" : "",
   "dtype" : "Temp + Humidity",
   "id" : "62721",
   "idx" : 3,
   "name" : "bureau",
   "nvalue" : 0,
   "stype" : "THGN122/123, THGN132, THGR122/228/238/268",
   "svalue1" : "19.0",
   "svalue2" : "34",
   "svalue3" : "2",
   "unit" : 1
}
" (QoS: 0, retained: false)
2017-01-19 11:06:05,761 INFO  - Client mosq/@IL\R8\7_1OBQj3hs@ sent a message to topic "domoticz/out": "{
   "Battery" : 100,
   "RSSI" : 7,
   "description" : "",
   "dtype" : "Temp + Humidity",`enter code here
`

但我总是在 chrome 控制台中遇到问题:

`WebSocket connection to 'ws://127.0.0.1:9001/' failed: Connection closed before receiving a handshake response
k._doConnect @ mqttws31-min.js:36
k._disconnected @ mqttws31-min.js:54
k._on_socket_error @ mqttws31-min.js:51
(anonymous) @ mqttws31-min.js:19e

我不是专家请帮忙

4

1 回答 1

4

根据 Eclipse Paho Wiki

在 MQTT 连接上指定的 url 的路径部分应该是“mqtt”,例如 ws://m2m.eclipse.org:800/mqtt。mqtt 应该是默认的,可以选择配置/指定替代方案

但是 paho javascript 使用的默认路径是“/ws”

HiveMQ 使用“/mqtt”的默认配置作为 websocket 的路径

可能的解决方案是

  • 将客户端中的路径更改为“/mqtt”

    client = new Paho.MQTT.Client("127.0.0.1", Number(9001), "/mqtt", "clientId");
    
  • 将 HiveMQ 配置中的路径更改为“/ws”

    <websocket-listener>
    ...
      <path>/ws</path>
    ...
      </websocket-listener>
    

问候,

Florian,来自 HiveMQ 团队。

于 2017-01-20T10:55:28.300 回答