Merge pull request #3374 from Steve-Mcl/mqtt-reconnect-fix

Mqtt reconnect fix
This commit is contained in:
Nick O'Leary 2022-01-26 11:03:20 +00:00 committed by GitHub
commit 08732bac0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -288,7 +288,7 @@ module.exports = function(RED) {
//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) {
node.brokerConn.publish(msg, done); // send the message
@ -730,12 +730,18 @@ module.exports = function(RED) {
node.client.on("reconnect", function() {
setStatusConnecting(node, true);
});
//TODO: what to do with this event? Anything? Necessary?
//Broker Disconnect - V5 event
node.client.on("disconnect", function(packet) {
//Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
var rc = packet && packet.properties && packet.properties.reasonString;
var rc = packet && packet.properties && packet.reasonCode;
//TODO: If keeping this event, do we use these? log these?
const rc = (packet && packet.properties && packet.reasonCode) || packet.reasonCode;
const rs = packet && packet.properties && packet.properties.reasonString || "";
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
node.client.on('close', function () {

View File

@ -442,7 +442,8 @@
"state": {
"connected": "Connected to 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",
"output": {