hi, I’m using the HiveMQ ‘Getting started’ code example using MQTT.JS over a web browser (Chrome) in a React app and I get this error.
WebSocket connection to ‘wss://localhost:8883/’ failed:
I also get the error when I use port: 8884 and I even get it when I use protocol WS.
my code looks like this:
import React, { useEffect } from 'react'
import * as mqtt from 'mqtt'
const ReactComponent = ()=> {
var options = {
host: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.s1.eu.hivemq.cloud',
port: 8883,
protocol: 'mqtts',
username: 'myname',
password: 'mypassword'
}
useEffect(() => {
let client = mqtt.connect(options)
client.on('connect', function() {
console.log('Connected')
// Subscribe to a topic
client.subscribe('testing', function(err) {
if (!err) {
// Publish a message to a topic
client.publish('testing', 'Hello mqtt')
}
})
})
}, [])
Does anyone know what could be happening wrong?