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

Related