optimization

This commit is contained in:
icanos 2020-01-20 21:32:46 +00:00
parent dc6faaf07e
commit 85a194b794
2 changed files with 6 additions and 6 deletions

View file

@ -294,12 +294,12 @@ class PlejdService extends EventEmitter {
const self = this;
try {
logger('sending challenge to device');
//logger('sending challenge to device');
await this.characteristics.auth.WriteValue([0], {});
logger('reading response from device');
//logger('reading response from device');
const challenge = await this.characteristics.auth.ReadValue({});
const response = this._createChallengeResponse(this.cryptoKey, challenge);
logger('responding to authenticate');
const response = this._createChallengeResponse(this.cryptoKey, Buffer.from(challenge));
//logger('responding to authenticate');
await this.characteristics.auth.WriteValue([...response], {});
this.emit('authenticated');
@ -346,7 +346,7 @@ class PlejdService extends EventEmitter {
this.pingRef = setInterval(async () => {
logger('ping');
await this.ping();
}, 5000);
}, 3000);
await this.ping();
}

View file

@ -29,8 +29,8 @@ async function main() {
// init the BLE interface
const plejd = new PlejdService(cryptoKey, true);
plejd.on('connectFailed', () => {
console.log('plejd-ble: were unable to connect, will retry connection in 10 seconds.');
setTimeout(() => {
console.log('plejd-ble: were unable to connect, will retry connection in 10 seconds.');
plejd.init();
}, 10000);
});