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,12 +315,22 @@ class PlejdService extends EventEmitter {
return false; return false;
} }
const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data); try {
this.characteristics.data.write(encryptedData, false); const encryptedData = this._encryptDecrypt(this.cryptoKey, this.deviceAddress, data);
this.characteristics.data.write(encryptedData, false);
let writeData; let writeData;
while ((writeData = this.writeQueue.shift()) !== undefined) { while ((writeData = this.writeQueue.shift()) !== undefined) {
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();
} }
} }