Quiero conectarme al servidor MQTT usando Vue. Intenté algo similar a lo que encontré en Google, pero fallé.
var mqtt = require('mqtt'); var fs = require('fs'); var options = { host: '127.0.0.1', port: 8883, protocol: 'mqtts', protocolId: 'MQIsdp', ca: [fs.readFileSync('<path>/ca.crt')], key: fs.readFileSync('<path>/client.key'), cert: fs.readFileSync('<path>/client.crt'), passphrase: 'CLIENT KEY PASSPHRASE', secureProtocol: 'TLSv1_method', protocolVersion: 3 }; var client = mqtt.connect(options); const option = { port: 48883, ca: [], key: '', cert: '', clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8), protocolId: 'MQTT', useSSL: true, passphrase: 'CLIENT KEY PASSPHRASE', secureProtocol: 'TLSv1_method', protocolVersion: 4, rejectUnauthorized: false, } axios.get('/' + 'ca.crt').then(response => { option.ca = [response.data] }) axios.get('/' + 'client.key').then(response => { option.key = response.data }) axios.get('/' + 'client.crt').then(response => { option.cert = response.data }) const client = mqtt.connect('wss://url', option) failed: WebSocket is closed before the connection is established. WebSocket connection to 'wss://url' failed: