mirror of https://github.com/node-red/node-red.git
Merge c1420b2898
into 848a69dc26
commit
6c68193db3
|
@ -27,6 +27,14 @@
|
|||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-user"><i class="icon-user"></i> Username</label>
|
||||
<input type="text" id="node-input-username" placeholder="Username">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-lock"></i> Password</label>
|
||||
<input type="password" id="node-input-password" placeholder="Password">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mqtt in">
|
||||
|
@ -40,7 +48,9 @@
|
|||
defaults: {
|
||||
name: {value:""},
|
||||
topic: {value:"",required:true},
|
||||
broker: {type:"mqtt-broker", required:true}
|
||||
broker: {type:"mqtt-broker", required:true},
|
||||
username: {type:"mqtt-username", required:false},
|
||||
password: {type:"mqtt-password", required:false}
|
||||
},
|
||||
color:"#c6dbef",
|
||||
inputs:0,
|
||||
|
@ -68,6 +78,14 @@
|
|||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-username"><i class="icon-user"></i> Username</label>
|
||||
<input type="text" id="node-input-username" placeholder="Username">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-lock"><i class="icon-user"></i> Password</label>
|
||||
<input type="text" id="node-input-password" placeholder="Password">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mqtt out">
|
||||
|
@ -82,7 +100,9 @@
|
|||
defaults: {
|
||||
name: {value:""},
|
||||
topic: {value:""},
|
||||
broker: {type:"mqtt-broker", required:true}
|
||||
broker: {type:"mqtt-broker", required:true},
|
||||
username: {value:""},
|
||||
password: {value:""}
|
||||
},
|
||||
color:"#c6dbef",
|
||||
inputs:1,
|
||||
|
|
|
@ -30,9 +30,11 @@ function MQTTInNode(n) {
|
|||
RED.nodes.createNode(this,n);
|
||||
this.topic = n.topic;
|
||||
this.broker = n.broker;
|
||||
this.username = n.username;
|
||||
this.password = n.password;
|
||||
this.brokerConfig = RED.nodes.getNode(this.broker);
|
||||
if (this.brokerConfig) {
|
||||
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port);
|
||||
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.username,this.password);
|
||||
var node = this;
|
||||
this.client.subscribe(this.topic,2,function(topic,payload,qos,retain) {
|
||||
var msg = {topic:topic,payload:payload,qos:qos,retain:retain};
|
||||
|
@ -61,11 +63,13 @@ function MQTTOutNode(n) {
|
|||
|
||||
this.topic = n.topic;
|
||||
this.broker = n.broker;
|
||||
this.username = n.username;
|
||||
this.password = n.password;
|
||||
|
||||
this.brokerConfig = RED.nodes.getNode(this.broker);
|
||||
|
||||
if (this.brokerConfig) {
|
||||
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port);
|
||||
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.username,this.password);
|
||||
this.on("input",function(msg) {
|
||||
if (msg != null) {
|
||||
if (this.topic) {
|
||||
|
|
|
@ -51,7 +51,9 @@ MQTTClient.prototype.connect = function(options) {
|
|||
self.options.clean = self.options.clean||true;
|
||||
self.options.protocolId = 'MQIsdp';
|
||||
self.options.protocolVersion = 3;
|
||||
|
||||
self.options.username = options.username;
|
||||
self.options.password = options.password;
|
||||
|
||||
self.client = mqtt.createConnection(this.port,this.host,function(err,client) {
|
||||
if (err) {
|
||||
self.emit('connectionlost',err);
|
||||
|
|
|
@ -25,12 +25,15 @@ function matchTopic(ts,t) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
get: function(broker,port) {
|
||||
var id = broker+":"+port;
|
||||
get: function(broker,port,username,password) {
|
||||
var prefix = "";
|
||||
if (username !== undefined || password !== undefined)
|
||||
prefix = (username||"") + ":" + (password||"") + "@";
|
||||
var id = prefix+broker+":"+port;
|
||||
if (!connections[id]) {
|
||||
connections[id] = function() {
|
||||
var client = mqtt.createClient(port,broker);
|
||||
var options = {keepalive:15,clientId:'mqtt_' + (1+Math.random()*4294967295).toString(16)};
|
||||
var options = {keepalive:15,clientId:'mqtt_' + (1+Math.random()*4294967295).toString(16),username:username,password:password};
|
||||
var queue = [];
|
||||
var subscriptions = [];
|
||||
var connecting = false;
|
||||
|
|
Loading…
Reference in New Issue