使用notify react-native-ble-manager读取数据将返回部分数据

时间:2020-07-05 20:13:11

标签: react-native bluetooth-lowenergy react-native-ble-plx

我正在使用BLE设备,并使用notify接收消息。我正在使用react-native-ble-manager

connectPeripheral = (per: Peripheral) => {
BleManager.connect(per.id)
  .then(async () => {
    console.log('Connected', per.name || per.id);
    const services = await BleManager.retrieveServices(per.id);
    console.log('Services', JSON.stringify(services));
    await BleManager.startNotification(per.id, ServiceId, CharecteristicId);
  })
  .catch((err) => {
    console.log('Error connecting', err, per.name || per.id);
  });
 };


const onUpdateValueForCharacteristic = bleManagerEmitter.addListener(
  'BleManagerDidUpdateValueForCharacteristic',
  this.onUpdateValueForCharacteristic,
);



onUpdateValueForCharacteristic = (
data: {
  value: any;
  peripheral: any;
  characteristic: any;
  service: any;
},
...args: any[]
) => {
console.log(
  data.value,
  data.peripheral,
  data.service,
  data.characteristic,
  args,
);

};

我在onUpdateValueForCharacteristic中收到的值只是预期的部分数据。 谁能帮忙使用notify来获取全部有效负载?

0 个答案:

没有答案