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

nRF51: writing to a characteristic

Hello,

I am using SD 130 on nRF5 with SDK V12.1.0.

I want to write to a characteristic using the android debug app (nrf connect).

This is my code for the characteristic:

  ble_uuid_t          char_uuid;
  char_uuid.uuid      = BLE_UUID_MY_CHARACTERISTC_UUID;
  err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
  APP_ERROR_CHECK(err_code);



  ble_gatts_attr_md_t attr_md;
  memset(&attr_md, 0, sizeof(attr_md));
  attr_md.vloc        = BLE_GATTS_VLOC_STACK;              
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);       
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);      

  /* Characteristic Value Attribute  */
  ble_gatts_attr_t    attr_char_value;

  memset(&attr_char_value, 0, sizeof(attr_char_value));   
  attr_char_value.p_uuid      = &char_uuid;
  attr_char_value.p_attr_md   = &attr_md;                     /* assign attribute metadata to characteristic value attribute */
  attr_char_value.max_len     = 1;                            /* max value length */
  attr_char_value.init_len    = 1;                            /* initial value length */
  attr_char_value.p_value = (uint8_t*)&MyVar;                            /* ptr to actual value */


  ble_gatts_char_md_t char_md;
  memset(&char_md, 0, sizeof(char_md));
  char_md.char_props.read = 1;                                /* set read property */
  char_md.char_props.write = 1;                               /* set write proper */
  

  err_code = sd_ble_gatts_characteristic_add(p_our_service->service_handle,
                                     &char_md,
                                     &attr_char_value,
                                     &p_our_service->char_handles_dry);
  APP_ERROR_CHECK(err_code);

What is happening: I can write a value to the characteristic. When I read it afterwards, it is correct. BUT: The debugger shows me, that MyVar did not change.

Question 1: Where is the new value saved? It's obviously not in MyVar as I assumed.

Question 2: How can I update MyVar with the correct value?

Thank you very much in advance!

Regards

Parents Reply Children
No Data
Related