I did a search but found little info with regards of using TLS with MQTT Plugins. I have finally added TLS to my MQTT broker for additional security. Now I need to modfify my HR .hrp to utilize it. Is anyone out there using this combination and if so, would you mind sharing some knowledge? Thanks
In case of any future interest, I was able to get my plugin to work with TLS. For my MQTT Plugin device, under “settings” I added a field for “TLS” as well as one for “ClientId” (ClientId not needed for TLS, just something I wanted to add). Then in my script, I added some new variables for the various Settings data.
var host = plugin.Settings[“Host”];
var port = plugin.Settings[“Port”];
var client = plugin.Settings[“Client”];
var username = plugin.Settings[“Username”];
var password = plugin.Settings[“Password”];
var tls = plugin.Settings[“TLS”];
Lastly, I put an if / else in my onConnect function.
function onConnect() {
if(tls) {
console.log(“TLS is true”);
mqtt.connect(“mqtts://” + username + “:” + password + “@” + host + “:” + port, {clientId:client, rejectUnauthorized:false});
} else {
console.log(“TLS is false”);
mqtt.connect(“mqtt://” + username + “:” + password + “@” + host + “:” + port, {clientId:client});
}
subscribed = false;
//console.log(“connected”);
}
Not really sure why this works, as I did not copy any “cert” files to my phone or add any to the HR .hrp file. Although a bit outdated, I actually used what Bill has posted on the website: