简体   繁体   English

如何在MQTT中使用SSL \\ TLS属性

[英]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. 我正在使用以下代码使用MQTT协议连接到云,但是我不知道如何使用SSL \\ TLS属性进行连接。

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);
});

Looking at the doc it doesn't look like kontakt supports MQTT over websockets. 查看该文档 ,看来kontakt似乎不支持Websocket上的MQTT。

Change the URI in the connect line to start with mqtts:// not wss:// 更改连接行中的URI以mqtts://而不是wss://开头

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM