Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get advertisement data for BLE in iOS

I'm creating an app that gets the UUID of all BLE devices within range. I've gotten it working fine in Android, where it gives me the advertisement data as a byte array. Now I'm trying to do the same in iOS.

I'm running a scan and it's detecting the device, and in the callback there's an NSDictionary called advertisementData. But the only information in it is as follows:

kCBAdvDataChannel = 39;
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = jaalee;
kCBAdvDataTxPowerLevel = 0;

Am I right in thinking I should be getting the entirety of the advertising packet? If not, how can I get it?

like image 381
user2564511 Avatar asked Apr 03 '14 09:04

user2564511


People also ask

What is advertisement data in BLE?

Advertising Data Format. When a BLE device is advertising, it periodically transmits packets, which contain information such as the preamble, access address, CRC, Bluetooth sender address, and so on.

Which channels does BLE use for advertising?

The device advertises on three channels. The advertising channels are channel 37 (2402 MHz), channel 38 (2426 MHz), and channel 39 (2480 MHz).

What is Bluetooth advertising packet?

Periodic advertising: Another feature of Bluetooth 5 Extended Advertisements is Periodic Advertisements. These are used for broadcasting packets to devices at a set period between two unconnected devices, meaning that more than one device can listen and tune in on these periodic advertisements.

What is BLE directed advertising?

Directed Advertising This is a special-purpose type of advertising, designed to invite a specific peer device to connect as quickly as possible.


2 Answers

Unfortunately, iOS does not allow you to access the raw advertisement data. I wrote a blog post demonstrating this. While the post is specifically about iBeacons, it applies to any BLE advertisement.

EDIT: To clarify, you can read the raw manufacturer data bytes or service data bytes of non-iBeacon advertisements. It is only the iBeacon advertisements that have their manufacturer data bytes hidden by CoreLocation. See here: Obtaining Bluetooth LE scan response data with iOS

The equivalent MacOS CoreLocation methods do allow this, so it is probably an intentional security or power saving restriction on iOS.

like image 70
davidgyoung Avatar answered Sep 21 '22 15:09

davidgyoung


Based on official documentation from Apple iOS and my personal experience:

YES, iOS does not allow you to access the RAW advertisement data.

BUT

If your intention is to put information in advertising packet and read them from the iOS app without connect with the peripheral, this is possible to do. Here is described how:

1) in the peripheral firmware you have to insert your manufacturer specifica data in the advertising packet, with the data type GAP_ADTYPE_MANUFACTURER_SPECIFIC (0xFF) Remember that in the Manufacturer Specific Data, first 2 octets contain the Company Identifier Code followed by the additional manufacturer specific data

2) in the iOS

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

You can see the manufacturer specific data in advertisementData dictionary with key:

CBAdvertisementDataManufacturerDataKey

3) if you want that in your App receive a callback notification every advertising packet sent by peripheral to iOS, remember to change the scan option to YES. Look at this post about that: Core Bluetooth - constant RSSI updates of in-range devices

In my blog post will be soon a tutorial: http://www.megabri.com/

like image 45
megabri Avatar answered Sep 20 '22 15:09

megabri