This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Help switching from notification to indication

Guys

I am a newbie using nordic modulesI am just starting to program here with a nRF52 and SDK 12.2

I was trying to edit the experimental_ble_app_blinky and experimental_ble_app_blink_central to use Indication instead of Notifications. may I am missing something because the two devices cant connect between them I am using a sniffer and I am getting only the peripheral advertising packets.

the changes I did to the peripheral code:

ble_lbs_on_button_change()

    ble_gatts_hvx_params_t params;
uint16_t len = 1; 

Data[0] = count++;			

memset(&params, 0, sizeof(params));
params.type = BLE_GATT_HVX_INDICATION; //BLE_GATT_HVX_NOTIFICATION;
params.handle = p_lbs->button_char_handles.value_handle;
params.p_data = Data[0]
params.p_len = &len;

return sd_ble_gatts_hvx(p_lbs->conn_handle, &params);

(2)

on the button_char_add():

  char_md.char_props.read   = 1;
char_md.char_props.indicate= 1;  // char_md.char_props.notify
char_md.p_char_user_desc  = NULL;
char_md.p_char_pf         = NULL;
char_md.p_user_desc_md    = NULL;
char_md.p_cccd_md         = &cccd_md;
char_md.p_sccd_md         = NULL;

and the central blinky changes on cccd_configure()

tx_message_t * p_msg;
uint16_t       cccd_val = enable ? BLE_GATT_HVX_INDICATION: 0; // BLE_GATT_HVX_NOTIFICATION 

Can some one give a hand? I cant be sure If I am doing it good or if there are extra changes

Thanks :)

  • Petter an aditional issue I am getting is... the central some times dont receive the notifications (data loss) when the two devices are 25feet+ away that is the main reason I am switching to use indications in case it helps to avoid data lost or in case a packet is not received. Using a sniffer I see the notification from the peripheral but for some reason the central does not receive it.

  • Why are you disconnecting? You should get a confirmation, but are you actually confirming the indication in the central application?

  • You will not lose any more packets with notifications compared to indications, they are both acked and retransmitted at the link layer. The difference is that indication has to be acknowledged at the application layer. See this for more information. If the central doesn't receive notifications at longer ranges it is probably because it is not receiving any packets at all.

  • So do I have to wait for BLE_EVT_TX_COMPLETE before kill the connection? I am going to test because now I am thinking a posible reason when I have a packet lost: In case the a packet lost I kill the connection to early, but I stll haven't any verification the BLE_EVT_TX_COMPLETE to do any retransmission in case this applies? Or how can I handle a packet lost when sending notification/indication to a central device

  • Hey Petter I added the sd_ble_gattc_hv_confirm to the central code when It receive an indication from the peripheral and in the peripheral code BLE_GATTS_EVT_HVC event when it receive the indication confrimation from the central after it I disconnect the two devices. It is working for now pretty good I am testing in case I lost some packet, in case a lost packet the peripheral send it again or do I have to wait 30sec for the timeout?

1 2 3