Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise( (resolve, reject) =>{
BleManager.startNotification(this.peripheralId, this.nofityServiceUUID[index], this.nofityCharacteristicUUID[index])
.then(() => {
console.log('Notification started');
resolve();
})
.catch((error) => {
console.log('Notification error:',error);
reject(error);
});
});
}
setTimeout(() => {
BleManager.startNotification(peripheral.id, service, bakeCharacteristic).then(() => {
console.log('Started notification on ' + peripheral.id);
setTimeout(() => {
BleManager.write(peripheral.id, service, crustCharacteristic, [0]).then(() => {
console.log('Writed NORMAL crust');
BleManager.write(peripheral.id, service, bakeCharacteristic, [1,95]).then(() => {
console.log('Writed 351 temperature, the pizza should be BAKED');
/*
var PizzaBakeResult = {
HALF_BAKED: 0,
BAKED: 1,
CRISPY: 2,
BURNT: 3,
ON_FIRE: 4
};*/
});
});
return new Promise( (resolve, reject) =>{
BleManager.startNotification(this.peripheralId, this.nofityServiceUUID, this.nofityCharacteristicUUID)
.then(() => {
console.log('Notification started');
resolve();
})
.catch((error) => {
console.log('Notification error:',error);
reject(error);
});
});
}
setTimeout(() => {
BleManager.startNotification(id, service, loadCellCharacteristic).then(() => {
console.log('Started sensing/notification on ' + id);
}).catch((error) => {
console.log('Notification error', error);
});
}, 200);
});
}).then( (peripheralInfo)=>{
console.log('Connected peripheralInfo: ', peripheralInfo);
this.peripheralId = peripheralInfo.id;
this.getUUID(peripheralInfo);
if(this.nofityServiceUUID.length == 4 || this.nofityServiceUUID.length != 36 ||
this.nofityServiceUUID == '' || this.nofityCharacteristicUUID == '' ||
this.writeServiceUUID == '' ||this.writeCharacteristicUUID == ''){
return 'invalid';
}
return BleManager.startNotification(this.peripheralId, this.nofityServiceUUID, this.nofityCharacteristicUUID)
}).then((status) => {
this.isConnecting = false; //当前蓝牙连接结束
setTimeout(() => {
BleManager.startNotification(peripheral.id, service, contentsCharacteristic).then(() => {
console.log('Started notification on ' + peripheral.id);
setTimeout(() => {
BleManager.write(peripheral.id, service, filenameCharacteristic, stringToBytes("/code.py")).then(() => {
console.log('Wrote filename');
setFileState("nameSet");
});
}, 500);
}).catch((error) => {
console.log('Notification error', error);
});
}, 200);
});