Add clientid/username/password to MQTT nodes

Alternative implementation, closes #42

The username/password as not stored in the main flow file for security reasons;
they are stored in the adjacent credentials file. This does mean an extra step
to importing an MQTT node, as the user has to manually edit it to re-add username
and password if needed.
This commit is contained in:
Nicholas O'Leary
2013-11-25 22:50:08 +00:00
parent 796080471d
commit 7040aaa179
3 changed files with 108 additions and 8 deletions

View File

@@ -25,13 +25,16 @@ function matchTopic(ts,t) {
}
module.exports = {
get: function(broker,port) {
var id = broker+":"+port;
get: function(broker,port,clientid,username,password) {
var id = "["+(username||"")+":"+(password||"")+"]["+(clientid||"")+"]@"+broker+":"+port;
if (!connections[id]) {
connections[id] = function() {
var client = mqtt.createClient(port,broker);
client.setMaxListeners(0);
var options = {keepalive:15,clientId:'mqtt_' + (1+Math.random()*4294967295).toString(16)};
var options = {keepalive:15};
options.clientId = clientid || 'mqtt_' + (1+Math.random()*4294967295).toString(16);
options.username = username;
options.password = password;
var queue = [];
var subscriptions = [];
var connecting = false;