iphone设备之间的蓝牙信号强度

时间:2013-01-29 17:28:49

标签: iphone ios objective-c ipad

我有两个通过蓝牙连接的iphone设备。是否有可能在这些设备之间获得信号强度?如果可能,怎么样? 谢谢, K.D

1 个答案:

答案 0 :(得分:8)

查看Apple Sample Project,通过蓝牙将数据从一台设备传输到另一台设备。 BTLE Apple Sample Code

您可以通过RSSI(接收信号强度指示)

的值找出信号强度

在示例代码中,您将在收到数据时获得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

我希望这会有所帮助。