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

Temporary GATT characteristic update

Hello,

I am adding an extra characteristic (of 6 bytes) into one of the services that exist in the default beacon app. Then I try to update this characteristic using master control app, but after I disconnect the beacon and connect back to it, the value is not there anymore. I'm not sure what to do to fix this. Any help would be appreciated.

Thanks!

Parents
  • @Sarah: Which beacon example did you base on ? Usually the beacon should not have any service or characteristic, because it's a beacon, non-connectable.

    Have you make sure you have read and write permission open on the characteristic ? You should try to read the value back after you write. Also make sure the device doesn't reset after you disconnect.

  • I'm using the ble_app_beacon_s110_pca20006 example, where when you press sw2 button the beacon switches to config mode. I looked at how other readable/writable characteristics are added and tried to implement the same. This is the function I created to add a new characteristic:

    static uint32_t beacon_mac_char_add(ble_bcs_t * p_bcs, const ble_bcs_init_t * p_bcs_init) {

    ble_gatts_char_md_t char_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_uuid; ble_gatts_attr_md_t attr_md;

    memset(&char_md, 0, sizeof(char_md));
    
    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL;
    char_md.p_sccd_md         = NULL;
    
    ble_uuid.type = p_bcs->uuid_type;
    ble_uuid.uuid = BCS_UUID_BEACON_MAC_CHAR;
    
    memset(&attr_md, 0, sizeof(attr_md));
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
    
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    
    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = BCS_DATA_MAC_LEN;
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = BCS_DATA_MAC_LEN;
    attr_char_value.p_value      = &p_bcs_init->p_beacon->data.mac_address[6];
    
    return sd_ble_gatts_characteristic_add(p_bcs->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_bcs->beacon_mac_char_handles);
    

    }

    I defined BCS_UUID_BEACON_MAC_CHAR to be 0x1522, as I didn't notice it being used in the code, and BCS_DATA_MAC_LEN is 6.

Reply
  • I'm using the ble_app_beacon_s110_pca20006 example, where when you press sw2 button the beacon switches to config mode. I looked at how other readable/writable characteristics are added and tried to implement the same. This is the function I created to add a new characteristic:

    static uint32_t beacon_mac_char_add(ble_bcs_t * p_bcs, const ble_bcs_init_t * p_bcs_init) {

    ble_gatts_char_md_t char_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_uuid; ble_gatts_attr_md_t attr_md;

    memset(&char_md, 0, sizeof(char_md));
    
    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = NULL;
    char_md.p_sccd_md         = NULL;
    
    ble_uuid.type = p_bcs->uuid_type;
    ble_uuid.uuid = BCS_UUID_BEACON_MAC_CHAR;
    
    memset(&attr_md, 0, sizeof(attr_md));
    
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
    attr_md.vloc       = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth    = 0;
    attr_md.wr_auth    = 0;
    attr_md.vlen       = 0;
    
    memset(&attr_char_value, 0, sizeof(attr_char_value));
    
    attr_char_value.p_uuid       = &ble_uuid;
    attr_char_value.p_attr_md    = &attr_md;
    attr_char_value.init_len     = BCS_DATA_MAC_LEN;
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = BCS_DATA_MAC_LEN;
    attr_char_value.p_value      = &p_bcs_init->p_beacon->data.mac_address[6];
    
    return sd_ble_gatts_characteristic_add(p_bcs->service_handle, &char_md,
                                               &attr_char_value,
                                               &p_bcs->beacon_mac_char_handles);
    

    }

    I defined BCS_UUID_BEACON_MAC_CHAR to be 0x1522, as I didn't notice it being used in the code, and BCS_DATA_MAC_LEN is 6.

Children
No Data
Related