反应本机 ble plx MonitorCharacteristicForService 无法正常工作

问题描述 投票:0回答:1

我是蓝牙开发新手。

我尝试使用此服务和特征uuid从蓝牙设备读取数据。

这是我得到的uuid

但是在我根据react-native-ble-plx的文档连接到设备之后 尝试监控或读取设备(我希望每1分钟左右获取一次读取数据) 但监控代码不起作用。

有没有遗漏的步骤?你能给我示例代码吗? 我尝试了每个 uuid 特征,但没有一个起作用。 这是我的代码:

manager.startDeviceScan(null, null, (error, device) => {
    if (error) {
      // Handle error (scanning will be stopped automatically)
      console.log('eror device scan',JSON.stringify(error))
      return
    }

    if (device.name === deviceName) {
      // Stop scanning as it's not necessary if you are scanning for one device.
      manager.stopDeviceScan()
      // Proceed with connection.
      device
      .connect()
      .then(async (device) => {
        
        let allServicAndChar = device.discoverAllServicesAndCharacteristics()
        console.log('allServicAndChar',JSON.stringify(allServicAndChar));

        return allServicAndChar;
      })
      .then(async device => {
        console.log('read characteristic');
        
        if(manager){
          //this code is called
           console.log('this code is called')
          // code below me is no response
          device.monitorCharacteristicForService('fee7', 'FEC8', (error, characteristic) => {
            
            if(error){
              __DEV__ && console.log('errorc',JSON.stringify(error));
            }else{
              console.log('===',characteristic?.value);
              
            }

          })
          
        }
      })
      .catch(error => {
        // Handle errors
        console.log('error connect to a device',JSON.stringify(error));
      })

    }
reactjs react-native react-native-ble-plx
1个回答
0
投票

如果您发现了什么,请告诉我,我面临着完全相同的问题

到目前为止我发现的是,您必须首先使用 writeDescriptorForDevice() 来“启用”通知属性

但我正在努力寻找描述符 UUID

© www.soinside.com 2019 - 2024. All rights reserved.