increase the length of name during advertising

13 posts / 0 new
Last post
christopher.j.m...
Offline
Last seen:6 years 2 months ago
加入:2015-01-29 19:44
increase the length of name during advertising

I am modifying the DSPS example code and am running into issues with changing the name that the device advertises as. The name constant is listed under .NVDS_TAG_DEVICE_NAME and there seems to be a length limitation of 8 bytes but I need 10. I tried changing the
#define ADV_DATA_LEN 0x1F (in co_bt.h)
to something with 2 more bits but this breaks the code

Specifically what are the contents of the 31 byte advertising message?
I can only see the
device name
device_name_length

Also I thought the BLE stack limited packets to 20 bytes, does advertising have a different rule or does it just sent two packets?

MHv_Dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2013-12-06 15:10
Hi,

Hi,

A BLE advertisement package can actually carry 31bytes of payload in addition to the 6bytes Bluetooth Device Address - total of 37bytes.

In the DSPS implementation, 3 bytes are used for flags and 18 bytes are used for a unique service ID (includes one byte for length and one byte for type). This leaves 10bytes for the length of the name (1 byte), the data type of the name (1byte) and the name itself. As you can see this limits the name to 8bytes/characters.

但不要惊慌;o)

You don't have to put a unique service ID in the advertising data. You can just go ahead and remove it. In app_sps_device_project.h change

#define APP_DFLT_ADV_DATA "\x11\x07\xb7\x5c\x49\xd2\x04\xa3\x40\x71\xa0\xb5\x35\x85\x3e\xb0\x83\x07"
#define APP_DFLT_ADV_DATA_LEN (18)

to

#define APP_DFLT_ADV_DATA "\x04\xFFHi!"
#define APP_DFLT_ADV_DATA_LEN (5)

This changes the advertised data to a manufacturer specific data set of the phrase "Hi!". And you can extend the Bluetooth Device name in NVDS like this:

.NVDS_TAG_DEVICE_NAME = "DA1458x123", //This is 10 characters long
.NVDS_TAG_BD_ADDRESS = {0xCC, 0x00, 0x00, 0xCA, 0xEA, 0xCC},
.ADV_DATA_TAG_LEN = 27,
.SCAN_RESP_DATA_TAG_LEN = 10,
.DEVICE_NAME_TAG_LEN = 10,

I hope that helps.

christopher.j.m...
Offline
Last seen:6 years 2 months ago
加入:2015-01-29 19:44
Thank you MHv_dialog! That

Thank you MHv_dialog! That definitely helps clarify my problem and I was able to get that to work. I was curious about the second byte of the APP_DFLT_ADV_DATA definition. Before this was marked as 0x07 which is commented in the code as "* x07 - Complete list of 128-bit UUIDs available" and you changed it to 0xFF and described that as a manufacture specific data set. Could you explain a little more about why you changed that and what it means? Thanks for your help, ~Chris

MHv_Dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2013-12-06 15:10
Hi,

Hi,

You can put different segments of data in your advertising. Sometimes it is useful to tell the world what kind of services your device offers. This allows, say, a smartphone to scan for devices and only list devices that offer a specific service applicable to the smartphone application - like a heart rate service. You can have as many data segments as space allows. Each segment is organized as follows:

The length of the segment includes the one byte of the type and the data. The type can be 0x02 for flags, 0x09 for Bluetooth Device name or 0xFF for manufacturer specific data. You can see all the data types on the website of the BT SIG:https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile.

为了让你对你的德维克更多的空间e name, I had to replace the "Complete list of 128bit..." with something that does not require as many bytes. We could also have placed your BD name in the scan response packet. In doing so, you would have to follow the format as described above and the BD name would only be detected by devices that are scanning in active mode.

redbear
Offline
Last seen:5 years 10 months ago
加入:2015-01-30 08:50
Hi,

Hi,
How to change .NVDS_TAG_DEVICE_NAME from smart phone app?
when da14580 receive data from app, eg: new dev name, how to replace the old one?
Thank you!

MT_dialog
Offline
Last seen:3 months 3 days ago
Staff
加入:2015-06-08 11:34
Hi redbear

Hi redbear

You can use following CMDs to BLE low layer, ( you can find all commands list in gapm_task.h)

GAPM_SET_DEV_NAME_CMD;

GAPM_GET_DEV_NAME_CMD;

GAPM_GET_DEV_BDADDR_CMD;

Details of commands can be found in following link:

http://support.dialog-semiconductor.com/resource/gap-interface-specification

Following is some code for your reference:

1. following function set_device_name from HCI host ====================

/* Internal */

void set_device_name(void)

{

struct gapm_set_dev_name_cmd *req = BleMsgAlloc(GAPM_SET_DEV_NAME_CMD, TASK_GAPM, TASK_APP,9 + sizeof(struct gapm_set_dev_name_cmd));

req->operation = GAPM_SET_DEV_NAME;

req->length = 10;

sprintf ((char *)请求- > name, "DialogDemo");

BleSendMsg((void *) req);

}

==============================

For BleSendMsg, BleMsgAlloc please check code in file ble_msg.c

==============================

Our code of handle GAPM_SET_DEV_NAME is as follow:

========================================

case GAPM_SET_DEV_NAME:

{

uint8_t status = (uint8_t) GAP_ERR_NOT_SUPPORTED;

#if (BLE_ATTS)

/* update name */

status = attmdb_att_set_value(GAPM_GET_ATT_HANDLE(GAP_IDX_DEVNAME), param->length,

(uint8_t*) &(param->name[0]));

#endif /* BLE_ATTS */

/* send command complete event with status code */

gapm_send_complete_evt(GAPM_CFG_OP, status);

}

Thanks MT_dialog

anthony42
Offline
Last seen:5 years 7 months ago
加入:2015-07-17 08:21
Hi, thank you for your reply.

Hi, thank you for your reply.

I found ble_msg.c in sdk, not in DA14580_DialogBeacon_3.40.6,
Do I need to copy all needed files to the current proj? any other way?
I found these code from app_task.c:
case GAPM_RESET:
{
// set device configuration
struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD,
TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd);
app_configuration_func(dest_id, cmd);
ke_msg_send(cmd);
}
//--------------------------------------------------------
I added these, seems not working:
case GAPM_SET_DEV_NAME:
attmdb_att_set_value(GAPM_GET_ATT_HANDLE(GAP_IDX_DEVNAME), 7,
"da14580"); // I don't know how to get the name form below msg, so ...
break;
in app_dia_xx_proj.c add:
void app_set_dev_name(const uint8_t * name)
{
struct gapm_set_dev_name_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_NAME_CMD,
TASK_GAPM, TASK_APP, gapm_set_dev_name_cmd);
cmd->operation = GAPM_SET_DEV_NAME;
cmd->length = 7;
memcpy(&cmd->name, &name, 7);
ke_msg_send(cmd);
}

a button callback will call app_set_dev_name(name);
//-------------------------------------------------------
and, I need to save the new config data(dev name, adv interval, UUID,user defined cmd, etc), even after power off.
looking forward to your response.
Thank you!

MT_dialog
Offline
Last seen:3 months 3 days ago
Staff
加入:2015-06-08 11:34
Hi antony42,

Hi antony42,

Please try the following,

Just place a function in your project like this:

void set_device_name(void)
{
struct gapm_set_dev_name_cmd *req = KE_MSG_ALLOC(GAPM_SET_DEV_NAME_CMD,
TASK_GAPM,
TASK_APP,
gapm_set_dev_name_cmd
);
req->operation = GAPM_SET_DEV_NAME;
req->length = 6;
memcpy(req->name,"Dialog",6);
ke_msg_send(req);
}

And in file app_task.c catch the completition event GAPM_SET_DEV_NAME:

case GAPM_SET_DEV_NAME:
{
app_set_dev_name();
}
break;

with the function void app_set_dev_name(void){ return }

In the implementation i used a timer instead of a button who is triggered some time after connection.

Thanks MT_dialog

anthony42
Offline
Last seen:5 years 7 months ago
加入:2015-07-17 08:21
Hi MT_dialog,

Hi MT_dialog,
thank you for your reply,
I tried and it works! Thank you!

I need to configure the beacon from a smart phone,
and these data should be stored in the flash.
I found in CFG_PRF_DEVICE_CONFIG:
struct app_beacon_config_tag
{
uint8_t uuid[16];
uint16_t major;
uint16_t minor;
uint16_t company_id;
uint16_t adv_int;
uint8_t power;
uint8_t pad;
};
can I add some items to this structure?
eg: dev name, led control and several user defined parameters.

Thanks Anthony

MT_dialog
Offline
Last seen:3 months 3 days ago
Staff
加入:2015-06-08 11:34
Hi Antony42,

Hi Antony42,

Yes, you can add additional fields in the struct in order to store them in flash, you should also add the specific fields of the struct in beacon_params array in app_dialog_beacon_proj.c file.

Thanks MT_dialog

Joacimwe
Offline
Last seen:1 year 6 months ago
Guru
加入:2014-01-14 06:45
Note that you should probably

Note that you should probably use KE_MSG_ALLOC_DYN instead of KE_MSG_ALLOC when you allocate the gapm_set_dev_name_cmd to avoid corrupting the memory, like this (for a name of length 6):

KE_MSG_ALLOC_DYN(GAPM_SET_DEV_NAME_CMD, TASK_GAPM, TASK_APP, gapm_set_dev_name_cmd,6);

anthony42
Offline
Last seen:5 years 7 months ago
加入:2015-07-17 08:21
Hi Joacimwe,

Hi Joacimwe,
Thank you for your reply,
you are right!
today I test the set_dev_name func,sometimes the system corruped,
then I remember your answet, use KE_MSG_ALLOC_DYN works fine.
why ?
in the ref code KE_MSG_ALLOC was used a lot.

Joacimwe
Offline
Last seen:1 year 6 months ago
Guru
加入:2014-01-14 06:45
In the API documentation, you

In the API documentation, you can see that some of the message structs end with a dynamically-sized array, such as GAPM_SET_DEV_NAME_CMD, GAPM_WHITE_LIST_MGT_CMD, GAPM_RESOLV_ADDR_CMD etc. Since the sizeof(such a struct) assumes 0 elements in the array, the size they occupy must be added as well to the size that are allocated for the message.