The problem is that you share settings
, but also modify them on each call. This can help:
var mqtt = require('mqtt')
, host = 'localhost'
, port = '1883';
exports.createClient = function(clientId){
var settings = {
keepalive: 30000,
protocolId: 'MQIsdp',
protocolVersion: 3,
username:'testuser',
password:'testpass'
}
if(clientId){
settings.clientId = deviceId + '-' + clientId;
}
return mqtt.createClient(port, host, settings);
}
Also you need to get deviceId
from arguments or some other legit place