简体   繁体   English

使用Core Bluetooth访问iOS 8上的自定义BLE设备的原始广告数据

[英]Accessing raw advertisement data for custom BLE device on iOS 8 using Core Bluetooth

I'd like to ask whether it is possible to access the raw advertisement data from a custom BLE device built using a Raspberry Pi from the Core Bluetooth API ? 我想询问是否可以从使用Core Bluetooth API的Raspberry Pi构建的自定义BLE设备访问原始广告数据

The use case is to broadcast constantly changed data from the Raspberry Pi to multiple iOS devices in the proximity and consume them in an iOS app. 用例是将Raspberry Pi中不断更改的数据广播到附近的多个iOS设备,并在iOS应用程序中使用它们。 See the topology description in this article . 看到拓扑描述这篇文章

I already found out that the iBeacon advertisements are filtered out from the Core Bluetooth API and are only accessible from the Core Location API only, which requires the knowledge of the UUID. 我已经发现iBeacon广告已从Core Bluetooth API中过滤掉,并且只能从Core Location API访问,这需要了解UUID。 Due to the constantly changed data a custom iBeacon wouldn't work for this particular use case anyway. 由于数据不断变化,自定义iBeacon无论如何都不适用于此特定用例。 But I am unsure whether I could achieve that with Core Bluetooth? 但我不确定我是否能用Core Bluetooth实现这一目标?

You can do what you want if you change the Raspberry Pi to transmit a non-iBeacon format. 如果更改Raspberry Pi以传输非iBeacon格式,则可以执行所需操作。 CoreBluetooth only filters out the raw bytes of advertisements if they are iBeacon advertisements. 如果广告是iBeacon广告, CoreBluetooth仅过滤广告的原始字节。 See here: Obtaining Bluetooth LE scan response data with iOS 请参阅此处: 使用iOS获取蓝牙LE扫描响应数据

A simple solution is to change your iBeacon advertisement to an open-source AltBeacon advertisement. 一个简单的解决方案是将您的iBeacon广告更改为开源的AltBeacon广告。 CoreLocation will no longer pick it up, but CoreBluetooth will. CoreLocation将不再接收它,但CoreBluetooth会。

Here's an example of what you get in the advertisementData NSDictionary in the CoreBluetooth centralManager:didDiscoverPeripheral:advertisementData:RSSI: callback. 以下是您在CoreBluetooth centralManager:didDiscoverPeripheral:advertisementData:RSSI:中的advertisementData NSDictionaryCoreBluetooth centralManager:didDiscoverPeripheral:advertisementData:RSSI: callback。 This example is the result of detecting an AltBeacon advertisement (an open-source beacon standard), with identifiers 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 1 2: 此示例是检测AltBeacon广告(开源信标标准)的结果,标识符为2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 1:

{
    kCBAdvDataIsConnectable = 0;
    kCBAdvDataManufacturerData = <1801beac 2f234454 cf6d4a0f adf2f491 1ba9ffa6 00010002 be00>;
}

You can see how to decode the above bytes by looking at the AltBeacon spec here. 您可以在此处查看AltBeacon规范,了解如何解码上述字节 Note that the above are the actual contents of the NSDictionary for a detected advertisement on iOS8 that were printed to the console using an NSLog statement. 请注意,以上是iOS8上检测到的广告的NSDictionary的实际内容,这些广告使用NSLog语句打印到控制台。

Quick answer is "there is no direct way". 快速回答是“没有直接的方法”。

Why: 为什么:
Because CoreBluetooth filters out advertisement data, except kCBAdvDataServiceUUIDs , kCBAdvDataLocalName , so there is now way to pass custom data from peripheral to central via advertising. 因为CoreBluetooth过滤掉了广告数据,除了kCBAdvDataServiceUUIDskCBAdvDataLocalName ,所以现在有办法通过广告将自定义数据从外围设备传递到中心。

How can we workaround: 我们如何解决方法:
Peripheral 外围设备
1) Holds some custom service (let's name it 'BeaconService'). 1)保留一些自定义服务(让我们将其命名为'BeaconService')。
2) BeaconService contains Beacon's UUID, major, minor characteristics. 2)BeaconService包含Beacon的UUID,主要,次要特征。
3) Advertises BeaconService UUID (via kCBAdvDataServiceUUIDs key). 3)通告BeaconService UUID(通过kCBAdvDataServiceUUIDs键)。

Central 中央
1) Scans for peripherals that have BeaconService UUID. 1)扫描具有BeaconService UUID的外围设备。
2) Found peripherals are queued. 2)找到外围设备排队。
3) Connection is opened to queued peripherals, and the iBeacon information is read from BeaconService. 3)连接打开到排队的外围设备,并从BeaconService读取iBeacon信息。
4) Read values can be used to start CoreLocation beacon monitoring/ranging. 4)读取值可用于启动CoreLocation信标监视/测距。

So by this way you can make bridge from CoreBluetooth to CoreLocation. 因此,通过这种方式,您可以建立从CoreBluetooth到CoreLocation的桥接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM