Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 95662a6

Browse files
committed
Fix connection, boost ver
1 parent ade9df7 commit 95662a6

File tree

4 files changed

+24
-42
lines changed

4 files changed

+24
-42
lines changed

blynk-espruino.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/* Copyright (c) 2015 Volodymyr Shymanskyy. See the file LICENSE for copying permission. */
2-
3-
function string_of_enum(e,value)
4-
{
5-
for (var k in e) if (e[k] == value) return k;
6-
return "Unknown(" + value + ")";
7-
}
1+
/* Copyright (c) 2015-2019 Volodymyr Shymanskyy. See the file LICENSE for copying permission. */
2+
'use strict';
83

94
function blynkHeader(msg_type, msg_id, msg_len) {
105
return String.fromCharCode(
@@ -16,20 +11,22 @@ function blynkHeader(msg_type, msg_id, msg_len) {
1611

1712
var MsgType = {
1813
RSP : 0,
19-
LOGIN : 2, //"token" or "mail pass"
14+
LOGIN : 2,
2015
PING : 6,
2116
TWEET : 12,
2217
EMAIL : 13,
2318
NOTIFY : 14,
2419
BRIDGE : 15,
2520
HW_SYNC : 16,
2621
INTERNAL : 17,
27-
SMS : 18,
2822
PROPERTY : 19,
2923
HW : 20,
24+
HW_LOGIN : 29,
3025

3126
REDIRECT : 41,
32-
DEBUG_PRINT : 55
27+
DEBUG_PRINT : 55,
28+
29+
EVENT_LOG : 64,
3330
};
3431

3532
var MsgStatus = {
@@ -130,7 +127,7 @@ var Blynk = function(auth, options) {
130127

131128
this.auth = auth;
132129
var options = options || {};
133-
this.heartbeat = options.heartbeat || (10*1000);
130+
this.heartbeat = options.heartbeat || 10000;
134131

135132
// Auto-detect board
136133
if (options.board) {
@@ -233,7 +230,7 @@ Blynk.prototype.onReceive = function(data) {
233230

234231
if (msg_type === MsgType.RSP) {
235232
//console.log('> ', string_of_enum(MsgType, msg_type), msg_id, string_of_enum(MsgStatus, msg_len));
236-
if (!self.profile) {
233+
237234
if (self.timerConn && msg_id === 1) {
238235
if (msg_len === MsgStatus.OK || msg_len === MsgStatus.ALREADY_REGISTERED) {
239236
clearInterval(self.timerConn);
@@ -243,7 +240,7 @@ Blynk.prototype.onReceive = function(data) {
243240
self.sendMsg(MsgType.PING);
244241
}, self.heartbeat);
245242
console.log('Authorized');
246-
self.sendMsg(MsgType.INTERNAL, ['ver', '0.5.3', 'buff-in', 256, 'dev', 'espruino']);
243+
self.sendMsg(MsgType.INTERNAL, ['ver', '0.5.4', 'buff-in', 256, 'dev', 'espruino']);
247244
self.emit('connect');
248245
} else {
249246
//if invalid token, no point in trying to reconnect
@@ -261,7 +258,7 @@ Blynk.prototype.onReceive = function(data) {
261258
}
262259
}
263260
}
264-
}
261+
265262
self.buff_in = self.buff_in.substr(5);
266263
continue;
267264
}
@@ -370,17 +367,13 @@ Blynk.prototype.connect = function() {
370367
self.conn.on('data', function(data) { self.onReceive(data); });
371368
self.conn.on('end', function() { self.end(); });
372369

373-
self.sendRsp(MsgType.LOGIN, 1, self.auth.length, self.auth);
370+
self.sendRsp(MsgType.HW_LOGIN, 1, self.auth.length, self.auth);
374371
});
375372
self.conn.on('error', function(err) { self.error(err); });
376373
};
377374

378-
if (self.profile) {
379-
doConnect();
380-
} else {
381375
self.timerConn = setInterval(doConnect, 10000);
382376
doConnect();
383-
}
384377
};
385378

386379
Blynk.prototype.disconnect = function(reconnect) {
@@ -431,6 +424,9 @@ Blynk.prototype.setProperty = function(pin, prop, val) {
431424
this.sendMsg(MsgType.PROPERTY, [pin, prop].concat(val));
432425
};
433426

427+
Blynk.prototype.eventLog = function(name, descr) {
428+
this.sendMsg(MsgType.EVENT_LOG, [name].concat(descr));
429+
};
434430

435431
Blynk.prototype.syncAll = function() {
436432
this.sendMsg(MsgType.HW_SYNC);
@@ -453,8 +449,4 @@ Blynk.prototype.tweet = function(message) {
453449
this.sendMsg(MsgType.TWEET, [message]);
454450
};
455451

456-
Blynk.prototype.sms = function(message) {
457-
this.sendMsg(MsgType.SMS, [message]);
458-
};
459-
460452
exports.Blynk = Blynk;

blynk.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/* Copyright (c) 2015 Volodymyr Shymanskyy. See the file LICENSE for copying permission. */
2-
1+
/* Copyright (c) 2015-2019 Volodymyr Shymanskyy. See the file LICENSE for copying permission. */
32
'use strict';
43

5-
var C = {
6-
};
7-
84
/*
95
* Helpers
106
*/
@@ -43,8 +39,7 @@ function blynkHeader(msg_type, msg_id, msg_len) {
4339

4440
var MsgType = {
4541
RSP : 0,
46-
REGISTER : 1, //"mail pass"
47-
LOGIN : 2, //"token" or "mail pass"
42+
LOGIN : 2,
4843
SAVE_PROF : 3,
4944
LOAD_PROF : 4,
5045
GET_TOKEN : 5,
@@ -58,9 +53,9 @@ var MsgType = {
5853
BRIDGE : 15,
5954
HW_SYNC : 16,
6055
INTERNAL : 17,
61-
SMS : 18,
6256
PROPERTY : 19,
6357
HW : 20,
58+
HW_LOGIN : 29,
6459

6560
REDIRECT : 41,
6661
DEBUG_PRINT : 55,
@@ -265,7 +260,7 @@ var Blynk = function(auth, options) {
265260

266261
this.auth = auth;
267262
var options = options || {};
268-
this.heartbeat = options.heartbeat || (10*1000);
263+
this.heartbeat = options.heartbeat || 10000;
269264

270265
console.log("\n\
271266
___ __ __\n\
@@ -461,7 +456,7 @@ Blynk.prototype.onReceive = function(data) {
461456
self.sendMsg(MsgType.PING);
462457
}, self.heartbeat);
463458
console.log('Authorized');
464-
self.sendMsg(MsgType.INTERNAL, ['ver', '0.5.3', 'buff-in', 4096, 'dev', 'js']);
459+
self.sendMsg(MsgType.INTERNAL, ['ver', '0.5.4', 'buff-in', 4096, 'dev', 'js']);
465460
self.emit('connect');
466461
} else {
467462
console.log('Could not login:', string_of_enum(MsgStatus, msg_len));
@@ -612,7 +607,7 @@ Blynk.prototype.connect = function() {
612607
self.conn.on('data', function(data) { self.onReceive(data); });
613608
self.conn.on('end', function() { self.end(); });
614609

615-
self.sendRsp(MsgType.LOGIN, 1, self.auth.length, self.auth);
610+
self.sendRsp(MsgType.HW_LOGIN, 1, self.auth.length, self.auth);
616611
});
617612
self.conn.on('error', function(err) { self.error(err); });
618613
};
@@ -698,10 +693,6 @@ Blynk.prototype.tweet = function(message) {
698693
this.sendMsg(MsgType.TWEET, [message]);
699694
};
700695

701-
Blynk.prototype.sms = function(message) {
702-
this.sendMsg(MsgType.SMS, [message]);
703-
};
704-
705696
if (typeof module !== 'undefined' && ('exports' in module)) {
706697
exports.Blynk = Blynk;
707698

control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: blynk-library-js
2-
Version: 0.5.3
2+
Version: 0.5.4
33
Description: Blynk library implementation for JavaScript (Node.js, Espruino)
44
Section: extras
55
Priority: optional

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blynk-library",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "Blynk library implementation for JavaScript (Node.js, Espruino)",
55
"author": "Volodymyr Shymanskyy",
66
"license": "MIT",
@@ -20,8 +20,7 @@
2020
"browser": {
2121
"./blynk-node.js": false
2222
},
23-
"dependencies": {
24-
},
23+
"dependencies": {},
2524
"keywords": [
2625
"Arduino",
2726
"Espruino",

0 commit comments

Comments
 (0)