Hello All!
I am attempting to connect to the Victron MQTT broker using typescript using this package mqtt - npm (npmjs.com)
This is the code I currently have (I have replaced some parts with * to hide personal information but I can assure that these details are correct):
const mqtt = require('mqtt') const TRUSTED_CA_LIST = `-----BEGIN CERTIFICATE----- *** *** *** *** *** -----END CERTIFICATE-----` function _get_vrm_broker_url(vrm_id: string) { var sum = 0 for (var i = 0; i < vrm_id.length; i++) { sum += vrm_id.charCodeAt(i) } var broker_index = sum % 128 return "mqtt" + broker_index + ".victronenergy.com" } const client = mqtt.connect('mqtts://' + _get_vrm_broker_url('*****'), { username: '*****', password: '*****', ca: TRUSTED_CA_LIST, }) client.on('connect', function () { console.log('connected') })
However when I test this in the browser I get the following error message:
WebSocket connection to 'wss://mqtt91.victronenergy.com/' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID
I hope someone can tell me where I'm going wrong and lead me in the right direction,
thank you for your time!
Josh