I am not getting the proper signal value for identify the distance between iPhone and the bluetooth device. I've connect the Peripheral
device with below code.
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
if (central.state != CBCentralManagerStatePoweredOn) {
return;
}
switch (central.state) {
case CBCentralManagerStatePoweredOn:{
centmanager = central;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[centmanager scanForPeripheralsWithServices:nil options:options];
NSArray *uuidArray = @[uuid];
NSArray *itemArray = [central retrieveConnectedPeripheralsWithServices:uuidArray];
if ([itemArray count]>0) {
self.myPeripheral = [itemArray objectAtIndex:0];
[centmanager connectPeripheral:self.myPeripheral options:nil];
}
return;
}
break;
default:
break;
}
}
And in the delegate method of the CBCentralManagerDelegate
, I got the RSSI
value but that is not right and consistent.
- (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) {
NSLog(@"\n\n Above reasonable range and Range ==>>> %d",RSSI.integerValue);
return;
}
// Reject if the signal strength is too low to be close enough (Close is around -22dB)
if (RSSI.integerValue < -35) {
NSLog(@"\n\n Out Of Range and Range ==>>> %d",RSSI.integerValue);
return;
}
}