我已经连接了设备,想开始有关特定服务和特性的通知,但是我无法获得确切的serviceuuid和featureuuid。
test(peripheral) {
if (peripheral){
if (peripheral.connected){
BleManager.disconnect(peripheral.id);
}else{
BleManager.connect(peripheral.id)
.then(() => {
let peripherals = this.state.peripherals;
let p = peripherals.get(peripheral.id);
if (p) {
p.connected = true;
peripherals.set(peripheral.id, p);
this.setState({peripherals});
}
setTimeout(() => {
BleManager.retrieveServices(peripheral.id)
.then((peripheralInfo) => {
// console.log("peripheralInfo-->>> ",peripheralInfo['characteristics']);
var service = '0000fee0-0000-1000-8000-00805f9b34fb';
// var bakeCharacteristic = '13333333-3333-3333-3333-333333330003';
var Characteristic = '00000006-0000-3512-2118-0009af100700';//peripheralInfo['characteristics'][0]['characteristic'];
setTimeout(() => {
BleManager.startNotification(peripheral.id, service, Characteristic).then(() => {
console.log('Started notification on ' + peripheral.id);
setTimeout(() => {
BleManager.read(peripheral.id, service, Characteristic).then((readData) => {
return(
<Text>readData</Text>
)
var data = Array.from(byteArray, function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('')
console.log(data);
});
// BleManager.write(peripheral.id, service, Characteristic, [100]).then(() => {
// console.log('Write: ' + data);
// });
}, 500);
}).catch((error) => {
console.log('Notification error', error);
});
}, 200);
});
}, 900);
}).catch((error) => {
console.log('Connection error', error);
});
}
}
}
这是我连接设备然后启动通知的功能。
如何启动有关所有服务和特征的通知?