我有两个通过蓝牙连接的 iPhone 设备。是否有可能在这些设备之间获得信号强度?如果可能的话,怎么样? 谢谢, K.D
最佳答案
查看用于通过蓝牙将数据从一台设备传输到另一台设备的 Apple 示例项目。 BTLE Apple Sample Code
可以通过RSSI(Received signal strength indication)的值来判断信号强度
在示例代码中,您将在收到数据时获得 RSSI 值。在Project中的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 值,您可以找到设备的强度和范围。
另请查看 RSSI Details on Wiki
希望对你有帮助
关于iphone - iphone 设备之间的蓝牙信号强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14588699/