Reputation: 409
So, I'm scanning for bluetooth peripherals and logging the strength of their signals.
- (void)viewDidLoad
{
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[centralManager scanForPeripheralsWithServices:nil options:nil];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Peripheral Discovered");
NSLog(@"%ld", (long)RSSI.integerValue);
}
At the method centralManager:didDiscoverPeripheral:advertisementData:RSSI: I have access to the RSSI number (signal strength).
What is the best way to get a closest to realtime update of this value?!
Should I set a timer and call scanForPeripheralsWithServices every X seconds? Should I implement some sort of recursive callback?
Is there any better way to get the peripheral signal strength?
Upvotes: 0
Views: 776
Reputation: 114846
You can periodically call the readRSSI
method on the CBPeripheral object.
Discussion
When you call this method to retrieve the RSSI of the peripheral while it is currently connected to the central manager, the peripheral calls the peripheralDidUpdateRSSI:error: method of its delegate object. If the RSSI value of the peripheral is successfully retrieved, you can access it through the peripheral’s RSSI property.
Upvotes: 3