From abceb1185bc81e869c11918bed3fb17e0bc83dd5 Mon Sep 17 00:00:00 2001 From: meeki007 <5952964+meeki007@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:15:23 -0500 Subject: [PATCH 1/2] Update 10-mqtt.js to meet mqtt specification of 23 length clientid MQTT clientid: If automatically generating a clientid for user it should be =< 23 Right now it generates length of 24. See mqtt specifications --> http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349242 "The Server MUST allow ClientIds which are between 1 and 23 UTF-8 encoded bytes in length,..." As 23 is the minimum we should shoot for this specification. I noticed this when connecting to a mqtt server that was set to minimum spec. it would not connect! Sure I can generate my own ID or fill it in with less than 23 but it did confuse me for 15min. --- packages/node_modules/@node-red/nodes/core/network/10-mqtt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index afa0066f4..451035a74 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -675,7 +675,7 @@ module.exports = function(RED) { node.options.password = node.password; node.options.keepalive = node.keepalive; node.options.clean = node.cleansession; - node.options.clientId = node.clientid || 'nodered_' + RED.util.generateId(); + node.options.clientId = node.clientid || 'nodered' + RED.util.generateId(); node.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000; delete node.options.protocolId; //V4+ default delete node.options.protocolVersion; //V4 default From f43d4e946523a797e7489deb46fed9ca78b70c6d Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 6 Jun 2025 11:45:17 +0100 Subject: [PATCH 2/2] Update test for generated client id --- test/nodes/core/network/21-mqtt_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/nodes/core/network/21-mqtt_spec.js b/test/nodes/core/network/21-mqtt_spec.js index 16c38d2e5..0075831c9 100644 --- a/test/nodes/core/network/21-mqtt_spec.js +++ b/test/nodes/core/network/21-mqtt_spec.js @@ -58,7 +58,7 @@ describe('MQTT Nodes', function () { mqttBroker.should.have.property('options'); mqttBroker.options.should.have.property('clean', true); mqttBroker.options.should.have.property('clientId'); - mqttBroker.options.clientId.should.containEql('nodered_'); + mqttBroker.options.clientId.should.containEql('nodered'); mqttBroker.options.should.have.property('keepalive').type("number"); mqttBroker.options.should.have.property('reconnectPeriod').type("number"); //as this is not a v5 connection, ensure v5 properties are not present @@ -894,4 +894,4 @@ function nextTopic(topic) { return (base_topic + topic + String(topicNo)); } -//#endregion HELPERS \ No newline at end of file +//#endregion HELPERS