mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Improve MQTT broker disconnect situation
* Ensure topic is sane to prevent error 129 * Ensure a log entry is made * Update node status
This commit is contained in:
parent
81a4fe59d9
commit
9c3be51fe9
@ -288,7 +288,7 @@ module.exports = function(RED) {
|
|||||||
//TODO: delete msg.responseTopic - to prevent it being resent?
|
//TODO: delete msg.responseTopic - to prevent it being resent?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
topicOK = topicOK && !/[\+#]/.test(msg.topic);
|
topicOK = topicOK && !/[\+#\b\f\n\r\t\v\0]/.test(msg.topic);
|
||||||
|
|
||||||
if (topicOK) {
|
if (topicOK) {
|
||||||
node.brokerConn.publish(msg, done); // send the message
|
node.brokerConn.publish(msg, done); // send the message
|
||||||
@ -730,12 +730,18 @@ module.exports = function(RED) {
|
|||||||
node.client.on("reconnect", function() {
|
node.client.on("reconnect", function() {
|
||||||
setStatusConnecting(node, true);
|
setStatusConnecting(node, true);
|
||||||
});
|
});
|
||||||
//TODO: what to do with this event? Anything? Necessary?
|
//Broker Disconnect - V5 event
|
||||||
node.client.on("disconnect", function(packet) {
|
node.client.on("disconnect", function(packet) {
|
||||||
//Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
|
//Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
|
||||||
var rc = packet && packet.properties && packet.properties.reasonString;
|
const rc = (packet && packet.properties && packet.reasonCode) || packet.reasonCode;
|
||||||
var rc = packet && packet.properties && packet.reasonCode;
|
const rs = packet && packet.properties && packet.properties.reasonString || "";
|
||||||
//TODO: If keeping this event, do we use these? log these?
|
const details = {
|
||||||
|
broker: (node.clientid?node.clientid+"@":"")+node.brokerurl,
|
||||||
|
reasonCode: rc,
|
||||||
|
reasonString: rs
|
||||||
|
}
|
||||||
|
node.log(RED._("mqtt.state.broker-disconnected", details));
|
||||||
|
setStatusDisconnected(node, true);
|
||||||
});
|
});
|
||||||
// Register disconnect handlers
|
// Register disconnect handlers
|
||||||
node.client.on('close', function () {
|
node.client.on('close', function () {
|
||||||
|
@ -442,7 +442,8 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"connected": "Connected to broker: __broker__",
|
"connected": "Connected to broker: __broker__",
|
||||||
"disconnected": "Disconnected from broker: __broker__",
|
"disconnected": "Disconnected from broker: __broker__",
|
||||||
"connect-failed": "Connection failed to broker: __broker__"
|
"connect-failed": "Connection failed to broker: __broker__",
|
||||||
|
"broker-disconnected": "Broker __broker__ disconnected client: __reasonCode__ __reasonString__"
|
||||||
},
|
},
|
||||||
"retain": "Retain",
|
"retain": "Retain",
|
||||||
"output": {
|
"output": {
|
||||||
|
Loading…
Reference in New Issue
Block a user