- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using hello_sensor application in WICED SMART SDK V1.1.0.
I want to set my bcm20732's device name like this: prefix string + bt address. For example, if prefix is "RAE", and bt address is 0x20732a123456, so the device name should be "RAE20732a123456".
I found this ticket: To change the device's name dynamically, then I followed its content and had changed the adv device name, this is code snippet:
//convert bt address to string
static void btAddr2Ascii( UINT8* hex, UINT8 size, char *buff )
{
UINT8 value;
UINT8 i;
for( i = 0; i < size; i++){
value = hex[size - 1 - i];
//ble_trace1("value: 0x%x\r\n", value);
if( (value >> 4) < 10 ){
*buff++ = (value >> 4) + '0'; //'0' ~ '9'
}
else if ( ( (value >> 4) > 9 ) && ( (value >> 4) < 16 ) ){
*buff++ = (value >> 4) + 55; //'A' ~ 'F'
}
if( (value & 0xf) < 10 ){
*buff++ = (value & 0xf) + '0'; //'0' ~ '9'
}
else if ( ( (value & 0xf) > 9 ) && ( (value & 0xf) < 16 ) ){
*buff++ = (value & 0xf) + 55; //'A' ~ 'F'
}
}
*buff++ = '\0';
}
......
char friendly_name[20];
BLE_ADV_FIELD adv[2];
//prepare name
memcpy(friendly_name, "RAE", 3 );
btAddr2Ascii(bda, 6, &friendly_name[3]);
//ble_trace1("friendly_name: %s\r\n", friendly_name);
adv[0].len = 1 + 1;
adv[0].val = ADV_FLAGS;
adv[0].data[0] = LE_LIMITED_DISCOVERABLE | BR_EDR_NOT_SUPPORTED;
// name
adv[1].len = strlen(friendly_name) + 1;
adv[1].val = ADV_LOCAL_NAME_COMP;
memcpy(adv[1].data, friendly_name, adv[1].len - 1);
bleprofile_GenerateADVData(adv, 2);
I can use iOS lightBlue to scan and find my bcm20732tag as peripheral and the device name is what I want, but after establishing a connection, the device name reverted to "Hello". I think that device name of gatt database should be changed either.
CHARACTERISTIC_UUID16 (0x0015, 0x0016, UUID_CHARACTERISTIC_DEVICE_NAME,
LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 16),
'H','e','l','l','o',0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
I used INT32 bleprofile_WriteHandle(UINT16 hdl, BLEPROFILE_DB_PDU *p_pdu); to change the gatt database,
db_pdu.len = 16;
memcpy(db_pdu.pdu, friendly_name, 16);
ble_trace1("wrHandle: 0x%X", bleprofile_WriteHandle(0x0015, &db_pdu));
the result of write handle was always 0x0d, so how can I change the device name of gatt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you should use 0x0016 for bleprofile_WriteHandle().
This is what I'm using. I hope it would help you.
-----
UINT8 *bda = emconinfo_getAddr();
sprintf(bleprofile_p_cfg->local_name, "RAE%02x%02x%02x%02x%02x%02x", bda[0x05], bda[0x04], bda[0x03], bda[0x02], bda[0x01], bda[0x00]);
BLEPROFILE_DB_PDU p_pdu;
p_pdu.len = 0x10;
memcpy(&p_pdu.pdu[0x00], bleprofile_p_cfg->local_name, strlen(bleprofile_p_cfg->local_name));
bleprofile_WriteHandle(0x0016, &p_pdu);
...
adv[1].len = strlen(bleprofile_p_cfg->local_name) + 0x01;
adv[1].val = ADV_LOCAL_NAME_COMP;
memcpy(adv[1].data, bleprofile_p_cfg->local_name, adv[1].len - 0x01);
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi dmiya,
Thanks for your advice, I think that it can work as what I want.
I still have question about INT32 bleprofile_WriteHandle(UINT16 hdl, BLEPROFILE_DB_PDU *p_pdu);
You can see that first parameter is hdl, handle, which is not handle value.