简体   繁体   English

BLE:从后台iOS应用程序广告UUID

[英]BLE : Advertising of UUID from background iOS app

As the iOS documentation states, when an iOS application that utilizes BLE as a peripheral moves to background mode, the local name is not advertised and all service UUIDs are placed in the overflow area. 正如iOS文档所述,当使用BLE作为外围设备的iOS应用程序转移到后台模式时,不会公布本地名称,并且所有服务UUID都放在溢出区域中。 The documentation states that they can only be discovered by an iOS device. 该文档指出它们只能由iOS设备发现。

My overall question is how exactly this happens on a lower level. 我的整体问题是如何在较低的层面上发生这种情况。 Using a non-iOS bluetooth packet sniffer, I examined the advertisement data structure from my iOS peripheral app when it was in foreground and in background modes. 使用非iOS蓝牙数据包嗅探器,当我处于前台和后台模式时,我检查了我的iOS外围应用程序中的广告数据结构。 The advertisement data structure in foreground mode looks to be what was expected, similar to other advertisement data from non-iOS devices, such as those I have coming from an Android device. 前台模式中的广告数据结构看起来是预期的,类似于来自非iOS设备的其他广告数据,例如我来自Android设备的那些。

When the iOS app is background mode, this structure changes and the service UUID is not apparent. 当iOS应用程序是后台模式时,此结构会更改,并且服务UUID不明显。 I do not see anything suggesting an “overflow” area. 我没有看到任何暗示“溢出”区域。

How does a iOS central device discover a peripheral device that is in background mode if the UUID is not a part of the advertising data packet? 如果UUID不是广告数据包的一部分,iOS中央设备如何发现处于后台模式的外围设备?

There is a so-called overflow area according to Apple documentation . 根据Apple文档,有一个所谓的溢出区域。 More information can be found in this archive page about Core Bluetooth concepts . 有关Core Bluetooth概念的此存档页面中可以找到更多信息。

I've sniffed the packets over the air. 我已经在空中嗅探了数据包。 You can read the details on github . 您可以在github上阅读详细信息。 What iOS does is broadcasting custom packages with particular bits representing UUIDs. iOS所做的是使用代表UUID的特定位来广播自定义包。 For example UUID 3333 is represented by a bit going up in the BLE package. 例如,UUID 3333由BLE包中的一个位表示。

04 3E 24 02 01 00 01 8C 91 A0 AD 8F 40 18 02 01 1A 14 FF 4C 00 01 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 D3 04 3E 24 02 01 00 01 8C 91 A0 AD 8F 40 18 02 01 1A 14 FF 4C 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D3

You see here 02 somewhere surrounded by zeros (preceding D3 the 8-bit RSSI value). 你在这里看到02被零包围的地方(在D3之前的8位RSSI值)。

Every UUID is one-hot encoded to a bit in this range. 每个UUID都是单热编码到此范围内的一位。 This will lead to collisions. 这将导致碰撞。 You will notice that if you send 1001 by one iPhone and scan for 3333 by another iPhone you will receive the advertisements as if UUID 3333 is sent. 您会注意到,如果您通过一部iPhone发送1001并通过另一部iPhone扫描3333 ,您将收到广告,就好像发送了UUID 3333

Note, there is a lot of nonsense written about this. 请注意,有很多关于此的废话。 It's just a regular undirected BLE packet. 它只是一个常规的无向BLE数据包。 It's not a scan response. 这不是扫描响应。 When running this on the background I've reliable gotten BLE packets every 0.2 seconds. 在后台运行时,我每隔0.2秒就可靠地获得BLE数据包。

在此输入图像描述

Time is on the x-axis (over a couple of days). 时间在x轴上(过了几天)。 The interval between messages is plotted on the y-axis. 消息之间的间隔绘制在y轴上。 You see that at times the intervals are a multiple of 0.2 seconds. 您会看到有时间隔是0.2秒的倍数。 However, you also see that this is shared across the three iPhones (one broadcasting 1000 , one broadcasting FFFF , and one broadcasting 3333 in the background). 但是,您还会看到这是在三个iPhone之间共享的(一个广播1000 ,一个广播FFFF ,一个广播3333在后台)。 This means that this is an artifact from the laptop receiving the messages. 这意味着这是接收消息的笔记本电脑中的工件。 The iPhones are probably even more robust than this. iPhone可能比这更强大。 Over the entire weekend the battery drop is like 25% , which has very likely to do with other things than the BLE broadcasting. 在整个周末,电池电量下降了25% ,这很可能与BLE广播以外的其他事情有关。

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

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