corebluetooth Reading RSSI error:The operation was cancelled
Asked Answered
N

1

8

I'm developing an app using Corebluetooth framework,

and connect to a BLE device to get RSSI value.

I set a function to read RSSI periodly, the timer code is below

NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1.2f target:self selector:@selector(detectRSSI) userInfo:nil repeats:YES];

and the detectRSSI code is below

- (void)detectRSSI
{
    [self.peripheral readRSSI];
}

So the question is,

the function works fine , but when I set time interval less then 1.2 sec,

the peripheralDidUpdateRSSI will randomly report error message like this:

The operation was cancelled.

And it wouldn't happened if the rate is more than 1.2sec.

Does anyone have any idea to read RSSI value more frequently (0.5 sec or less)?

Naca answered 21/3, 2013 at 5:59 Comment(3)
Perhaps try instead: peripheral.RSSIEmir
The RSSI isn't change if I only call [peripheral RSSI] or peripheral.RSSI. The value would be updated after calling [peripheral readRSSI].Finally i found the answer that the limit of reading frequency is define by firmware.Naca
If you using BLE use didRangeBeacons:. The device will only scan so many times per sec.Alceste
M
0

I encounter the same problem as well. For me, it works when I simply add sleep(2) inside peripheralDidUpdateRSSI. Just don't forget to use background queue when initialising CBCentralManager.

- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error
{
    NSLog(@"RSSI = %@", peripheral.RSSI);
    sleep(2);
    [self.connectedPeripheral readRSSI];
}
Manic answered 21/2, 2014 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.