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

S110, Service, Send Data

Hello! I'm using sdk8 and s110. I want my peripheral device to send data to the central. I doing following steps:

1. initialize service:

void services_init(void)
{
    ble_uuid_t  service_uuid;
    uint32_t    err_code;

    service_uuid.uuid = LOCAL_SERVICE_UUID;
    err_code = sd_ble_uuid_vs_add(&m_base_uuid128, &service_uuid.type);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &service_uuid, &m_service_handle);
    APP_ERROR_CHECK(err_code);
}

2. add charecteristic:

void char_add(const uint8_t uuid_type)
{
    uint32_t            err_code;
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          char_uuid;
    ble_gatts_attr_md_t attr_md;

    memset(&cccd_md, 0, sizeof(cccd_md));

    cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);

    memset(&char_md, 0, sizeof(char_md));

    char_md.char_user_desc_max_size         = 0;
    char_md.char_user_desc_size             = 0;
    char_md.p_char_user_desc                = 0;

    char_md.char_props.read   = 1;
    char_md.char_props.write  = 1;
    char_md.char_props.notify = 1;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &cccd_md;
    char_md.p_sccd_md         = NULL;

    char_uuid.type = uuid_type;
    char_uuid.uuid = LOCAL_CHAR_UUID;

    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));

    memcpy(m_char_value, "OKEY", strlen("OKEY"));

    attr_char_value.p_uuid    = &char_uuid;
    attr_char_value.p_attr_md = &attr_md;
    attr_char_value.init_len  = APP_CFG_CHAR_LEN;
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = APP_CFG_CHAR_LEN;
    attr_char_value.p_value   = m_char_value;

    err_code = sd_ble_gatts_characteristic_add(m_service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &m_char_handles);
    APP_ERROR_CHECK(err_code);
}

3. Send data:

void send_char_data(char *data, char size)
{
    ble_gattc_write_params_t write_params;
    uint32_t            err_code;

    write_params.write_op = BLE_GATT_OP_WRITE_CMD;
    write_params.handle   = m_char_handles.value_handle;
    write_params.offset   = 0;
    write_params.len      = size;
    write_params.p_value  = data;

    err_code = sd_ble_gattc_write(m_conn_handle, &write_params);
    APP_ERROR_CHECK(err_code);
}

But no data I can't receive on central side. Is what all right what i done?

Related