This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blynk-api.html
462 lines (420 loc) · 16 KB
/
blynk-api.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<!--
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 getPinType(type) {
switch (type) {
case 'A':
type = 'Analog';
break;
case 'D':
type = 'Digital';
break;
case 'V':
type = 'Virtual';
break;
default:
break;
}
return type;
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function ws_oneditprepare() {
/*if(this.client) {
$("#node-input-mode").val('client').change();
}*/
}
function api_oneditsave() {
}
function preparePinIn() {
$("#node-input-pin_all").on("change", function () {
if ($(this).is(":checked")) {
$("#node-input-pin").parent().hide();
} else {
$("#node-input-pin").parent().show();
}
}).change();
}
function api_onConfigSave() {
var ws = $("#node-config-input-path").val();
var url = $("#node-config-input-api").val();
if (url) {
if (url.substr(-1) != '/') url += '/';
$("#node-config-input-api").val(url);
} else if (ws) {
url = ws.replace('/websockets', '/').replace('wss:', 'https:').replace('ws:', 'http:');
$("#node-config-input-api").val(url);
}
}
$(document).on('change', 'select#node-input-type_connect', function () {
var typeConnect = this.value;
// if(typeConnect == 'ws' && $("#node-input-pin_type").val() != 'V') {}
if (typeConnect == 'ws') {
//$('select#node-input-pin_type option[value="D"]').attr('disabled','disabled');
$('select#node-input-pin_type option[value!="V"]').attr('disabled', 'disabled');
$("#node-input-pin_type").val('V');
} else {
$('select#node-input-pin_type option[value!="V"]').removeAttr('disabled');
}
});
$(document).on('change', 'select#node-input-pin_type', function () {
var pinType = this.value;
if (pinType != 'V' && $("#node-input-type_connect").val() != 'api') {
// alert('Digital pin only send via API');
$("#node-input-type_connect").val('api');
}
});
function ws_label() {
_pin = 'no pin';
_type = '';
switch (this.type) {
case 'blynk-api-in-read':
_type = 'Read Event';
break;
case 'blynk-api-in-write':
_type = 'Write Event';
break;
case 'blynk-api-out-read':
_type = 'Read';
break;
case 'blynk-api-out-write':
_type = 'Write';
break;
default:
break;
}
if (typeof this.pin === 'number') {
if (this.pin_type) {
_pin = this.pin_type + this.pin + ' - ' + _type;
} else {
_pin = this.pin + ' - ' + _type;
}
}
if (this.pin_all) {
_pin = 'All Pins' + ' - ' + _type;
}
if (this.type == "blynk-api-out-email") {
return this.name || this.email || 'email';
}
if (this.type == "blynk-api-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-api-client', {
category: 'config',
defaults: {
name: { value: '' },
api: { value: '' },
path: { value: '', required: true, validate: RED.validators.regex(/^((?!\/debug\/ws).)*$/) },
key: { value: '', required: true }
},
inputs: 0,
outputs: 0,
label: ws_label,
oneditsave: api_onConfigSave,
});
RED.nodes.registerType('blynk-api-in-read', {
category: 'Blynk API',
paletteLabel: 'read event',
defaults: {
name: { value: '' },
pin: { value: 0 },
pin_type: { value: 'V' },
pin_all: { value: 0 },
client: { type: "blynk-api-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: api_oneditsave,
oneditprepare: preparePinIn
});
RED.nodes.registerType('blynk-api-in-write', {
category: 'Blynk API',
paletteLabel: 'write event',
defaults: {
name: { value: '' },
pin: { value: 0 },
pin_type: { value: 'V' },
pin_all: { value: 0 },
client: { type: "blynk-api-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: api_oneditsave,
oneditprepare: preparePinIn
});
RED.nodes.registerType('blynk-api-out-write', {
category: 'Blynk API',
paletteLabel: 'write',
defaults: {
name: { value: '' },
type_connect: { value: 'ws' }, // ws - api
pin_type: { value: 'D' }, // Virtual - Digital - Analog
pin: { value: 0 },
client: { type: "blynk-api-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: api_oneditsave,
oneditprepare: ws_oneditprepare
});
RED.nodes.registerType('blynk-api-out-read', {
category: 'Blynk API',
paletteLabel: 'read',
defaults: {
name: { value: '' },
type_connect: { value: 'api' }, // ws - api
pin_type: { value: 'D', required: true },
pin: { value: '', required: true },
client: { type: "blynk-api-client", validate: ws_validateclient }
},
color: "#1BC17C",
inputs: 1,
outputs: 1,
icon: "white-globe.png",
align: "right",
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
label: ws_label,
oneditsave: api_oneditsave,
oneditprepare: ws_oneditprepare
});
RED.nodes.registerType('blynk-api-out-email', {
category: 'Blynk API',
paletteLabel: 'email',
defaults: {
name: { value: '' },
email: {},
client: { type: "blynk-api-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: api_oneditsave,
oneditprepare: ws_oneditprepare
});
})();
</script>
<!-- Blynk Input Node - Read -->
<script type="text/x-red" data-template-name="blynk-api-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_all"><i class="fa fa-cogs"></i> <span>Pins</span></label>
<input type="checkbox" id="node-input-pin_all" value="1" style="width: auto; vertical-align: top;"> All Pins</span></input>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Pin</span></label>
<select id="node-input-pin_type" style="width:25%">
<option value="V">Virtual Pin</option>
<option value="D">Digital Pin</option>
</select>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin" style="width:45%">
</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-api-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-api-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_all"><i class="fa fa-cogs"></i> <span>Pins</span></label>
<input type="checkbox" id="node-input-pin_all" value="1" style="width: auto; vertical-align: top;"> All Pins</span></input>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Pin</span></label>
<select id="node-input-pin_type" style="width:25%">
<option value="V">Virtual Pin</option>
<option value="D">Digital Pin</option>
</select>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin" style="width:45%">
</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-api-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-api-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-type_connect"><i class="fa fa-tag"></i> <span>Type connect</span></label>
<select id="node-input-type_connect" style="width:70%">
<option value="ws">Websocket</option>
<option value="api">API</option>
</select>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Pin</span></label>
<select id="node-input-pin_type" style="width:25%">
<option value="V">Virtual Pin</option>
<option value="D">Digital Pin</option>
<!-- <option value="A">Analog Pin</option> -->
</select>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin" style="width:45%">
</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-api-out-write">
<p>Write pin value.</p>
<p>This node will write the value in payload to the specified pin number.</p>.
</script>
<!-- Blynk out Node - Read -->
<script type="text/x-red" data-template-name="blynk-api-out-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-type_connect"><i class="fa fa-tag"></i> <span>Type connect</span></label>
<select id="node-input-type_connect" style="width:70%" disabled>
<option value="ws">Websocket</option>
<option value="api">API</option>
</select>
</div>
<div class="form-row">
<label for="node-input-pin"><i class="fa fa-tag"></i> <span>Pin</span></label>
<select id="node-input-pin_type" style="width:25%">
<option value="V">Virtual Pin</option>
<option value="D">Digital Pin</option>
<option value="A">Analog Pin</option>
</select>
<input type="number" id="node-input-pin" min="0" max="128" placeholder="pin" style="width:45%">
</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-api-out-read">
<p>Get pin value.</p>
</script>
<!-- Blynk out Node - Email -->
<script type="text/x-red" data-template-name="blynk-api-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-api-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-api-client">
<div class="form-row">
<label for="node-config-input-path"><i class="fa fa-bookmark"></i> Url WS</label>
<input type="text" id="node-config-input-path" placeholder="ex. ws://blynk-cloud.com/websockets">
</div>
<div class="form-row">
<label for="node-config-input-api"><i class="fa fa-bookmark"></i> Endpoint API</label>
<input type="text" id="node-config-input-api" placeholder="ex. http://blynk-cloud.com/">
</div>
<div class="form-row">
<label for="node-config-input-key"><i class="fa fa-bookmark"></i> Auth Token</label>
<input type="text" id="node-config-input-key" placeholder="ex. "f45626c103a94983b469637978b0c78a"">
</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 websocket of Blynk Cloud Server is:<br>
<b>ws://blynk-cloud.com/websockets</b><br>
or with secure SSL:<br>
<b>wss://blynk-cloud.com/websockets</b>
API Endpoint:<br>
<b>http://blynk-cloud.com</b></p>
</div>
<div class="form-tips">
Url for Local server is:<br>
<b>ws://<your-local-ip>:8080/websockets</b><br>
or with secure SSL:<br>
<b>wss://<your-local-ip>:9443/websockets</b></p>
API Endpoint:<br>
<b>http://<your-local-ip>:8080</b></p>
</div>
</script>
<script type="text/x-red" data-help-name="blynk-api-client">
<p>This configuration node connects to a Blynk WebSocket Server on the specified URL.</p>
</script>