⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
5 posts / 0 new
Last post
Anonymous (not verified)
BLE profile help 14681

Hi,

I'm trying to create a BLE profile for sending sensor data over BLE link. Can you point me in the direction where I can find example for this? Is there a document where i can read on implementing a custom profile?

Regards

Device:
JK_Dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2016-08-22 23:07
Hi Mutahir,

Hi Mutahir,

Eventually, we will have an application note to describe this process - but in the mean time, you could use ble_peripheral located in demos to get you started or pxp reporter. As for a customer service, within SDK 1.0.8, you could reference our serial port service (sps.c) located in the ble_services folder. SPS is a custom service that uses the constructs of the SDKs APIs to create a custom service. Following the flow of the SDK, in the application layer, you use the following two lines to initialize the service:

ble_service_t *svc;

svc = my_service_init(callbacks cb);
ble_service_add(svc);

----------------------------------------------------

You can then follow the flow of the other services from the init functions - from the sps_init function:

ble_service_t *sps_init(sps_callbacks_t *cb)
{
uint16_t num_attr, sps_tx_desc_h, sps_rx_desc_h, sps_flow_ctrl_desc_h;
sp_service_t *sps;
att_uuid_t uuid;

sps = OS_MALLOC(sizeof(*sps));
memset(sps, 0, sizeof(*sps));

num_attr = ble_gatts_get_num_attr(0, 3, 5);

ble_uuid_from_string(UUID_SPS, &uuid);
ble_gatts_add_service(&uuid, GATT_SERVICE_PRIMARY, num_attr);

/* SPS Server TX */
ble_uuid_from_string(UUID_SPS_SERVER_TX, &uuid);
ble_gatts_add_characteristic(&uuid, GATT_PROP_NOTIFY, ATT_PERM_NONE,
sps_server_tx_size, 0, NULL, &sps->sps_tx_val_h);

ble_uuid_create16(UUID_GATT_CLIENT_CHAR_CONFIGURATION, &uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_RW, 2, 0, &sps->sps_tx_ccc_h);

ble_uuid_create16(UUID_GATT_CHAR_USER_DESCRIPTION, &uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_tx_desc), 0, &sps_tx_desc_h);

/* SPS Server RX */
ble_uuid_from_string(UUID_SPS_SERVER_RX, &uuid);
ble_gatts_add_characteristic(&uuid, GATT_PROP_WRITE_NO_RESP, ATT_PERM_WRITE,
sps_server_rx_size, 0, NULL, &sps->sps_rx_val_h);

ble_uuid_create16(UUID_GATT_CHAR_USER_DESCRIPTION, &uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_rx_desc), 0, &sps_rx_desc_h);

/* SPS Flow Control */
ble_uuid_from_string(UUID_SPS_FLOW_CTRL, &uuid);
ble_gatts_add_characteristic(&uuid, GATT_PROP_WRITE_NO_RESP | GATT_PROP_NOTIFY, ATT_PERM_WRITE,
1, 0, NULL, &sps->sps_flow_ctrl_val_h);

ble_uuid_create16(UUID_GATT_CLIENT_CHAR_CONFIGURATION, &uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_RW, 2, 0, &sps->sps_flow_ctrl_ccc_h);

ble_uuid_create16(UUID_GATT_CHAR_USER_DESCRIPTION, &uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_flow_control_desc), 0, &sps_flow_ctrl_desc_h);

/* Register SPS Service */
ble_gatts_register_service(&sps->svc.start_h, &sps->sps_tx_val_h, &sps->sps_tx_ccc_h,
&sps_tx_desc_h, &sps->sps_rx_val_h, &sps_rx_desc_h,
&sps->sps_flow_ctrl_val_h, &sps->sps_flow_ctrl_ccc_h,
&sps_flow_ctrl_desc_h, 0);

/* Set value of Characteristic Descriptions */
ble_gatts_set_value(sps_tx_desc_h, sizeof(sps_tx_desc), sps_tx_desc);
ble_gatts_set_value (sps_rx_desc_h sizeof (sps_rx_desc), sps_rx_desc);
ble_gatts_set_value(sps_flow_ctrl_desc_h, sizeof(sps_flow_control_desc),
sps_flow_control_desc);

sps - > svc。end_h = sps->svc.start_h + num_attr;
sps - > svc。write_req = handle_write_req;
sps - > svc。read_req = handle_read_req;
sps - > svc。event_sent = handle_event_sent;
sps->cb = cb;

return &sps->svc;
}

mutahir (not verified)
Thanks for the extensive

Thanks for the extensive reply, much appreciated. Coming back to ble_peripheral how do i modify the my_service to have a readable data value that I can update regularly.

JK_Dialog
Offline
Last seen:2 months 2 weeks ago
Staff
加入:2016-08-22 23:07
Again, please refer to sps.c

Again, please refer to sps.c (or any of the other ble profiles) for the example. The my_service_init does nothing at this point, but could be modified. You could change the characteristic that is there to GATT_PROP_READ and then register a read callback. Registering the read call back is illustrated on line 287 of sps.c, and setting the value is also illustrated.

/* Set value of Characteristic Descriptions */
ble_gatts_set_value(sps_tx_desc_h, sizeof(sps_tx_desc), sps_tx_desc);
ble_gatts_set_value (sps_rx_desc_h sizeof (sps_rx_desc), sps_rx_desc);
ble_gatts_set_value(sps_flow_ctrl_desc_h, sizeof(sps_flow_control_desc),
sps_flow_control_desc);

sps - > svc。end_h = sps->svc.start_h + num_attr;
sps - > svc。write_req = handle_write_req;
sps - > svc。read_req = handle_read_req;
sps - > svc。event_sent = handle_event_sent;
sps->cb = cb;

return &sps->svc;

mutahir (not verified)
thanks really helped

thanks really helped