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

Issue on writing custom Characteristics

Hi,
I have very STRANG issues. I am adding custom Characteristics to custom Services. I have added 10 custom Characteristics with the same config 8 of them are working perfectly fine but 2 of them are causing issues. 

I am also attaching my project.

I have the following 2 issues.

1-Issue with Custom Characteristics no 4:

I have successfully read/write on others 9 Characteristics but unable to write from device side on Characteristics no 4. (I am writing in on_write function you can check in ble_cus.c)

2-Issue with Custom Characteristics no 5:
When I add this I got following issue.

    err_code = custom_value_char_add_5(p_cus, p_cus_init);
    APP_ERROR_CHECK(err_code);  







5415.Project.zip

Parents
  • 1-Issue with Custom Characteristics no 4:

    I have successfully read/write on others 9 Characteristics but unable to write from device side on Characteristics no 4. (I am writing in on_write function you can check in ble_cus.c)

     What happens when you "write from device side on characteristic no 4"? Can you describe the issue?

    By the way, you should check the return values on:

    err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
    NRF_LOG_INFO("Feedback On X");

     

    2-Issue with Custom Characteristics no 5:
    When I add this I got following issue.

     Where exactly did  you add this, and what does it return? Did you add it inside the nrf_ble_qwr_conn_handle_assign()?

    Have you tried looking into nrf_ble_qwr_conn_handle_assign()? Try to debug and see why it returns 8.

  • What happens when you "write from device side on characteristic no 4"? Can you describe the issue?

    I have debugged code and I have set different printouts and its printing "Point 1" of the following code.


          case 4:
    
          // Update database.
          err_code = sd_ble_gatts_value_set(p_cus->conn_handle,
                                            p_cus->custom_value_handles_4.value_handle,
                                            &gatts_value);
    
          if (err_code != NRF_SUCCESS)
          {
              NRF_LOG_INFO("Point 1");
              return err_code;
          }
          // Send value if connected and notifying.
          if ((p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)) 
          {
              NRF_LOG_INFO("Point 2");
              ble_gatts_hvx_params_t hvx_params;
    
              memset(&hvx_params, 0, sizeof(hvx_params));
    
              hvx_params.handle = p_cus->custom_value_handles_4.value_handle;
              hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
              hvx_params.offset = gatts_value.offset;
              hvx_params.p_len  = &gatts_value.len;
              hvx_params.p_data = gatts_value.p_value;
    
              err_code = sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
              NRF_LOG_INFO("Point 3");
    
          }
          else
          {
              NRF_LOG_INFO("Point 4");
              err_code = NRF_ERROR_INVALID_STATE;
           }
          break;
    



     Where exactly did  you add this, and what does it return? Did you add it inside the nrf_ble_qwr_conn_handle_assign()?

    I am adding it in the same way as adding others' characteristics.

    uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
    {
        if (p_cus == NULL || p_cus_init == NULL)
        {
            return NRF_ERROR_NULL;
        }
    
        uint32_t   err_code;
        ble_uuid_t ble_uuid;
    
        // Initialize service structure
        p_cus->conn_handle               = BLE_CONN_HANDLE_INVALID;
    
        // Add Custom Service UUID
        ble_uuid128_t base_uuid = {CUSTOM_SERVICE_UUID_BASE};
        err_code =  sd_ble_uuid_vs_add(&base_uuid, &p_cus->uuid_type);
        VERIFY_SUCCESS(err_code);
        
        ble_uuid.type = p_cus->uuid_type;
        ble_uuid.uuid = CUSTOM_SERVICE_UUID;
    
        // Add the Custom Service
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_cus->service_handle);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    
        // Add Custom value characteristic
        err_code = custom_value_char_add_1(p_cus, p_cus_init);// This line is not strictly needed, but if you plan to do more, don't return this value
        APP_ERROR_CHECK(err_code);
        err_code = custom_value_char_add_2(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_3(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_4(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_5(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_6(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_7(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_8(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_9(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code);  
        err_code = custom_value_char_add_10(p_cus, p_cus_init);
        APP_ERROR_CHECK(err_code); 
      
        return err_code;
    }
    

  • Muqarrab said:
    I have debugged code and I have set different printouts and its printing "Point 1" of the following code.

     So what does sd_ble_gatts_value_set() return before it prints "Point 1"?

     

    Muqarrab said:
    I am adding it in the same way as adding others' characteristics.

     So why does nrf_ble_qwr_conn_handle_assign() return 8? What check or what function inside nrf_ble_qwr_conn_handle_assign() causes it to return 8? Please try to debug this. 

  • I looked a bit deeper into your project. 

    Inside ble_cus_custom_value_update(), you are trying to send notifications on each of the characteristics. But none of your characteristics supports notifications. Also, your on_write() function never checks the return value of ble_cus_custom_value_update(). It always returns the value for sd_ble_gatts_hvx(), but I don't think you have picked it up. The return value reflects that notifications are not supported. 

    BR,
    Edvin

  • So what does sd_ble_gatts_value_set() return before it prints "Point 1"?

    I am getting the following issue.



     So why does nrf_ble_qwr_conn_handle_assign() return 8? What check or what function inside nrf_ble_qwr_conn_handle_assign() causes it to return 8? Please try to debug this.

    I don't know how to debug next. Can you please guide?
    I have also attached my project can you please check for once.
    Thanks!

  • Muqarrab said:
    I don't know how to debug next. Can you please guide?
    I have also attached my project can you please check for once.

     I have tried your project, and I don't get any of the errors that you get. 

    Go to the definition of nrf_ble_qwr_conn_handle_assign() and set a breakpoint inside it. When the breakpoint hits, check that the p_qwr pointer is not NULL, and check the value of p_qwr->initialized. What is that value?

     

    Muqarrab said:
    I am getting the following issue.

     Are you sure this happens in the project that you sent to me? Can you please try to unzip it in an unmodified SDK? Try to download the SDK again, and unzip it. Don't change anything outside the project folder that you attached here. Does the issues still occur?

Reply
  • Muqarrab said:
    I don't know how to debug next. Can you please guide?
    I have also attached my project can you please check for once.

     I have tried your project, and I don't get any of the errors that you get. 

    Go to the definition of nrf_ble_qwr_conn_handle_assign() and set a breakpoint inside it. When the breakpoint hits, check that the p_qwr pointer is not NULL, and check the value of p_qwr->initialized. What is that value?

     

    Muqarrab said:
    I am getting the following issue.

     Are you sure this happens in the project that you sent to me? Can you please try to unzip it in an unmodified SDK? Try to download the SDK again, and unzip it. Don't change anything outside the project folder that you attached here. Does the issues still occur?

Children
Related