我有两个通过蓝牙连接的iPhone设备。是否可以获取这些设备之间的信号强度?如果可以,应该怎么做? 谢谢, K.D
我有两个通过蓝牙连接的iPhone设备。是否可以获取这些设备之间的信号强度?如果可以,应该怎么做? 谢谢, K.D
请查看苹果蓝牙传输示例项目,了解如何通过蓝牙从一个设备传输数据到另一个设备。BTLE Apple Sample Code
您可以通过接收信号强度指示(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];
}
}