+
-
-
-
-
-
-
-
-
-
- 0
- 1
- 2
-
-
-
-
-
-
-
@@ -269,6 +305,9 @@
Birth Message
This is a message that will be published on the configured topic whenever the
connection is established.
+
Close Message
+
This is a message that will be published on the configured topic before the
+ connection is closed normally, either by re-deploying the node, or by shutting down.
Will Message
This is a message that will be published by the broker in the event the node
unexpectedly loses its connection.
@@ -300,14 +339,18 @@
compatmode: { value: true},
keepalive: {value:60,validate:RED.validators.number()},
cleansession: {value: true},
- willTopic: {value:""},
- willQos: {value:"0"},
- willRetain: {value:false},
- willPayload: {value:""},
birthTopic: {value:""},
birthQos: {value:"0"},
birthRetain: {value:false},
- birthPayload: {value:""}
+ birthPayload: {value:""},
+ closeTopic: {value:""},
+ closeQos: {value:"0"},
+ closeRetain: {value:false},
+ closePayload: {value:""},
+ willTopic: {value:""},
+ willQos: {value:"0"},
+ willRetain: {value:false},
+ willPayload: {value:""}
},
credentials: {
user: {type:"text"},
@@ -343,14 +386,39 @@
id: "mqtt-broker-tab-security",
label: this._("mqtt.tabs-label.security")
});
+
tabs.addTab({
- id: "mqtt-broker-tab-birth",
- label: this._("mqtt.tabs-label.birth")
- });
- tabs.addTab({
- id: "mqtt-broker-tab-will",
- label: this._("mqtt.tabs-label.will")
+ id: "mqtt-broker-tab-messages",
+ label: this._("mqtt.tabs-label.messages")
});
+
+ function setUpSection(sectionId, isExpanded) {
+ var birthMessageSection = $(sectionId);
+ var paletteHeader = birthMessageSection.find('.palette-header');
+ var twistie = paletteHeader.find('i');
+ var sectionContent = birthMessageSection.find('.section-content');
+
+ function toggleSection(expanded) {
+ twistie.toggleClass('expanded', expanded);
+ sectionContent.toggle(expanded);
+ }
+ paletteHeader.click(function(e) {
+ e.preventDefault();
+ var isExpanded = twistie.hasClass('expanded');
+ toggleSection(!isExpanded);
+ });
+ toggleSection(isExpanded);
+ }
+
+ // show first section if none are set so the user gets the idea
+ var showBirthSection = this.birthTopic !== ""
+ || this.willTopic === ""
+ && this.birthTopic === ""
+ && this.closeTopic == "";
+ setUpSection('#mqtt-broker-section-birth', showBirthSection);
+ setUpSection('#mqtt-broker-section-close', this.closeTopic !== "");
+ setUpSection('#mqtt-broker-section-will', this.willTopic !== "");
+
setTimeout(function() { tabs.resize(); },0);
if (typeof this.cleansession === 'undefined') {
this.cleansession = true;
@@ -368,14 +436,18 @@
this.keepalive = 15;
$("#node-config-input-keepalive").val(this.keepalive);
}
- if (typeof this.willQos === 'undefined') {
- this.willQos = "0";
- $("#node-config-input-willQos").val("0");
- }
if (typeof this.birthQos === 'undefined') {
this.birthQos = "0";
$("#node-config-input-birthQos").val("0");
}
+ if (typeof this.closeQos === 'undefined') {
+ this.willQos = "0";
+ $("#node-config-input-willQos").val("0");
+ }
+ if (typeof this.willQos === 'undefined') {
+ this.willQos = "0";
+ $("#node-config-input-willQos").val("0");
+ }
function updateTLSOptions() {
if ($("#node-config-input-usetls").is(':checked')) {
diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js
index c1a8318a6..509099aa4 100644
--- a/nodes/core/io/10-mqtt.js
+++ b/nodes/core/io/10-mqtt.js
@@ -60,6 +60,15 @@ module.exports = function(RED) {
};
}
+ if (n.closeTopic) {
+ this.closeMessage = {
+ topic: n.closeTopic,
+ payload: n.closePayload || "",
+ qos: Number(n.closeQos||0),
+ retain: n.closeRetain=="true"|| n.closeRetain===true
+ };
+ }
+
if (this.credentials) {
this.username = this.credentials.user;
this.password = this.credentials.password;
@@ -314,6 +323,10 @@ module.exports = function(RED) {
this.on('close', function(done) {
this.closing = true;
if (this.connected) {
+ // Send close message
+ if (node.closeMessage) {
+ node.publish(node.closeMessage);
+ }
this.client.once('close', function() {
done();
});
diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json
index c93270e95..74ec0bcd4 100644
--- a/nodes/core/locales/en-US/messages.json
+++ b/nodes/core/locales/en-US/messages.json
@@ -323,6 +323,7 @@
"broker": "Server",
"example": "e.g. localhost",
"qos": "QoS",
+ "retain": "Retain",
"clientid": "Client ID",
"port": "Port",
"keepalive": "Keep alive time (s)",
@@ -332,17 +333,22 @@
"verify-server-cert":"Verify server certificate",
"compatmode": "Use legacy MQTT 3.1 support"
},
+ "sections-label":{
+ "birth-message": "Message sent on connection (birth message)",
+ "will-message":"Message sent on an unexpected disconnection (will message)",
+ "close-message":"Message sent before disconnecting (close message)"
+ },
"tabs-label": {
"connection": "Connection",
"security": "Security",
- "will": "Will Message",
- "birth": "Birth Message"
+ "messages": "Messages"
},
"placeholder": {
"clientid": "Leave blank for auto generated",
"clientid-nonclean":"Must be set for non-clean sessions",
"will-topic": "Leave blank to disable will message",
- "birth-topic": "Leave blank to disable birth message"
+ "birth-topic": "Leave blank to disable birth message",
+ "close-topic": "Leave blank to disable close message"
},
"state": {
"connected": "Connected to broker: __broker__",