[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / io / 10-mqtt.html
1 <!--
2   Copyright 2013,2014 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="mqtt in">
18     <div class="form-row">
19         <label for="node-input-broker"><i class="fa fa-globe"></i> Broker</label>
20         <input type="text" id="node-input-broker">
21     </div>
22     <div class="form-row">
23         <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
24         <input type="text" id="node-input-topic" placeholder="Topic">
25     </div>
26     <div class="form-row">
27         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
28         <input type="text" id="node-input-name" placeholder="Name">
29     </div>
30 </script>
31
32 <script type="text/x-red" data-help-name="mqtt in">
33     <p>MQTT input node. Connects to a broker and subscribes to the specified topic. The topic may contain MQTT wildcards.</p>
34     <p>Outputs an object called <b>msg</b> containing <b>msg.topic, msg.payload, msg.qos</b> and <b>msg.retain</b>.</p>
35     <p><b>msg.payload</b> is a String.</p>
36 </script>
37
38 <script type="text/javascript">
39     RED.nodes.registerType('mqtt in',{
40         category: 'input',
41         defaults: {
42             name: {value:""},
43             topic: {value:"",required:true},
44             broker: {type:"mqtt-broker", required:true}
45         },
46         color:"#d8bfd8",
47         inputs:0,
48         outputs:1,
49         icon: "bridge.png",
50         label: function() {
51             return this.name||this.topic||"mqtt";
52         },
53         labelStyle: function() {
54             return this.name?"node_label_italic":"";
55         }
56     });
57 </script>
58
59 <script type="text/x-red" data-template-name="mqtt out">
60     <div class="form-row">
61         <label for="node-input-broker"><i class="fa fa-globe"></i> Broker</label>
62         <input type="text" id="node-input-broker">
63     </div>
64     <div class="form-row">
65         <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
66         <input type="text" id="node-input-topic" placeholder="Topic">
67     </div>
68     <div class="form-row">
69         <label for="node-input-qos"><i class="fa fa-empire"></i> QoS</label>
70         <select id="node-input-qos" style="width:125px !important">
71             <option value=""></option>
72             <option value="0">0</option>
73             <option value="1">1</option>
74             <option value="2">2</option>
75         </select>
76         &nbsp;&nbsp;<i class="fa fa-history"></i>&nbsp;Retain &nbsp;<select id="node-input-retain" style="width:125px !important">
77             <option value=""></option>
78             <option value="false">false</option>
79             <option value="true">true</option>
80         </select>
81     </div>
82     <div class="form-row">
83         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
84         <input type="text" id="node-input-name" placeholder="Name">
85     </div>
86     <div class="form-tips">Tip: Leave topic, qos or retain blank if you want to set them via msg properties.</div>
87 </script>
88
89 <script type="text/x-red" data-help-name="mqtt out">
90     <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>
91     <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>
92     <p>If <b>msg.payload</b> contains an object it will be stringified before being sent.</p>
93 </script>
94
95 <script type="text/javascript">
96     RED.nodes.registerType('mqtt out',{
97         category: 'output',
98         defaults: {
99             name: {value:""},
100             topic: {value:""},
101             qos: {value:""},
102             retain: {value:""},
103             broker: {type:"mqtt-broker", required:true}
104         },
105         color:"#d8bfd8",
106         inputs:1,
107         outputs:0,
108         icon: "bridge.png",
109         align: "right",
110         label: function() {
111             return this.name||this.topic||"mqtt";
112         },
113         labelStyle: function() {
114             return this.name?"node_label_italic":"";
115         }
116     });
117 </script>
118
119 <script type="text/x-red" data-template-name="mqtt-broker">
120     <div class="form-row node-input-broker">
121         <label for="node-config-input-broker"><i class="fa fa-globe"></i> Broker</label>
122         <input class="input-append-left" type="text" id="node-config-input-broker" placeholder="localhost" style="width: 40%;" >
123         <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
124         <input type="text" id="node-config-input-port" placeholder="Port" style="width:45px">
125     </div>
126     <div class="form-row">
127         <label for="node-config-input-clientid"><i class="fa fa-tag"></i> Client ID</label>
128         <input type="text" id="node-config-input-clientid" placeholder="Leave blank for auto generated">
129     </div>
130     <div class="form-row">
131         <label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
132         <input type="text" id="node-config-input-user">
133     </div>
134     <div class="form-row">
135         <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
136         <input type="password" id="node-config-input-password">
137     </div>
138 </script>
139
140 <script type="text/javascript">
141     RED.nodes.registerType('mqtt-broker',{
142         category: 'config',
143         defaults: {
144             broker: {value:"",required:true},
145             port: {value:1883,required:true,validate:RED.validators.number()},
146             clientid: { value:"" }
147         },
148         credentials: {
149             user: {type:"text"},
150             password: {type: "password"}
151         },
152         label: function() {
153             if (this.broker == "") { this.broker = "localhost"; }
154             return (this.clientid?this.clientid+"@":"")+this.broker+":"+this.port;
155         }
156     });
157 </script>