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

enable / disable indication issue when characteristic is already sending

I'm working on a program which sends 20 kb of data (sending 16 byte at a time) with one condition which is that indication should be enabled first. the first function checks if indication is enabled on characteristic before starting transfer. when when the transfer is on progress and I disable indication the whole system hang

what could be the issue.

1 : is it because im trying to disable / enable indication when sending is on progress

2 : is the function (1 one)which checks if indication is enabled incorrectly programmed)

3 :my function for waiting for indication answer is it correct???

4 : is there any way to activate indication manually (send command and run indication disable manually within my peripheral code)

I shouldn't lost any data so I'm using indication instead of notification.

static bool is_flash_data_indication_enabled(uint16_t conn_handle)
{
    uint32_t          err_code;
    uint8_t           cccd_value_buf[BLE_CCCD_VALUE_LEN];
    ble_gatts_value_t value;

    value.len = BLE_CCCD_VALUE_LEN;
    value.offset = 0;
    value.p_value = cccd_value_buf;
    err_code = sd_ble_gatts_value_get(conn_handle, m.flash_data_char_handles.cccd_handle, &value);
    if (err_code != NRF_SUCCESS) {
        return false;
    }
    uint16_t cccd_value = uint16_decode(cccd_value_buf);
    return (bool)((cccd_value & BLE_GATT_HVX_INDICATION) != 0);
}

    if ((m.conn_handle != BLE_CONN_HANDLE_INVALID) && (is_flash_data_indication_enabled(m.conn_handle))) {
       // send data
                        indication_pending = true;
                        do {
// send a buffer of 16 byte
                            err_code = ble_param_update(&m, FLASH_DATA, NULL, steps_store_characteristic_value);//update data on BLE
                        } while (err_code == BLE_ERROR_NO_TX_BUFFERS);
                        indication_timeout = 0;
                        while (indication_pending) {
                            app_sched_execute();
                            nrf_delay_ms(25);
                            if ((indication_timeout >= 80) || (err_code == NRF_ERROR_INVALID_STATE)) {
                                disconnected = true;
                                break;
                            }
                        }
    }

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
...
        // indication
    case BLE_GATTS_EVT_HVC:
        indication_pending = false;
        break;
....
}
Parents
  • FormerMember
    0 FormerMember

    If you try to send an indication after indications has been disabled, sd_ble_gatts_hvx(..) will return the error NRF_ERROR_INVALID_STATE. You could for example verify if that causes some problems.

    Indications (and notifications) can only be enabled and disabled by the client (in this case the central). The reason is the following: when the server (often the peripheral) updates values to the client, the client has to be ready to receive these updates.

  • For the third time, if the indication is accepted by the stack it will go out, if it goes out a reply will come back, when the reply comes back the buffer will be released and the callback will occur. There is no race condition, it doesn't matter if indications are turned off, as long as the link is up the client will reply. This is all in the bluetooth spec.

Reply
  • For the third time, if the indication is accepted by the stack it will go out, if it goes out a reply will come back, when the reply comes back the buffer will be released and the callback will occur. There is no race condition, it doesn't matter if indications are turned off, as long as the link is up the client will reply. This is all in the bluetooth spec.

Children
No Data
Related