我正在尝试创建自定义 BLE 广告和扫描响应。广告是 iBeacon。我还希望它广播服务的可用性。我不能将服务 uuid 放入广告数据中,因为它会太长(据我了解,Bluegiga 的 BGScript 只允许广告数据中包含 32 个八位字节)。我将服务 uuid 放在扫描响应中,希望这将允许移动设备查看服务,以便搜索并连接到设备。出于某种原因,我无法让它工作。iOS 不再将 BLE 设备作为 iBeacon 拾取,并且不识别该服务可用。我将为服务 uuid 使用什么 AD 类型,我将如何格式化该数据(包括服务 uuid)?
这是我到目前为止所拥有的:
广告数据
02 01 06 // flags
1a ff 4c 00 02 15 // manufacturer data, apple company id, iBeacon preamble
aa aa aa aa - aa aa - aa aa - aa aa - aa aa aa aa aa aa // iBeacon UUID
00 01 00 01 // iBeacon major, minor
c6 // measured tx power
扫描响应数据
11 // length
16 // ad type (I am not sure what this should be)
a5 b7 67 a0 - 74 9b - 11 e3 - 98 1f - 08 00 20 0c 9a 66 // service UUID
为了获得更好的上下文,这里是 BLE112 的 BGScript 部分:
event system_boot( major, minor, patch, build, ll_version, protocol_version, hw )
call gap_set_adv_parameters( 20, 100, 7 )
call gap_set_mode( gap_general_discoverable, gap_undirected_connectable )
# Flags
data( 0:1) = $02
data( 1:1) = $01
data( 2:1) = $06
# Manufacturer data
data( 3:1) = $1a
data( 4:1) = $ff
# Preamble
data( 5:1) = $4c
data( 6:1) = $00
data( 7:1) = $02
data( 8:1) = $15
# UUID
data( 9:1) = $aa
data(10:1) = $aa
data(11:1) = $aa
data(12:1) = $aa
data(13:1) = $aa
data(14:1) = $aa
data(15:1) = $aa
data(16:1) = $aa
data(17:1) = $aa
data(18:1) = $aa
data(19:1) = $aa
data(20:1) = $aa
data(21:1) = $aa
data(22:1) = $aa
data(23:1) = $aa
data(24:1) = $aa
# Major
data(25:1) = $00
data(26:1) = $01
# Minor
data(27:1) = $00
data(28:1) = $01
# Measured power (specified in 2's complement, so 0xC6 is -58)
data(29:1) = $c6
# Scan Response Data
sr_data( 0:1) = $11
sr_data( 1:1) = $21
# Service Uuid
sr_data( 2:1) = $a5
sr_data( 3:1) = $b7
sr_data( 4:1) = $67
sr_data( 5:1) = $a0
sr_data( 6:1) = $74
sr_data( 7:1) = $9b
sr_data( 8:1) = $11
sr_data( 9:1) = $e3
sr_data(10:1) = $98
sr_data(11:1) = $1f
sr_data(12:1) = $08
sr_data(13:1) = $00
sr_data(14:1) = $20
sr_data(15:1) = $0c
sr_data(16:1) = $9a
sr_data(17:1) = $66
# Set advertisement data
call gap_set_adv_data(0, 30, data(0:30))
call gap_set_adv_data(1, 18, sr_data(0:18))
#set bondable mode
call sm_set_bondable_mode(1)
end