mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'pr_1947' into dev
This commit is contained in:
@@ -28,6 +28,15 @@
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-datatype"><i class="fa fa-sign-out"></i> <span data-i18n="mqtt.label.output"></span></label>
|
||||
<select id="node-input-datatype" style="width:70%;">
|
||||
<option value="auto" data-i18n="mqtt.output.auto"></option>
|
||||
<option value="buffer" data-i18n="mqtt.output.buffer"></option>
|
||||
<option value="utf8" data-i18n="mqtt.output.string"></option>
|
||||
<option value="base64" data-i18n="mqtt.output.base64"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<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">
|
||||
@@ -61,6 +70,7 @@
|
||||
name: {value:""},
|
||||
topic: {value:"",required:true,validate: RED.validators.regex(/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/)},
|
||||
qos: {value: "2"},
|
||||
datatype: {value:"auto",required:true},
|
||||
broker: {type:"mqtt-broker", required:true}
|
||||
},
|
||||
color:"#d8bfd8",
|
||||
@@ -77,6 +87,9 @@
|
||||
if (this.qos === undefined) {
|
||||
$("#node-input-qos").val("2");
|
||||
}
|
||||
if (this.datatype === undefined) {
|
||||
$("#node-input-datatype").val("auto");
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -392,13 +392,22 @@ module.exports = function(RED) {
|
||||
if (!/^(#$|(\+|[^+#]*)(\/(\+|[^+#]*))*(\/(\+|#|[^+#]*))?$)/.test(this.topic)) {
|
||||
return this.warn(RED._("mqtt.errors.invalid-topic"));
|
||||
}
|
||||
this.datatype = n.datatype || "utf8";
|
||||
var node = this;
|
||||
if (this.brokerConn) {
|
||||
this.status({fill:"red",shape:"ring",text:"node-red:common.status.disconnected"});
|
||||
if (this.topic) {
|
||||
node.brokerConn.register(this);
|
||||
this.brokerConn.subscribe(this.topic,this.qos,function(topic,payload,packet) {
|
||||
if (isUtf8(payload)) { payload = payload.toString(); }
|
||||
if (node.datatype =="buffer") {
|
||||
// payload = payload;
|
||||
} else if (node.datatype =="base64") {
|
||||
payload = payload.toString('base64');
|
||||
} else if (node.datatype =="utf8") {
|
||||
payload = payload.toString('utf8');
|
||||
} else {
|
||||
if (isUtf8(payload)) { payload = payload.toString(); }
|
||||
}
|
||||
var msg = {topic:topic,payload:payload, qos: packet.qos, retain: packet.retain};
|
||||
if ((node.brokerConn.broker === "localhost")||(node.brokerConn.broker === "127.0.0.1")) {
|
||||
msg._topic = topic;
|
||||
|
Reference in New Issue
Block a user