mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add qos option to MQTT In node
This commit is contained in:
parent
6b0bef61a5
commit
44dc37ef6d
@ -20,6 +20,14 @@
|
|||||||
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
||||||
<input type="text" id="node-input-topic" data-i18n="[placeholder]common.label.topic">
|
<input type="text" id="node-input-topic" data-i18n="[placeholder]common.label.topic">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-qos"><i class="fa fa-empire"></i> <span data-i18n="mqtt.label.qos"></span></label>
|
||||||
|
<select id="node-input-qos" style="width:125px !important">
|
||||||
|
<option value="0">0</option>
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||||
@ -44,6 +52,7 @@
|
|||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
topic: {value:"",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)},
|
topic: {value:"",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)},
|
||||||
|
qos: {value: "2"},
|
||||||
broker: {type:"mqtt-broker", required:true}
|
broker: {type:"mqtt-broker", required:true}
|
||||||
},
|
},
|
||||||
color:"#d8bfd8",
|
color:"#d8bfd8",
|
||||||
@ -55,6 +64,11 @@
|
|||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
|
},
|
||||||
|
oneditprepare: function() {
|
||||||
|
if (this.qos === undefined) {
|
||||||
|
$("#node-input-qos").val("2");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -298,6 +298,8 @@ module.exports = function(RED) {
|
|||||||
function MQTTInNode(n) {
|
function MQTTInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.topic = n.topic;
|
this.topic = n.topic;
|
||||||
|
this.qos = parseInt(n.qos===undefined?"2":n.qos);
|
||||||
|
|
||||||
this.broker = n.broker;
|
this.broker = n.broker;
|
||||||
this.brokerConn = RED.nodes.getNode(this.broker);
|
this.brokerConn = RED.nodes.getNode(this.broker);
|
||||||
if (!/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/.test(this.topic)) {
|
if (!/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/.test(this.topic)) {
|
||||||
@ -308,7 +310,7 @@ module.exports = function(RED) {
|
|||||||
this.status({fill:"red",shape:"ring",text:"common.status.disconnected"});
|
this.status({fill:"red",shape:"ring",text:"common.status.disconnected"});
|
||||||
if (this.topic) {
|
if (this.topic) {
|
||||||
node.brokerConn.register(this);
|
node.brokerConn.register(this);
|
||||||
this.brokerConn.subscribe(this.topic,2,function(topic,payload,packet) {
|
this.brokerConn.subscribe(this.topic,this.qos,function(topic,payload,packet) {
|
||||||
if (isUtf8(payload)) { payload = payload.toString(); }
|
if (isUtf8(payload)) { payload = payload.toString(); }
|
||||||
var msg = {topic:topic,payload:payload, qos: packet.qos, retain: packet.retain};
|
var msg = {topic:topic,payload:payload, qos: packet.qos, retain: packet.retain};
|
||||||
if ((node.brokerConn.broker === "localhost")||(node.brokerConn.broker === "127.0.0.1")) {
|
if ((node.brokerConn.broker === "localhost")||(node.brokerConn.broker === "127.0.0.1")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user