Sending multiple bytes to a characteristic

⚠️
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
Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Sending multiple bytes to a characteristic

Hi all,

I am trying to write multiple bytes to a characteristic using the ble_app_peripheral project from the SDK, following from Training_03_custom_profile_gatt_cmd_example_v1.

The issue I am currently facing is that the handler is not triggered when multiple bytes are send to the characteristic. I am sending the data from an android phone running BlueLoupe. Turning the LED on and off by sending 0x01 and 0x00 respectively works with no problems. I increased DEF_USER_LED_STATE_CHAR_LEN in user_custs1_def.h from 1 to several higher numbers, but none of them made the 583 execute the handler when other data was send to the characteristic than 0x00 or 0x01.

How can I modify the handler to be triggered when multiple bytes are send to a characteristic?

Kind regards,
Niek

注,我使用SDK 5.0.3.268 5.0.2.1but this option was not selectable

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

If i got the question correctly, you cant trigger the write handler depending on the bytes that you have on your characteristic, the write callback is triggered on each bulk of data (on each write command) that the client sends and not in each byte, in order to trigger the handler on each byte, you need to send data byte to byte from your central. In the custom profile implementation the gattc_write_cmd_ind_handler() function that notifies the application that a characteristic is written is executed once on each GATTC_WRITE_CMD_IND and sends only one CUSTS1_VAL_WRITE_IND per writting event.

Thanks MT_dialog

Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Hello MT_dialog,

Hello MT_dialog,

I am afraid I did not explain myself properly. I mean not to trigger the handler multiple times on one write event.
What I want is to send multiple bytes to a character and have the handler triggered only once. In the handler itself I want to use the multiple bytes.

I started editing the code from the training and made the following in user_custs1_impl.c
As this code shows, I want to handle all the bytes that are send to the handler at once.

void user_led_wr_ind_handler(ke_msg_id_t const msgid,
struct custs1_val_write_ind const*param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)

{
char n[8];
for(int i = 0; i < 8; i++){
n[i] = (char) param->value[i];
}
if(check_key(n)){
uint8_t led_state=0;
memcpy(&led_state,¶m->value[8],param->length);
if(led_state==LED_ON)
GPIO_SetActive(GPIO_LED_PORT,GPIO_LED_PIN);
else if (led_state==LED_OFF)
GPIO_SetInactive(GPIO_LED_PORT,GPIO_LED_PIN);
}
}

Kind regards,
Niek

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
Joined:2015-06-08 11:34
Hi Niekvdd,

Hi Niekvdd,

I am not able to understand what your issue is, you will be able to write more than one byte and send it over to the peripheral and the handler will occur. For example if you modify the characteristic's length to lets say 50 (#define DEF_CUST1_CTRL_POINT_CHAR_LEN 50) for example, the handler will trigger once and deliver to your application the pointer that points to the 50 bytes that the client has send over. You can make a simple test in the ble_app_peripheral example.

Thanks MT_dialog

Niekvdd
Offline
Last seen:1 year 11 months ago
Joined:2017-01-25 09:29
Hi MT_dialog,

Hi MT_dialog,

It is working now. Somewhere down the line I made myself believe that the handler was not triggered when I sent multiple bytes. I think it is because the led only turns on when you send hex 01 OR 0100, instead of 0001 what I had been testing with.

Thank you for your help!

Kind regards,
Niek