我尝试使用mqtt.js包将我的react应用程序连接到HiveMQ,但出现此错误。
这是我用的密码
useEffect(() => {
const options: IClientOptions = {
protocol: "ws",
username: "myfirstdevice",
password: "qweqwe123",
};
const client = mqtt.connect('ws://8dedd20fc1164c8e9ce132a8a8359991.s1.eu.hivemq.cloud:8884', options);
// const client = mqtt.connect(options);
client.on('connect', function () {
console.log('Connected');
});
client.on('error', function (error) {
console.log("ERROR", error);
});
client.on('message', (topic,message,packet)=>{
console.log("RECEIVE", topic)
console.log("RECEIVE", message)
console.log("RECEIVE", packet)
});
}, []);
1条答案
按热度按时间jdg4fx2g1#
端口8884用于安全WebSocket上的MQTT
您需要将URL更改为以
wss://
而不是ws://
开头