Ios 刷新许多蓝牙外围设备的RSSI值
我试图从几个蓝牙外围设备上测量iOS(6带BLE)上的RSSI指示灯。 我可以通过scanForPeripheral获得RSSI:Ios 刷新许多蓝牙外围设备的RSSI值,ios,objective-c,bluetooth,core-bluetooth,bluetooth-lowenergy,Ios,Objective C,Bluetooth,Core Bluetooth,Bluetooth Lowenergy,我试图从几个蓝牙外围设备上测量iOS(6带BLE)上的RSSI指示灯。 我可以通过scanForPeripheral获得RSSI: NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil]; [_manager scanForPeripheralsWithS
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[_manager scanForPeripheralsWithServices:nil
options:options];
加上:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
这是可行的,但我无法控制接收数据包的速率,结果似乎不确定
我读过:但我的速率根本不接近100毫秒(超过1~2秒)
如果我连接到设备上,readRSSI的结果似乎更可靠
我正在寻找一种在扫描模式下“刺激”外设进行更频繁更新的方法,或者一次连接到多个外设的方法
谢谢
编辑:我也尝试过快速启动/停止扫描,似乎在启动扫描时检测到更多设备,更新更频繁(假设您使用的是iOS设备:)CoreBluetooth可能有意限制其在天线上的活动速率。Bluetooth LE、Bluetooth Classic和Wi-Fi都位于iOS设备上的同一天线上,因此收音机会尽量将不必要的嘈杂声降至最低。你可以尝试在CoreBluetooth上安装一个bug来添加一个控制更新频率的选项或方法,但我不认为他们会实现它,因为他们的主要设计目标是:1。不要不必要地耗尽设备的电池电量。与其他天线的无线电共存。(他们也在Apple devforums上的帖子中说,例如,如果你想要比iOS BTLE实现更高的数据速率,你应该使用Bluetooth Classic或专为其设计的东西。BTLE首先是低功耗的,他们已经把这一点带到了逻辑的尽头。)(假设你在iOS设备上:)CoreBluetooth可能有意限制其在天线上的活动速率。Bluetooth LE、Bluetooth Classic和Wi-Fi都位于iOS设备上的同一天线上,因此收音机会尽量将不必要的嘈杂声降至最低。你可以尝试在CoreBluetooth上安装一个bug来添加一个控制更新频率的选项或方法,但我不认为他们会实现它,因为他们的主要设计目标是:1。不要不必要地耗尽设备的电池电量。与其他天线的无线电共存。(他们在Apple devforums上的帖子中也提到,例如,如果你想要比iOS BTLE实现更高的数据速率,你应该使用Bluetooth Classic或专为其设计的产品。BTLE首先是低功耗的,他们已经将这一点考虑到了逻辑上。)我相信你已经弄明白了这一点,但为了防止有人(像我一样)在寻找其他信息时遇到这种情况,如果你没有使用coreLocation的其他iOS设备,你需要调用
外围设备更新程序si:
委托使用[self.myPeripheral readRSSI]代码>
您可以在updateValue委托中随时调用DidUpdateValue ForCharacteristic:
中的RSSI数据更新
viewDidLoad中不需要此选项:
NSDictionary*options=etc.
此NSDictionary是在didiscoverperipheral:
委托中创建的
因此,整个流程将是:
检查您在获取RSSI数据的NSLog中是否接收到RSSI
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
if ([localName length] > 0){
NSLog(@"Discovered: %@ RSSI: %@", peripheral.name, RSSI);
// your other needs ...
}
在此处调用peripheraldidaupdaterssi:
,因为如果您将notify value设置为YES[peripheral setNotifyValue:YES forCharacteristic:characteristic],更新将持续发生代码>
- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
//Call the peripheralDidUpdateRSSI delegate ..
[self.myPeripheral readRSSI];
// do all of your other characteristic value updates here
}
readRSSI
每次更新之前的特征值时,都会调用代表,在代表处对UILabel(或您正在使用的任何内容)执行RSSI更新:
- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error;
{
_rssiLabel.text = [self.myPeripheral.RSSI stringValue];
NSLog(@"RSSI Method”);
}
如果你的应用程序不需要特征值,只需在其中运行一个循环,无论何时需要RSSI值刷新。我肯定你已经找到了这个问题,但万一有人遇到这个问题(就像我刚才做的那样)寻找其他信息,如果您没有将其他iOS设备与coreLocation一起使用,则需要使用[self.myPeripheral readRSSI]调用外围设备更新器si:
委托代码>
您可以在updateValue委托中随时调用DidUpdateValue ForCharacteristic:
中的RSSI数据更新
viewDidLoad中不需要此选项:
NSDictionary*options=etc.
此NSDictionary是在didiscoverperipheral:
委托中创建的
因此,整个流程将是:
检查您在获取RSSI数据的NSLog中是否接收到RSSI
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
if ([localName length] > 0){
NSLog(@"Discovered: %@ RSSI: %@", peripheral.name, RSSI);
// your other needs ...
}
在此处调用peripheraldidaupdaterssi:
,因为如果您将notify value设置为YES[peripheral setNotifyValue:YES forCharacteristic:characteristic],更新将持续发生代码>
- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
//Call the peripheralDidUpdateRSSI delegate ..
[self.myPeripheral readRSSI];
// do all of your other characteristic value updates here
}
readRSSI
每次更新之前的特征值时,都会调用代表,在代表处对UILabel(或您正在使用的任何内容)执行RSSI更新:
- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error;
{
_rssiLabel.text = [self.myPeripheral.RSSI stringValue];
NSLog(@"RSSI Method”);
}
如果你的应用程序不需要特征值,只需在其中运行一个循环,无论你需要什么时间刷新RSSI值。事实上,peripal.readRSSI()
和peripheraldupdaterssi
之间的延迟就像一秒钟
我认为最好的方法是读取BLE设备本身上的RSSI值并将其发送到iOS设备。事实上,peripal.readRSSI()
和peripheradUpdaterssi
之间的延迟就像一秒钟
我认为最好的方法是读取BLE设备本身的RSSI值并将其发送到iOS设备。外围设备根据外围设备的固件进行广告。这可以设置为从100ms低到几乎高达2秒。
当使用iOS设备作为蓝牙外设时,我没有办法改变它。
以下是苹果的文档:请参阅第3.5节。。。
外围设备根据外围设备的固件发布广告。这可以设置为从100ms低到几乎100毫秒