Incorrect value when is_value_user = true

8176.ble_app_uart.zip

Hello,

I'm creating a BLE project with a couple of custom services. One of my simple characteristics in a service is a string. When is_value_user = false everything works fine. I want to move away from this due to the number and size of my characteristics, and keeping them in memory twice isn't going to work out. The string is kept in a global variable, and I've confirmed the string is good via the debugger, but the value reported by the nRF connect app is gibberish.

Any help is appreciated.

Parents
  • Hello,

    Are you using the nRF5 SDK? If so, what version are you using? 

    Can you please show me how you have implemented this global variable, and how you are handling the sending of notifications? The best is if you can describe it briefly, and send me the project (or a minimized project) that can replicate the issue that you are seeing.

    Please note that after you have called sd_ble_gatts_hvx() (sending notifications) it takes some time for the softdevice to actually send the data, so if the buffer changes in the meantime, that may corrupt the data you are sending over BLE. The reason for this is that when you call the notification-send-function, the softdevice (BLE stack) needs to wait for the next connection event (every connection interval) before it is able to communicate with the connected device. If the data changes in the meantime, it will be corrupted. It may also be related with how you are sending the data to the sd_ble_gatts_hvx() function. Are you using a pointer? Or a local variable? I know you say it is a global variable, but I am not sure how you are using it. 

    Best regards,

    Edvin

  • Hello Edwin,

    I am using the nRF5 SDK, version 17.0.2.

    I've created a minimum project based on the UART service example that shows the issue. What is the best way to share it with you?

  • you can zip the project folder (remember to place all files that you have changed inside the project folder), so that I can unzip it into an unmodified SDK and run it.

    You can upload the .zip folder here by using "Insert" -> image/video/file -> click the "upload" text (that doesn't really look like a button) and navigate to the file. Alternatively, you can drag and drop the .zip folder into the text window.

    If you are not able to upload it, try deleting the build folders, that tend to take up a lot of space.

    Best regards,

    Edvin

Reply Children
  • I see that UpdateTestName() returns 0x3002 = BLE_ERROR_INVALID_CONN_HANDLE, so that will not work.

    If I comment that out, I see that the characteristic user description has the same value that you have printed in the log:

    I guess that is not where you wanted to put the data.

    If you want the data in the characteristic itself, look at how it is done in the ble_app_uart example by default. I believe that the start value is set using attr_char_value.p_value   = p_char_props->p_init_value;, so you need to set it before you call characteristic_add(). You can try to add it using:

    add_char_params.p_init_value = "pointer to the array that you want to use";

    I don't remember the details, and I don't have time to test it now. I am sorry. I will be out of office next week. If you need a follow up before I return, you can try to create a new ticket, but please note that we are very short staffed during the summer holidays. 

    Actually, I did some fiddling in your project before hitting "reply". Please check the attached main.c, TestService.h and TestService.c.

    I only did some changes in services_init(), ble_test_init_t, ble_test_init(), and UpdateTestName().

    As I suspected, the array needs to be passed on when you initialize the service. Now it looks like this:

    So perhaps you can find out how you remove the characteristic user descriptor that you have added.

    Best regards,

    Edvin

Related