-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathblynk-websockets.html
283 lines (249 loc) · 9.65 KB
/
blynk-websockets.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!--
Copyright 2013 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/javascript">
(function() {
function ws_oneditprepare() {
/*if(this.client) {
$("#node-input-mode").val('client').change();
}*/
}
function ws_oneditsave() {
}
function ws_label() {
_pin = 'no pin';
_type = '';
if(this.type == 'blynk-websockets-in-read') {
_type = 'Read Event';
}
if(this.type == 'blynk-websockets-in-write') {
_type = 'Write Event';
}
if(this.type == 'blynk-websockets-out-write') {
_type = 'Write';
}
if(this.pin) {
_pin ='Pin V'+ this.pin + ' - ' + _type;
}
if(this.type == "blynk-websockets-out-email") {
return this.name||this.email||'email';
}
if(this.type == "blynk-websockets-client") {
return this.name||this.key||'n/a';
}
return this.name||_pin;
}
function ws_validateclient() {
/* if($("#node-input-mode").val() === 'client' || (this.client && !this.server)) {
return RED.nodes.node(this.client) != null;
}
else {
return true;
}*/
return true;
}
RED.nodes.registerType('blynk-websockets-client',{
category: 'config',
defaults: {
name: { value: ''},
path: {value: '', required:true, validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/) },
key: {value: '', required:true}
},
inputs:0,
outputs:0,
label: ws_label
});
RED.nodes.registerType('blynk-websockets-in-read', {
category: 'blynk ws',
paletteLabel: 'read event',
defaults: {
name: {value: ''},
pin: {value: 0},
client: {type:"blynk-websockets-client", validate: ws_validateclient}
},
color:"#1BC17C",
inputs:0,
outputs:1,
icon: "white-globe.png",
labelStyle: function() {
return this.name?"node_label_italic":"";
},
label: ws_label,
oneditsave: ws_oneditsave,
oneditprepare: ws_oneditprepare
});
RED.nodes.registerType('blynk-websockets-in-write', {
category: 'blynk ws',
paletteLabel: 'write event',
defaults: {
name: {value: ''},
pin: {value: 0},
client: {type:"blynk-websockets-client", validate: ws_validateclient}
},
color:"#1BC17C",
inputs:0,
outputs:1,
icon: "white-globe.png",
labelStyle: function() {
return this.name?"node_label_italic":"";
},
label: ws_label,
oneditsave: ws_oneditsave,
oneditprepare: ws_oneditprepare
});
RED.nodes.registerType('blynk-websockets-out-write',{
category: 'blynk ws',
paletteLabel: 'write',
defaults: {
name: {value: ''},
pin: {value: 0},
client: {type: "blynk-websockets-client", validate: ws_validateclient}
},
color:"#1BC17C",
inputs:1,
outputs:0,
icon: "white-globe.png",
align: "right",
labelStyle: function() {
return this.name?"node_label_italic":"";
},
label: ws_label,
oneditsave: ws_oneditsave,
oneditprepare: ws_oneditprepare
});
RED.nodes.registerType('blynk-websockets-out-email',{
category: 'blynk ws',
paletteLabel: 'email',
defaults: {
name: {value: ''},
email: {},
client: {type: "blynk-websockets-client", validate: ws_validateclient}
},
color:"#1BC17C",
inputs:1,
outputs:0,
icon: "email.png",
align: "right",
labelStyle: function() {
return this.name?"node_label_italic":"";
},
label: ws_label,
oneditsave: ws_oneditsave,
oneditprepare: ws_oneditprepare
});
})();
</script>
<!-- Blynk Input Node - Read -->
<script type="text/x-red" data-template-name="blynk-websockets-in-read">
<div class="form-row" id="websocket-client-row">
<label for="node-input-client"><i class="fa fa-bookmark"></i> <span>Connection</span></label>
<input type="text" id="node-input-client">
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Virtual Pin</span></label>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="blynk-websockets-in-read">
<p>Blynk read event node.</p>
<p>msg.payload will contain the virtual pin number that triggered the read event</p>
</script>
<!-- Blynk Input Node - Write -->
<script type="text/x-red" data-template-name="blynk-websockets-in-write">
<div class="form-row" id="websocket-client-row">
<label for="node-input-client"><i class="fa fa-bookmark"></i> <span>Connection</span></label>
<input type="text" id="node-input-client">
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Virtual Pin</span></label>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="blynk-websockets-in-write">
<p>Blynk write event node.</p>
<p>msg.payload will contain the the value to write to the specified pin.</p>
<p>msg.arrayOfValues will contain an array of values sent, useful for Widgets that have the MERGE ability.</p>
</script>
<!-- Blynk out Node - Write -->
<script type="text/x-red" data-template-name="blynk-websockets-out-write">
<div class="form-row" id="websocket-client-row">
<label for="node-input-client"><i class="fa fa-bookmark"></i> <span>Connection</span></label>
<input type="text" id="node-input-client">
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Virtual Pin</span></label>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="blynk-websockets-out-write">
<p>Blynk write node.</p>
<p>This node will write the value in payload to the specified pin number.</p>.
</script>
<!-- Blynk out Node - Email -->
<script type="text/x-red" data-template-name="blynk-websockets-out-email">
<div class="form-row" id="websocket-client-row">
<label for="node-input-client"><i class="fa fa-bookmark"></i> <span>Connection</span></label>
<input type="text" id="node-input-client">
</div>
<div class="form-row">
<label for="node-input-email"><i class="fa fa-tag"></i> <span>Email</span></label>
<input type="text" id="node-input-email" placeholder="Email address">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="blynk-websockets-out-email">
<p>Blynk email node.</p>
<p>This node will send an email using your msg.topic for subject and msg.payload for content.
<br />
Remember to add the email widget in your project and that the Blynk server has a setting how many emails per minute to send.
</p>
</script>
<!-- Blynk Server configuration node -->
<script type="text/x-red" data-template-name="blynk-websockets-client">
<div class="form-row">
<label for="node-config-input-path"><i class="fa fa-bookmark"></i> Url</label>
<input type="text" id="node-config-input-path" placeholder="ws://blynk-cloud.com:8080/websockets">
</div>
<div class="form-row">
<label for="node-config-input-key"><i class="fa fa-bookmark"></i> Project key</label>
<input type="text" id="node-config-input-key" placeholder="Blynk token">
</div>
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-tips">
<p>The url of Blynk Cloud Server is:<br>
<b>ws://blynk-cloud.com:8080/websockets</b></p>
</div>
</script>
<script type="text/x-red" data-help-name="blynk-websockets-client">
<p>This configuration node connects to a Blynk WebSocket Server on the specified URL.
<br /><br />
The url of Blynk Cloud Server is:<br>
<b>ws://blynk-cloud.com:8080/websockets</b></p>
</script>