How to decode the BLE advertisement data

懵懂的女人 提交于 2019-12-20 04:48:26

问题


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]);
    }


}


来源:https://stackoverflow.com/questions/45854508/how-to-decode-the-ble-advertisement-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!