您好我也在使用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
我不是专家,请帮忙
答案 0 :(得分: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团队。