added catch for write error unknown peripheral

This commit is contained in:
icanos 2020-01-14 18:08:02 +00:00
parent 74ee9e0c21
commit dfdc7b4927

View file

@ -315,6 +315,7 @@ class PlejdService extends EventEmitter {
return false; return false;
} }
try {
const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data); const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data);
this.characteristics.data.write(encryptedData, false); this.characteristics.data.write(encryptedData, false);
@ -323,6 +324,15 @@ class PlejdService extends EventEmitter {
this.characteristics.data.write(this._encryptDecrypt(this.cryptoKey, this.deviceAddress, writeData), false); this.characteristics.data.write(this._encryptDecrypt(this.cryptoKey, this.deviceAddress, writeData), false);
} }
} }
catch (error) {
console.log('error: writing to plejd: ' + error);
console.log('will reconnect and try again.');
this.writeQueue.push(data);
this.disconnect();
this.connect();
}
}
onAuthenticated() { onAuthenticated() {
// Start ping // Start ping