forked from cuongquay/node-red-contrib-aws-iot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws-iot.html
237 lines (221 loc) · 7.23 KB
/
aws-iot.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!--
Copyright 2014 IBM Corp.
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="aws-iot-device">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-globe"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-mode"><i class="fa fa-tag"></i> Type</label>
<select type="text" id="node-config-input-mode">
<option value="broker">MQTT Broker</option>
<option value="shadow">Thing Shadow</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-clientId"><i class="fa fa-tag"></i> Client ID</label>
<input type="text" id="node-config-input-clientId" placeholder="Client ID">
</div>
<div class="form-row">
<label for="node-config-input-endpoint"><i class="fa fa-tag"></i> Endpoint</label>
<input type="text" id="node-config-input-endpoint" placeholder="AWS IoT Endpoint">
</div>
<div class="form-row">
<label for="node-config-input-awscerts"><i class="fa fa-tag"></i> AWS Certs</label>
<input type="text" id="node-config-input-awscerts"></input>
</div>
</script>
<!-- MQTT Broker Configuration -->
<script type="text/javascript">
RED.nodes.registerType('aws-iot-device', {
category : 'config',
defaults : {
name : {
value : "",
required : true
},
mode : {
value : "",
required : true
},
clientId : {
value : ""
},
endpoint : {
value : "",
required : true
},
awscerts : {
value : "/root/.agent/certs",
required : true
}
},
label : function() {
return this.name;
}
});
</script>
<script type="text/x-red" data-template-name="aws-mqtt out">
<div class="form-row">
<label for="node-input-device"><i class="fa fa-globe"></i> Device</label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-globe"></i> Topic</label>
<input type="text" id="node-input-topic">
</div>
<div class="form-row">
<label for="node-input-qos"><i class="fa fa-empire"></i> <span> QoS</span></label>
<select id="node-input-qos" style="width:125px !important">
<option value="0">0</option>
<option value="1">1</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="aws-mqtt out">
<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>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-mqtt out', {
category : 'output',
color : "#e97b00",
defaults : {
device : {
type : "aws-iot-device",
required : true
},
topic : {
value : ""
},
qos : {
value : 0,
validate : RED.validators.number()
}
},
inputs : 1,
outputs : 0,
icon : "bridge.png",
align : "right",
label : function() {
var dbNode = RED.nodes.node(this.device);
return this.name || ( dbNode ? dbNode.label() : "aws-mqtt");
},
labelStyle : function() {
return this.name ? "node_label_italic" : "";
}
});
</script>
<script type="text/x-red" data-template-name="aws-mqtt in">
<div class="form-row">
<label for="node-input-device"><i class="fa fa-device"></i> Device</label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tag"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
</script>
<script type="text/x-red" data-help-name="aws-mqtt in">
<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>
<p><b>msg.payload</b> is usually a string, but can also be a binary buffer.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-mqtt in', {
category : 'input',
color : "#e97b00",
defaults : {
device : {
type : "aws-iot-device",
required : true
},
topic : {
value : ""
}
},
inputs : 0,
outputs : 1,
icon : "bridge.png",
align : "left",
label : function() {
var dbNode = RED.nodes.node(this.device);
return this.name || ( dbNode ? dbNode.label() : "aws-mqtt");
},
labelStyle : function() {
return this.name ? "node_label_italic" : "";
}
});
</script>
<!-- ThingShadow Configuration -->
<script type="text/x-red" data-template-name="aws-thing">
<div class="form-row">
<label for="node-input-device"><i class="fa fa-globe"></i> Device</label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-method"><i class="fa fa-empire"></i> <span>Method</span></label>
<select id="node-input-method" style="width:125px !important">
<option value="get">GET</option>
<option value="update">UPDATE</option>
<option value="delete">DELETE</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="aws-thing">
<p>A thing shadow (sometimes referred to as a device shadow) is a JSON document that is used to store and retrieve current state information for a thing (device, app, and so on).</p>
<p>The Thing Shadows service maintains a thing shadow for each thing you connect to AWS IoT.</p>
<p>You can use thing shadows to get and set the state of a thing over MQTT or HTTP, regardless of whether the thing is connected to the Internet.</p>
<p>Each thing shadow is uniquely identified by its name. <b>Thing Name</b> that used for Device Shadow MQTT Pub/Sub Messages:
<pre>$aws/things/thingName/shadow/#</pre>
</p>
<p>The input pin accepts a <b>msg.payload</b> with JSON format following the structure of AWS ThingShadow document for UPDATE
<pre>
<b>msg.payload</b> = {
state: {
desired: {
color: "RED"
}
}
}</pre>
</p>
<p>Whereas, the two output pins show out the STATUS (pin 1) and the TIMEOUT (pin 2) messages in the <b>msg.payload</b></p>
</script>
<script type="text/javascript">
RED.nodes.registerType('aws-thing', {
category : 'function',
color : "#e97b00",
defaults : {
device : {
type : "aws-iot-device",
required : true
},
method : {
value : "get",
required : true
}
},
inputs : 1,
outputs : 1,
icon : "light.png",
align : "right",
label : function() {
var dbNode = RED.nodes.node(this.device);
return "[" + this.method + "] /" + ( dbNode ? dbNode.label() : "aws-thing");
},
labelStyle : function() {
return this.name ? "node_label_italic" : "";
}
});
</script>