【发布时间】:2021-11-26 08:47:42
【问题描述】:
我已经从计算机模拟了一个信标,我正在尝试从我的 react 本机应用程序中读取信标信息(uuid、标识符等)。
我决定使用这个库 https://github.com/dotintent/react-native-ble-plx 作为图书馆。
我面临的问题是虽然它在我扫描时显示了一些设备,但名称、uuid 和其他信息显示为空。
例如:
'device', { serviceUUIDs: null,
isConnectable: null,
overflowServiceUUIDs: null,
txPowerLevel: null,
serviceData: null,
manufacturerData: 'TEACFCd6h5jcoxKqh9ACQqwTAAOBqZYcxQ==',
name: null,
mtu: 23,
rssi: -47,
solicitedServiceUUIDs: null,
localName: null,
id: '32:BD:32:6C:E9:C2',
这是我的代码
const bluetoothInstance = new BleManager();
const scanAndConnect = () => {
bluetoothInstance.startDeviceScan(null, { allowDuplicates: true }, (error, device) => {
console.log('device', device);
console.log('error', error);
if (error) {
// Handle error (scanning will be stopped automatically)
return;
}
if (device?.name === 'MyProjectName') {
bluetoothInstance.stopDeviceScan();
} else {
// bluetoothInstance.stopDeviceScan();
}
});
};
useEffect(() => {
bluetoothInstance.onStateChange((state) => {
console.log('state', state);
if (state === 'PoweredOn') {
scanAndConnect();
}
}, true);
}, []);
如何读取信标 uuid 和名称?有没有其他的图书馆可以推荐?还是代码中缺少某些内容?任何帮助将不胜感激。
【问题讨论】:
-
您能否使用诸如nRF Connect 之类的通用 BLE 扫描仪检查它们是否确实具有名称和服务 uuid?
-
我从另一个信标扫描仪检查过,它显示了我的模拟信标
标签: react-native bluetooth-lowenergy ibeacon beacon react-native-ble-plx