我的BLE 112模块存在配置问题:我无法显示扫描响应的内容。
我试图通过该方法的advertisementData字典访问它:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"advertData: %@", advertisementData);
}
我使用BlueGiga作为例子给出的代码:"BGScript": custom_advertisement - Custom advertisement packet creation 以下是zip文件custom_advertisement.zip
的网址以下是我在advertData中收到的内容:
adv: {
kCBAdvDataIsConnectable = 1;
kCBAdvDataManufacturerData = <ffffb1b2 b3>;
kCBAdvDataTxPowerLevel = 3;
}
但我几乎从未在iOS上显示扫描响应的内容,即本地名称CBAdvertisementDataLocalName。使用嗅探器,扫描响应可用,... ...
以下是用于格式化扫描响应的.bgs脚本的一部分:
# flags for discoverable/connectable
adv_data(0:1) = $02 # ad field length = 2 bytes
adv_data(1:1) = gap_ad_type_flags # ad field type = 0x01 (Flags)
adv_data(2:1) = $06 # flags = 0x06, connectable/undirected
# tx power field advertisement, iOS apps may need this
adv_data(3:1) = $02 # ad field length = 2 bytes
adv_data(4:1) = gap_ad_type_txpower # ad field type = 0x0A (TX Power)
adv_data(5:1) = $03 # TX power in dBm
# custom manufacturer
adv_data(6:1) = $06 # ad field length = 5 bytes (arbitrary, maybe more or less but minimum 3)
adv_data(7:1) = $ff # ad field type = 0xFF (Manufacturer Specific Data)
adv_data(8:1) = $ff # unknown/prototype Company Identifier Code - octet 2
adv_data(9:1) = $ff # unknown/prototype Company Identifier Code - octet 1
adv_data(10:1) = $b1 # custom data byte #1 (can be anything)
adv_data(11:1) = $b2 # custom data byte #2 (can be anything)
adv_data(12:1) = $b3 # custom data byte #3 (can be anything)
# -------------------------------
# build custom scan response data
# -------------------------------
# get Bluetooth MAC address of this device (NOTE: this is little-endian!)
call system_address_get()(mac_addr(0:6))
sr_data(0:1) = $13 # ad field length = 19 bytes (0x13)
sr_data(1:1) = gap_ad_type_localname_complete # ad field type = 0x09 (Complete local name)
sr_data(2:1) = $4d # 'M'
sr_data(3:1) = $79 # 'y'
sr_data(4:1) = $20 # ' '
sr_data(5:1) = $57 # 'W'
sr_data(6:1) = $69 # 'i'
sr_data(7:1) = $64 # 'd'
sr_data(8:1) = $67 # 'g'
sr_data(9:1) = $65 # 'e'
sr_data(10:1) = $74 # 't'
sr_data(11:1) = $20 # ' '
sr_data(12:1) = (mac_addr(2:1)/$10) + 48 + ((mac_addr(2:1)/$10)/10*7) # MAC byte 4 10's digit
sr_data(13:1) = (mac_addr(2:1)&$f) + 48 + ((mac_addr(2:1)&$f )/10*7) # MAC byte 4 1's digit
sr_data(14:1) = $3a # ':'
sr_data(15:1) = (mac_addr(1:1)/$10) + 48 + ((mac_addr(1:1)/$10)/10*7) # MAC byte 5 10's digit
sr_data(16:1) = (mac_addr(1:1)&$f) + 48 + ((mac_addr(1:1)&$f )/10*7) # MAC byte 5 1's digit
sr_data(17:1) = $3a # ':'
sr_data(18:1) = (mac_addr(0:1)/$10) + 48 + ((mac_addr(0:1)/$10)/10*7) # MAC byte 6 10's digit
sr_data(19:1) = (mac_addr(0:1)&$f) + 48 + ((mac_addr(0:1)&$f )/10*7) # MAC byte 6 1's digit
# set advertisement interval to 1s-2s, use all advertisement channels
# (note min/max parameters are in units of 625 uSec)
call gap_set_adv_parameters(1600, 3200, 7)
# set custom advertisement data
call gap_set_adv_data(0, 13, adv_data(0:13))
# set custom scan response data (i.e. the Device Name value)
call gap_set_adv_data(1, 20, sr_data(0:20))
有人作为主意吗?