mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user