我有两个通过蓝牙连接的 iPhone 设备。是否可以获得这些设备之间的信号强度?如果可以的话,如何?
谢谢,
凯德
查看通过蓝牙将数据从一台设备传输到另一台设备的 Apple 示例项目。BTLE 苹果示例代码
您可以通过 RSSI(接收信号强度指示)的值了解信号强度
在示例代码中,收到数据时您将获得 RSSI 值。检查项目中BTLECentralViewController.m中的以下方法:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
// Reject any where the value is above reasonable range
if (RSSI.integerValue > -15) {
return;
}
// Reject if the signal strength is too low to be close enough (Close is around -22dB)
if (RSSI.integerValue < -35) {
return;
}
NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);
// Ok, it's in range - have we already seen it?
if (self.discoveredPeripheral != peripheral) {
// Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it
self.discoveredPeripheral = peripheral;
// And connect
NSLog(@"Connecting to peripheral %@", peripheral);
[self.centralManager connectPeripheral:peripheral options:nil];
}
}
每次当您从另一台设备收到广告数据时。您将收到 RSSI 值,从中您可以找到设备的强度和范围。
还看一下Wiki 上的 RSSI 详细信息
我希望这会对你有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)