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

Problem with sending data from central to peripheral

Hello,

recently i made software for peripheral with custom service and five custom characteristics and everything works just fine. Now I want to make central capable of writing to my custom characteristics on perpiheral. I'm working with Central/Uart example from SDK. I changed example and now i can discover all my characteristics properly, but writing to them doesn't work. i'm using  "ble_nus_string_send(&m_nus, data, sizeof(data))" but I'm not receiving anything on peripheral when I use discovered characteristics handles. What is strange when I use handle value 0x0003 I'm receiving event on peripheral, but only with this value. Can anyone tell what I'm doing wrong?

on_write handle on peripheral:

static void on_write(ble_config_t *p_config, ble_evt_t const *p_ble_evt)
{
    ret_code_t err_code;
    ble_config_evt_t evt;
    ble_config_client_context_t *p_client;
    ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

    err_code = blcm_link_ctx_get(p_config->p_link_ctx_storage,
        p_ble_evt->evt.gatts_evt.conn_handle,
        (void *)&p_client);
    if (err_code != NRF_SUCCESS)
    {
        SEGGER_RTT_printf(0, "Link context for 0x%02X connection handle could not be fetched.",
            p_ble_evt->evt.gatts_evt.conn_handle);
    }

    memset(&evt, 0, sizeof(ble_config_evt_t));
    evt.p_config = p_config;
    evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
    evt.p_link_ctx = p_client;

    if ((p_evt_write->handle == p_config->rx_handlesID.value_handle) &&
        (p_config->data_handler != NULL))
    {
        evt.type = BLE_CONFIG_EVT_RX_ID_DATA;
        evt.params.rx_data.p_data = p_evt_write->data;
        evt.params.rx_data.length = p_evt_write->len;

        p_config->data_handler(&evt);
    }
    else if ((p_evt_write->handle == p_config->rx_handlesMeasurment_interval.value_handle) &&
             (p_config->data_handler != NULL))
    {
        evt.params.rx_data.p_data = p_evt_write->data;
        evt.params.rx_data.length = p_evt_write->len;

        p_config->data_handler(&evt);
    }
    else if ((p_evt_write->handle == p_config->rx_handlesAdvertising_interval.value_handle) &&
             (p_config->data_handler != NULL))
    {
        evt.type = BLE_CONFIG_EVT_ADVERTISING_INTERVAL;
        evt.params.rx_data.p_data = p_evt_write->data;
        evt.params.rx_data.length = p_evt_write->len;

        p_config->data_handler(&evt);
    }
    else if ((p_evt_write->handle == p_config->rx_handlesLow_alarm.value_handle) &&
             (p_config->data_handler != NULL))
    {
        evt.type = BLE_CONFIG_EVT_LOW_ALARM;
        evt.params.rx_data.p_data = p_evt_write->data;
        evt.params.rx_data.length = p_evt_write->len;

        p_config->data_handler(&evt);
    }
    else if ((p_evt_write->handle == p_config->rx_handlesHigh_alarm.value_handle) &&
             (p_config->data_handler != NULL))
    {
        evt.type = BLE_CONFIG_EVT_HIGH_ALARM;
        evt.params.rx_data.p_data = p_evt_write->data;
        evt.params.rx_data.length = p_evt_write->len;

        p_config->data_handler(&evt);
    }
    else
    {
        // Do Nothing. This event is not relevant for this service.
    }
}

Related