Received empty data array after notification

Hi,

I adapted the nus_client from the Nordic Connect SDK v2.7.0. I changed the UUID and some function names, but in general the code stays the same. I can subscribe one of the characteristics and receive data from it. But the problem is, that everytime I receive a notification, I get another receive event with an empty data array. This leads to an unsubscribtion of the characteristic. 

00> D: [NOTIFICATION] data 0x2000d40c length 4
00> D: ble_mode_data_received
00> data: 01000000
00> D: [NOTIFICATION] data 0 length 0
00> D: [UNSUBSCRIBED]

The client only sends notifications with length = 1, so it's unlikely that the event comes from the client. The client is implemented in nrf5 SDK and sends data with the following code:

void ble_fob_on_mode_change(uint16_t conn_handle, ble_fob_t * p_fob, uint8_t mode_state)
{
    ble_gatts_value_t gatts_value;
    
    // Initialize value struct.
    memset(&gatts_value, 0, sizeof(gatts_value));

    gatts_value.len     = sizeof(uint8_t);
    gatts_value.offset  = 0;
    gatts_value.p_value = &mode_state;
	
    sd_ble_gatts_value_set(conn_handle,
                            p_fob->mode_char_handles.value_handle,
                            &gatts_value);
    
    // send notification
    if(conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        ble_gatts_hvx_params_t params;
        uint16_t len = sizeof(mode_state);

        memset(&params, 0, sizeof(params));
        params.type   = BLE_GATT_HVX_NOTIFICATION;
        params.handle = p_fob->mode_char_handles.value_handle;
        params.p_data = &mode_state;
        params.p_len  = &len;

        sd_ble_gatts_hvx(conn_handle, &params);
    }
}

How can I resolve this problem?

Best regards,

Christian

Parents
  • Triple-check the return code of your notification function. A return value of BT_GATT_ITER_STOP will automagically unsubscribe!

  • Hi, 

    the only place where BT_GATT_ITER_STOP is returned is when the [UNSUBSCRIBE] happens. I attached the wireshark file for the connection.

     keyfob_unsubscribe.pcapng

    At the same time these were the logs of the peripheral:

    00> D: Connecting (0)
    00> I: Connected
    00> 
    00> D: Security changed: E7:B8:CB:8B:91:F8 (random) level 2
    00> D: The discovery procedure succeeded
    00> D: Getting handles from service.
    00> D: Found handle for mode characteristic.
    00> D: Found handle for CCC of mode characteristic.
    00> D: Found handle for serial characteristic.
    00> D: [SUBSCRIBED] mode characteristic
    00> D: [NOTIFICATION] data 0x2000e34c length 4
    00> D: ble_mode_data_received
    00> data: 01000000
    00> D: [NOTIFICATION] data 0 length 0
    00> D: [UNSUBSCRIBED]
    00> D: ble_mode_unsubscribed
    00> D: [SUBSCRIBED] mode characteristic
    00> D: [NOTIFICATION] data 0x2000e34c length 4
    00> D: ble_mode_data_received
    00> data: 00000000
    00> D: [NOTIFICATION] data 0 length 0
    00> D: [UNSUBSCRIBED]
    00> D: ble_mode_unsubscribed
    00> D: [SUBSCRIBED] mode characteristic

    At the moment I use a workaround and subscribe everytime when the characteristic gets unsubscribed. This is why there are more than one [SUBSCRIBED] messages.

    I hope this helps.

    Christian

Reply
  • Hi, 

    the only place where BT_GATT_ITER_STOP is returned is when the [UNSUBSCRIBE] happens. I attached the wireshark file for the connection.

     keyfob_unsubscribe.pcapng

    At the same time these were the logs of the peripheral:

    00> D: Connecting (0)
    00> I: Connected
    00> 
    00> D: Security changed: E7:B8:CB:8B:91:F8 (random) level 2
    00> D: The discovery procedure succeeded
    00> D: Getting handles from service.
    00> D: Found handle for mode characteristic.
    00> D: Found handle for CCC of mode characteristic.
    00> D: Found handle for serial characteristic.
    00> D: [SUBSCRIBED] mode characteristic
    00> D: [NOTIFICATION] data 0x2000e34c length 4
    00> D: ble_mode_data_received
    00> data: 01000000
    00> D: [NOTIFICATION] data 0 length 0
    00> D: [UNSUBSCRIBED]
    00> D: ble_mode_unsubscribed
    00> D: [SUBSCRIBED] mode characteristic
    00> D: [NOTIFICATION] data 0x2000e34c length 4
    00> D: ble_mode_data_received
    00> data: 00000000
    00> D: [NOTIFICATION] data 0 length 0
    00> D: [UNSUBSCRIBED]
    00> D: ble_mode_unsubscribed
    00> D: [SUBSCRIBED] mode characteristic

    At the moment I use a workaround and subscribe everytime when the characteristic gets unsubscribed. This is why there are more than one [SUBSCRIBED] messages.

    I hope this helps.

    Christian

Children
No Data
Related