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

Clearing characteristic value

Hi,

I tried looking for an answer for this, however unsuccessfully.
I have a custom characteristic and I set it with a string of values when it is added to the custom service.

I need to remove those values or if cannot remove, to replace the string with a zero.

For example: 0x01, 0x02, 0x03... ==> 0x00

I can set the zero to the characteristic value, however it only replaces the first byte of the string, leaving other bytes untouched.
Setting NULL does nothing.
How could I clear the string away?

Thank you!

Parents
  • Let me try to give you an intuition of how it works.

    When running the SVCall sd_ble_gatts_characteristic_add(..) one of the arguments is the GATT attribute structure p_attr_char_value. That structure contains respectively the length and the value of the characteristics:

    • init_len and max_len gives the length in bytes
    • *p_value points to the attribute data

    What happens if init_len and max_len is set to 4? Then the length is 4*(8 bits) = 32 bits, which can store numbers from 0 up to (2³²-1), or (0x)0 up to (0x)FFFF FFFF.

    If you set the value equal to (0x)0201 0022 and the length equal to 4 then the following value will show up in nRF Connect: (0x) 22-00-01-02. Notice how the order is switched, the last byte is written first and so on.

    Best regards, Simon.

Reply
  • Let me try to give you an intuition of how it works.

    When running the SVCall sd_ble_gatts_characteristic_add(..) one of the arguments is the GATT attribute structure p_attr_char_value. That structure contains respectively the length and the value of the characteristics:

    • init_len and max_len gives the length in bytes
    • *p_value points to the attribute data

    What happens if init_len and max_len is set to 4? Then the length is 4*(8 bits) = 32 bits, which can store numbers from 0 up to (2³²-1), or (0x)0 up to (0x)FFFF FFFF.

    If you set the value equal to (0x)0201 0022 and the length equal to 4 then the following value will show up in nRF Connect: (0x) 22-00-01-02. Notice how the order is switched, the last byte is written first and so on.

    Best regards, Simon.

Children
No Data
Related