mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add birth message to MQTT node
This commit is contained in:
parent
fcf4f40c36
commit
c1d694a97c
@ -115,7 +115,7 @@
|
||||
|
||||
<script type="text/x-red" data-template-name="mqtt-broker">
|
||||
<div class="form-row">
|
||||
<ul style="background: #fff; min-width: 550px; margin-bottom: 20px;" id="node-config-mqtt-broker-tabs"></ul>
|
||||
<ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-mqtt-broker-tabs"></ul>
|
||||
</div>
|
||||
<div id="node-config-mqtt-broker-tabs-content" style="min-height: 170px;">
|
||||
<div id="mqtt-broker-tab-connection" style="display:none">
|
||||
@ -159,6 +159,28 @@
|
||||
<label for="node-config-input-verifyservercert" style="width: 70%;" data-i18n="mqtt.label.verify-server-cert"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="mqtt-broker-tab-birth" style="display:none">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-birthTopic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
||||
<input type="text" id="node-config-input-birthTopic" data-i18n="[placeholder]mqtt.placeholder.birth-topic">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-birthQos"><i class="fa fa-empire"></i> <span data-i18n="mqtt.label.qos"></span></label>
|
||||
<select id="node-config-input-birthQos" style="width:125px !important">
|
||||
<option value="0">0</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
<i class="fa fa-history"></i> <span data-i18n="mqtt.retain"></span> <select id="node-config-input-birthRetain" style="width:125px !important">
|
||||
<option value="false" data-i18n="mqtt.false"></option>
|
||||
<option value="true" data-i18n="mqtt.true"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-birthPayload"><i class="fa fa-envelope"></i> <span data-i18n="common.label.payload"></span></label>
|
||||
<input type="text" id="node-config-input-birthPayload" data-i18n="[placeholder]common.label.payload">
|
||||
</div>
|
||||
</div>
|
||||
<div id="mqtt-broker-tab-will" style="display:none">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-willTopic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
||||
@ -207,9 +229,13 @@
|
||||
keepalive: {value:15,validate:RED.validators.number()},
|
||||
cleansession: {value: true},
|
||||
willTopic: {value:""},
|
||||
willQos: {value:0},
|
||||
willQos: {value:"0"},
|
||||
willRetain: {value:false},
|
||||
willPayload: {value:""}
|
||||
willPayload: {value:""},
|
||||
birthTopic: {value:""},
|
||||
birthQos: {value:"0"},
|
||||
birthRetain: {value:false},
|
||||
birthPayload: {value:""}
|
||||
},
|
||||
credentials: {
|
||||
user: {type:"text"},
|
||||
@ -235,6 +261,10 @@
|
||||
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")
|
||||
@ -260,6 +290,14 @@
|
||||
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");
|
||||
}
|
||||
|
||||
function updateTLSOptions() {
|
||||
if ($("#node-config-input-usetls").is(':checked')) {
|
||||
|
@ -51,6 +51,14 @@ module.exports = function(RED) {
|
||||
this.queue = [];
|
||||
this.subscriptions = {};
|
||||
|
||||
if (n.birthTopic) {
|
||||
this.birthMessage = {
|
||||
topic: n.birthTopic,
|
||||
payload: n.birthPayload || "",
|
||||
qos: Number(n.birthQos||0),
|
||||
retain: n.birthRetain=="true"|| n.birthRetain===true
|
||||
};
|
||||
}
|
||||
events.EventEmitter.call(this);
|
||||
this.setMaxListeners(0);
|
||||
|
||||
@ -159,6 +167,11 @@ module.exports = function(RED) {
|
||||
node.client.subscribe(topic, options);
|
||||
}
|
||||
|
||||
// Send any birth message
|
||||
if (node.birthMessage) {
|
||||
node.publish(node.birthMessage);
|
||||
}
|
||||
|
||||
// Send any queued messages
|
||||
while(node.queue.length) {
|
||||
var msg = node.queue.shift();
|
||||
|
@ -224,12 +224,14 @@
|
||||
"tabs-label": {
|
||||
"connection": "Connection",
|
||||
"security": "Security",
|
||||
"will": "Will Message"
|
||||
"will": "Will Message",
|
||||
"birth": "Birth Message"
|
||||
},
|
||||
"placeholder": {
|
||||
"clientid": "Leave blank for auto generated",
|
||||
"clientid-nonclean":"Must be set for non-clean sessions",
|
||||
"will-topic": "Leave blank to disable will message"
|
||||
"will-topic": "Leave blank to disable will message",
|
||||
"birth-topic": "Leave blank to disable birth message"
|
||||
},
|
||||
"state": {
|
||||
"connected": "Connected to broker: __broker__",
|
||||
|
@ -29,7 +29,7 @@
|
||||
"when": "3.7.3",
|
||||
"bcryptjs": "2.2.0",
|
||||
"nopt": "3.0.3",
|
||||
"mqtt": "1.3.x",
|
||||
"mqtt": "1.4.x",
|
||||
"ws": "0.7.2",
|
||||
"fs-extra": "0.22.1",
|
||||
"clone": "1.0.2",
|
||||
|
Loading…
Reference in New Issue
Block a user