Anshul
Anshul

Reputation: 4548

How to use SSL\TLS properties with MQTT

I am using following code to connect to the cloud using MQTT protocol but I don't know how to connect using SSL\TLS properties.

var mqtt = require('mqtt');

var options = {
    port: 8083,
    host: 'wss://ovs.kontakt.io',
    clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
    username: 'test',
    password: '*******',
    rejectUnauthorized: false
};
var client = mqtt.connect('wss://ovs.kontakt.io', options);
client.on('connect', function() { // When connected
    console.log('connected');
    // subscribe to a topic

    // publish a message to a topic

});


client.on('error', function(err) {
  console.log(err);
});

Upvotes: 0

Views: 327

Answers (1)

hardillb
hardillb

Reputation: 59791

Looking at the doc it doesn't look like kontakt supports MQTT over websockets.

Change the URI in the connect line to start with mqtts:// not wss://

var client = mqtt.connect('mqtts://ovs.kontakt.io', options);

Upvotes: 0

Related Questions