mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
make sure MQTT msg has a topic
This commit is contained in:
parent
5234fda266
commit
2a47951e46
@ -45,21 +45,26 @@ module.exports = function(RED) {
|
|||||||
this.status({fill:"red",shape:"ring",text:"disconnected"});
|
this.status({fill:"red",shape:"ring",text:"disconnected"});
|
||||||
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password);
|
this.client = connectionPool.get(this.brokerConfig.broker,this.brokerConfig.port,this.brokerConfig.clientid,this.brokerConfig.username,this.brokerConfig.password);
|
||||||
var node = this;
|
var node = this;
|
||||||
this.client.subscribe(this.topic,2,function(topic,payload,qos,retain) {
|
if (this.topic) {
|
||||||
if (isUtf8(payload)) { payload = payload.toString(); }
|
this.client.subscribe(this.topic,2,function(topic,payload,qos,retain) {
|
||||||
var msg = {topic:topic,payload:payload,qos:qos,retain:retain};
|
if (isUtf8(payload)) { payload = payload.toString(); }
|
||||||
if ((node.brokerConfig.broker === "localhost")||(node.brokerConfig.broker === "127.0.0.1")) {
|
var msg = {topic:topic,payload:payload,qos:qos,retain:retain};
|
||||||
msg._topic = topic;
|
if ((node.brokerConfig.broker === "localhost")||(node.brokerConfig.broker === "127.0.0.1")) {
|
||||||
}
|
msg._topic = topic;
|
||||||
node.send(msg);
|
}
|
||||||
});
|
node.send(msg);
|
||||||
this.client.on("connectionlost",function() {
|
});
|
||||||
node.status({fill:"red",shape:"ring",text:"disconnected"});
|
this.client.on("connectionlost",function() {
|
||||||
});
|
node.status({fill:"red",shape:"ring",text:"disconnected"});
|
||||||
this.client.on("connect",function() {
|
});
|
||||||
node.status({fill:"green",shape:"dot",text:"connected"});
|
this.client.on("connect",function() {
|
||||||
});
|
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||||
this.client.connect();
|
});
|
||||||
|
this.client.connect();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.error("topic not defined");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.error("missing broker configuration");
|
this.error("missing broker configuration");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user