问题
I'm writing an app (on android) to read RSSI from bluetooth devices, for location recognition using rssi fingerprinting. I have working code for reading RSSI from non-paired and discoverable bluetooth devices that are not BT4.0/BLE. I would like to know if I get some BLE-based tags (such as stick-n-find) would I be able to read their RSSI only by putting myself (my android phone to be precise), into bt-discovery mode.
回答1:
In BT Low Energy the roles are switched. The Stick-n-find would be Advertising it's service(s) Name or other information. When you receive that Advertisement from your iOS APP you will get an RSSI value with that Advertisement.
So just do something like:
@property (strong, nonatomic) CBCentralManager *CM;
#define SERVICE_ID_STR "4d1dc300-424d-13e2-a661-0002a55dc51b"
self.CM = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber
numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
CBUUID *peripheralUUID = [CBUUID UUIDWithString:@SERVICE_ID_STR];
[self.CM scanForPeripheralsWithServices:[NSArray arrayWithObject:myUUID]
options:scanOptions];
then when it hears the Advertisement package from a Peripheral you will get
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI {
where you get the RSSI.
If you only want a callback to didDiscoverPeripheral for the FIRST time the peripheral is heard then don't use the ScanOptions
[self.CM scanForPeripheralsWithServices:[NSArray arrayWithObject:myUUID] options:nil];
回答2:
From what I gather, some Android phone manufacturers may include BLE support, but it is not currently supported by Android directly (as of 4.2 Jellybean). See Issue 33371 for more info.
It looks like BLE may be coming in the next Android version as hinted in this Google Groups discussion.
来源:https://stackoverflow.com/questions/15493978/rssi-from-bluetooth-low-energy-ble-tags