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

Unable to read packets from custom BLE Characteristic

Hello guys!

We are workng with nRF52840 SoC and SDK v17.0.2.

Custom BLE Services and Characteristics are needed to implement in our device. Before starting that implementation, I passed through your beginner's tutorials on Services and Characteristics.

I was able to add our custom service, to assign read and write permissions, the size of the data packet in bytes and so on. We used nRF 52840 Dongle and nRF Connect app to test data transfer through custom BLE characteristics.

Everything is going smooth, we are able to establish BLE Connection, see our custom Characteristic and its properties:

However, when I want to send data from nRF52840 Dongle to our nRF52840 SoC, I am unable to read the data for some readon.

BLE_GATTS_EVT_WRITE event is properly triggered inside our custom BLE Service observer but when I try to extract received data bytes with sd_ble_gatts_value_get() function:

rx_data_buff = malloc(BLE_TIMESTAMP_HANDSHAKE_PACKET_SIZE * sizeof(uint8_t));

ble_gatts_value_t new_mercury_gatt_value = {.len = BLE_TIMESTAMP_HANDSHAKE_PACKET_SIZE,
                                            .offset = 0,
                                            .p_value = rx_data_buff
                                           };

err_code = sd_ble_gatts_value_get(p_ble_evt->evt.gatts_evt.conn_handle, p_mercury_service->timestamp_handshake_char_handles.value_handle, &new_mercury_gatt_value);
APP_ERROR_CHECK(err_code);

I don't see correct data.

Do you have any idea what I am doing wrong? Is sd_ble_gatts_value_get() function the best approach to read the data from particular BLE Characteristic?

FYI, BLE packet size we are sending through this custom Characteristic is 36 Bytes long. Consequently, I needed to change NRF_SDH_BLE_GATT_MAX_MTU_SIZE flag from 23 to 40 inside sdk_config.h file. Is there any similar parameter we need to set in order to allow proper reception of 36-Bytes of data through the custom BLE Characteristic?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

P.S. It might be useful to mention that I started our app development process from ble_app_multirole_lesc example located under examples/ble_central_and_peripheral/experimental.

Parents
  • I think I resolved the issue. It might be useful for someone in the future so here is what I do when BLE_GATTS_EVT_WRITE event happens:

    case BLE_GATTS_EVT_WRITE:
    
        if(p_ble_evt->evt.gatts_evt.params.write.handle == p_mercury_service->timestamp_handshake_char_handles.value_handle){
            NRF_LOG_WARNING("Data received over desired custom BLE Characteristic!");
            NRF_LOG_WARNING("BLE Data length: %d", p_ble_evt->evt.gatts_evt.params.write.len);    
            NRF_LOG_HEXDUMP_INFO(p_ble_evt->evt.gatts_evt.params.write.data, p_ble_evt->evt.gatts_evt.params.write.len)
        } else {
            NRF_LOG_WARNING("Data received over some other cusotm BLE Charecteristic!");
        }
    
        break;

    with 

    if(p_ble_evt->evt.gatts_evt.params.write.handle == p_mercury_service->timestamp_handshake_char_handles.value_handle)
     condition, I basically check if received data coming from desired custom BLE Characteristic. If affirmative, we can access the data through p_ble_evt->evt.gatts_evt.params.write.data pointer. The length of received data can be read from p_ble_evt->evt.gatts_evt.params.write.len !

    Cheers,

    Bojan.

Reply
  • I think I resolved the issue. It might be useful for someone in the future so here is what I do when BLE_GATTS_EVT_WRITE event happens:

    case BLE_GATTS_EVT_WRITE:
    
        if(p_ble_evt->evt.gatts_evt.params.write.handle == p_mercury_service->timestamp_handshake_char_handles.value_handle){
            NRF_LOG_WARNING("Data received over desired custom BLE Characteristic!");
            NRF_LOG_WARNING("BLE Data length: %d", p_ble_evt->evt.gatts_evt.params.write.len);    
            NRF_LOG_HEXDUMP_INFO(p_ble_evt->evt.gatts_evt.params.write.data, p_ble_evt->evt.gatts_evt.params.write.len)
        } else {
            NRF_LOG_WARNING("Data received over some other cusotm BLE Charecteristic!");
        }
    
        break;

    with 

    if(p_ble_evt->evt.gatts_evt.params.write.handle == p_mercury_service->timestamp_handshake_char_handles.value_handle)
     condition, I basically check if received data coming from desired custom BLE Characteristic. If affirmative, we can access the data through p_ble_evt->evt.gatts_evt.params.write.data pointer. The length of received data can be read from p_ble_evt->evt.gatts_evt.params.write.len !

    Cheers,

    Bojan.

Children
No Data
Related