2013-09-05 16:02:48 +02:00
<!--
2015-06-03 08:54:43 +02:00
Copyright 2013,2015 IBM Corp.
2013-09-05 16:02:48 +02:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
< script type = "text/x-red" data-template-name = "mqtt in" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-broker" > < i class = "fa fa-globe" > < / i > < span data-i18n = "mqtt.label.broker" > < / span > < / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-broker" >
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-topic" > < i class = "fa fa-tasks" > < / i > < span data-i18n = "common.label.topic" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-topic" data-i18n = "[placeholder]common.label.topic" >
2013-09-05 16:02:48 +02:00
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-09-05 16:02:48 +02:00
< / div >
< / script >
< script type = "text/x-red" data-help-name = "mqtt in" >
2014-01-08 17:44:47 +01:00
< p > MQTT input node. Connects to a broker and subscribes to the specified topic. The topic may contain MQTT wildcards.< / p >
< p > Outputs an object called < b > msg< / b > containing < b > msg.topic, msg.payload, msg.qos< / b > and < b > msg.retain< / b > .< / p >
2015-03-03 16:56:33 +01:00
< p > < b > msg.payload< / b > is usually a string, but can also be a binary buffer.< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('mqtt in',{
category: 'input',
defaults: {
name: {value:""},
topic: {value:"",required:true},
broker: {type:"mqtt-broker", required:true}
},
2014-01-08 17:44:47 +01:00
color:"#d8bfd8",
2013-09-05 16:02:48 +02:00
inputs:0,
outputs:1,
icon: "bridge.png",
label: function() {
2013-09-27 11:38:59 +02:00
return this.name||this.topic||"mqtt";
2013-09-05 16:02:48 +02:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
< / script >
< script type = "text/x-red" data-template-name = "mqtt out" >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-broker" > < i class = "fa fa-globe" > < / i > < span data-i18n = "mqtt.label.broker" > < / span > < / label >
2013-09-05 16:02:48 +02:00
< input type = "text" id = "node-input-broker" >
< / div >
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-topic" > < i class = "fa fa-tasks" > < / i > < span data-i18n = "common.label.topic" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-topic" data-i18n = "[placeholder]common.label.topic" >
2013-09-05 16:02:48 +02:00
< / div >
2014-08-22 13:42:07 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-qos" > < i class = "fa fa-empire" > < / i > < span data-i18n = "mqtt.label.qos" > < / span > < / label >
2014-08-22 13:42:07 +02:00
< select id = "node-input-qos" style = "width:125px !important" >
< option value = "" > < / option >
< option value = "0" > 0< / option >
< option value = "1" > 1< / option >
< option value = "2" > 2< / option >
< / select >
2015-05-10 22:47:22 +02:00
< i class = "fa fa-history" > < / i > < span data-i18n = "mqtt.retain" > < / span > < select id = "node-input-retain" style = "width:125px !important" >
2014-08-22 13:42:07 +02:00
< option value = "" > < / option >
2015-05-10 22:47:22 +02:00
< option value = "false" data-i18n = "mqtt.false" > < / option >
< option value = "true" data-i18n = "mqtt.true" > < / option >
2014-08-22 13:42:07 +02:00
< / select >
< / div >
2013-09-05 16:02:48 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2015-05-26 22:11:14 +02:00
< input type = "text" id = "node-input-name" data-i18n = "[placeholder]common.label.name" >
2013-09-05 16:02:48 +02:00
< / div >
2015-05-10 22:47:22 +02:00
< div class = "form-tips" > < span data-i18n = "mqtt.tip" > < / span > < / div >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/x-red" data-help-name = "mqtt out" >
2014-08-22 13:42:07 +02:00
< p > Connects to a MQTT broker and publishes < b > msg.payload< / b > either to the < b > msg.topic< / b > or to the topic specified in the edit window. The value in the edit window has precedence.< / p >
< p > Likewise QoS and/or retain values in the edit panel will overwrite any < b > msg.qos< / b > and < b > msg.retain< / b > properties. If nothing is set they default to < i > 0< / i > and < i > false< / i > respectively.< / p >
< p > If < b > msg.payload< / b > contains an object it will be stringified before being sent.< / p >
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('mqtt out',{
category: 'output',
defaults: {
name: {value:""},
topic: {value:""},
2014-08-22 13:42:07 +02:00
qos: {value:""},
retain: {value:""},
2013-09-05 16:02:48 +02:00
broker: {type:"mqtt-broker", required:true}
},
2014-01-08 17:44:47 +01:00
color:"#d8bfd8",
2013-09-05 16:02:48 +02:00
inputs:1,
outputs:0,
icon: "bridge.png",
align: "right",
label: function() {
2013-09-27 11:38:59 +02:00
return this.name||this.topic||"mqtt";
2013-09-05 16:02:48 +02:00
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
< / script >
< script type = "text/x-red" data-template-name = "mqtt-broker" >
2015-06-03 08:54:43 +02:00
< div class = "form-row" >
2015-09-01 23:30:15 +02:00
< ul style = "background: #fff; min-width: 550px; margin-bottom: 20px;" id = "node-config-mqtt-broker-tabs" > < / ul >
2013-11-25 23:50:08 +01:00
< / div >
2015-09-01 23:30:15 +02:00
< div id = "node-config-mqtt-broker-tabs-content" style = "min-height: 170px;" >
< div id = "mqtt-broker-tab-connection" style = "display:none" >
< div class = "form-row node-input-broker" >
< label for = "node-config-input-broker" > < i class = "fa fa-globe" > < / i > < span data-i18n = "mqtt.label.broker" > < / span > < / label >
< input class = "input-append-left" type = "text" id = "node-config-input-broker" placeholder = "localhost" style = "width: 40%;" >
< label for = "node-config-input-port" style = "margin-left: 10px; width: 35px; " > < span data-i18n = "mqtt.label.port" > < / span > < / label >
< input type = "text" id = "node-config-input-port" data-i18n = "[placeholder]mqtt.label.port" style = "width:45px" >
< / div >
< div class = "form-row" >
< label for = "node-config-input-clientid" > < i class = "fa fa-tag" > < / i > < span data-i18n = "mqtt.label.clientid" > < / span > < / label >
< input type = "text" id = "node-config-input-clientid" data-i18n = "[placeholder]mqtt.placeholder.clientid" >
< / div >
< div class = "form-row" >
< label for = "node-config-input-keepalive" style = "width: auto" > < i class = "fa fa-clock-o" > < / i > < span data-i18n = "mqtt.label.keepalive" > < / span > < / label >
< input type = "text" id = "node-config-input-keepalive" style = "width: 50px" >
< input type = "checkbox" id = "node-config-input-cleansession" style = "margin-left: 30px; height: 1em;display: inline-block; width: auto; vertical-align: middle;" >
< label for = "node-config-input-cleansession" style = "width: auto;" data-i18n = "mqtt.label.cleansession" > < / label >
< / div >
< div class = "form-row" >
< input type = "checkbox" id = "node-config-input-compatmode" style = "display: inline-block; width: auto; vertical-align: top;" >
< label for = "node-config-input-compatmode" style = "width: auto;" data-i18n = "mqtt.label.compatmode" > < / label >
< / div >
< / div >
< div id = "mqtt-broker-tab-security" style = "display:none" >
< div class = "form-row" >
< label for = "node-config-input-user" > < i class = "fa fa-user" > < / i > < span data-i18n = "common.label.username" > < / span > < / label >
< input type = "text" id = "node-config-input-user" >
< / div >
< div class = "form-row" >
< label for = "node-config-input-password" > < i class = "fa fa-lock" > < / i > < span data-i18n = "common.label.password" > < / span > < / label >
< input type = "password" id = "node-config-input-password" >
< / div >
< div class = "form-row" >
< input type = "checkbox" id = "node-config-input-usetls" style = "display: inline-block; width: auto; vertical-align: top;" >
< label for = "node-config-input-usetls" style = "width: 70%;" data-i18n = "mqtt.label.use-tls" > < / label >
< / div >
< div class = "form-row" >
< input type = "checkbox" id = "node-config-input-verifyservercert" style = "display: inline-block; width: auto; vertical-align: top;" >
< label for = "node-config-input-verifyservercert" style = "width: 70%;" data-i18n = "mqtt.label.verify-server-cert" > < / label >
< / 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 >
< input type = "text" id = "node-config-input-willTopic" data-i18n = "[placeholder]mqtt.placeholder.will-topic" >
< / div >
< div class = "form-row" >
< label for = "node-config-input-willQos" > < i class = "fa fa-empire" > < / i > < span data-i18n = "mqtt.label.qos" > < / span > < / label >
< select id = "node-config-input-willQos" 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-willRetain" 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-willPayload" > < i class = "fa fa-envelope" > < / i > < span data-i18n = "common.label.payload" > < / span > < / label >
< input type = "text" id = "node-config-input-willPayload" data-i18n = "[placeholder]common.label.payload" >
< / div >
< / div >
2013-11-25 23:50:08 +01:00
< / div >
2015-09-01 23:30:15 +02:00
2013-09-05 16:02:48 +02:00
< / script >
< script type = "text/javascript" >
RED.nodes.registerType('mqtt-broker',{
category: 'config',
defaults: {
2014-05-29 23:13:21 +02:00
broker: {value:"",required:true},
2013-11-25 23:50:08 +01:00
port: {value:1883,required:true,validate:RED.validators.number()},
2015-09-01 23:30:15 +02:00
clientid: { value:"", validate: function(v) {
if ($("#node-config-input-clientid").length) {
// Currently editing the node
return $("#node-config-input-cleansession").is(":checked") || v.length > 0;
} else {
return this.cleansession || v.length > 0;
}
}},
usetls: {value: false},
verifyservercert: { value: false},
2015-06-03 08:54:43 +02:00
compatmode: { value: true},
2015-09-01 23:30:15 +02:00
keepalive: {value:15,validate:RED.validators.number()},
cleansession: {value: true},
willTopic: {value:""},
willQos: {value:0},
willRetain: {value:false},
willPayload: {value:""}
2014-07-18 15:47:58 +02:00
},
credentials: {
user: {type:"text"},
password: {type: "password"}
2013-09-05 16:02:48 +02:00
},
label: function() {
2014-05-29 23:13:21 +02:00
if (this.broker == "") { this.broker = "localhost"; }
2014-02-17 23:42:31 +01:00
return (this.clientid?this.clientid+"@":"")+this.broker+":"+this.port;
2015-06-03 08:54:43 +02:00
},
oneditprepare: function () {
2015-09-01 23:30:15 +02:00
var tabs = RED.tabs.create({
id: "node-config-mqtt-broker-tabs",
onchange: function(tab) {
$("#node-config-mqtt-broker-tabs-content").children().hide();
$("#" + tab.id).show();
}
});
tabs.addTab({
id: "mqtt-broker-tab-connection",
label: this._("mqtt.tabs-label.connection")
});
tabs.addTab({
id: "mqtt-broker-tab-security",
label: this._("mqtt.tabs-label.security")
});
tabs.addTab({
id: "mqtt-broker-tab-will",
label: this._("mqtt.tabs-label.will")
});
setTimeout(function() { tabs.resize()},0);
2015-09-01 23:58:26 +02:00
if (typeof this.cleansession === 'undefined') {
this.cleansession = true;
$("#node-config-input-cleansession").prop("checked",true);
}
2015-09-01 23:30:15 +02:00
if (typeof this.usetls === 'undefined'){
this.usetls = false;
$("#node-config-input-usetls").prop("checked",false);
2015-06-03 08:54:43 +02:00
}
2015-09-01 23:30:15 +02:00
if (typeof this.verifyservercert === 'undefined'){
this.verifyservercert = true;
$("#node-config-input-verifyservercert").prop("checked",true);
2015-06-03 08:54:43 +02:00
}
2015-09-01 23:30:15 +02:00
if (typeof this.compatmode === 'undefined'){
2015-06-03 08:54:43 +02:00
this.compatmode = true;
$("#node-config-input-compatmode").prop('checked', true);
}
2015-09-01 23:30:15 +02:00
if (typeof this.keepalive === 'undefined'){
this.keepalive = 15;
2015-09-01 23:58:26 +02:00
$("#node-config-input-keepalive").val(this.keepalive);
2015-06-03 08:54:43 +02:00
}
2015-09-01 23:30:15 +02:00
function updateTLSOptions() {
if ($("#node-config-input-usetls").is(':checked')) {
$("#node-config-input-verifyservercert").prop("disabled", false);
$("#node-config-input-verifyservercert").next().css("color","");
} else {
$("#node-config-input-verifyservercert").prop("disabled", true);
$("#node-config-input-verifyservercert").next().css("color","#aaa");
}
2015-06-03 08:54:43 +02:00
}
2015-09-01 23:30:15 +02:00
updateTLSOptions();
$("#node-config-input-usetls").on("click",function() {
updateTLSOptions();
});
var node = this;
function updateClientId() {
if ($("#node-config-input-cleansession").is(":checked")) {
$("#node-config-input-clientid").attr("placeholder",node._("mqtt.placeholder.clientid"));
2015-06-03 08:54:43 +02:00
} else {
2015-09-01 23:30:15 +02:00
$("#node-config-input-clientid").attr("placeholder",node._("mqtt.placeholder.clientid-nonclean"));
2015-06-03 08:54:43 +02:00
}
2015-09-01 23:30:15 +02:00
$("#node-config-input-clientid").change();
}
setTimeout(updateClientId,0);
$("#node-config-input-cleansession").on("click",function() {
updateClientId();
2015-06-03 08:54:43 +02:00
});
2013-09-05 16:02:48 +02:00
}
});
< / script >