How to decode the BLE advertisement data

2019-02-27 19:14发布

问题:

After scanning for the BLE device, I call the below method:

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI 

and receive the following advertisement data as such:

{ kCBAdvDataManufacturerData = <ffff0215 cf6d4a0f .....  adf2f491 ... ... > }

How can I decode the data and access its information?

回答1:

It seems that you are expecting this advertising packet to be decodable as iBeacon, but it is not. The full bytes listed in comments are:

ff ff 02 15 e8 4a 40 af 7b 8d e8 8d 4a 7b 40 af af e8 4a 40 40 af 7b 8d c3

The 02 15 is the company code of Apple, but the next two bytes e8 4a are not consistent with the pattern you will see for iBeacon. There is no reason to think, therefore, that beacon identifiers are encoded in this packet.

What do the data mean? It's impossible to say without more information about what software or hardware is transmitting this packet and what its intended purpose is. All we can tell is that it is a manufacturer advertisement (type ff) and is reporting itself as an Apple device.

If you want to figure out the meaning of the packet, you need to determine what app or hardware manufacturer is emitting it and seek documentation from that entity.



回答2:

my small code snippet:

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    // NSLog(@"%@", central);
    NSLog(@"%@", peripheral);
    //NSLog(@"%@", advertisementData);
    NSLog(@"%@", RSSI);

    // more details:
    NSString* name = [peripheral name]; // name in NULL in iOS 6
    NSLog(@"%@", name);

    for (NSString * key in advertisementData){
        NSLog(@"%@", advertisementData[key]);
    }


}