I am currently trying to use my nRF52 as a BLE central to connect to a OBD II BLE Device. I am able to use the name scan filters and connect here
case NRF_BLE_SCAN_EVT_FILTER_MATCH:
{
// Check if this is the OBD II device by comparing its name
uint8_t * adv_data = p_adv_report->data.p_data;
uint16_t adv_data_len = p_adv_report->data.len;
if(compare_device_name(adv_data, adv_data_len))
{
// Initiate connection
err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
p_scan_evt->p_scan_params,
&m_scan.conn_params,
APP_BLE_CONN_CFG_TAG);
APP_ERROR_CHECK(err_code);
}
break;
After connecting, I assign the handle here
case BLE_GAP_EVT_CONNECTED:
obd_connected = true;
obd_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
NRF_LOG_INFO("Connected to OBD with conn_handle: %d", obd_conn_handle);
NRF_LOG_INFO("Role: %d", ble_conn_state_role(obd_conn_handle));
// Start timer to discover services after 5 seconds
timerStart(TIMER_OBD_SERVICE_DISCO, APP_TIMER_OBD_SERVICE_DISCO_MS);
break;
I then try and write some initialization commands using the ble_nus_send function by sending it the message, length and handle here
ret_code_t ble_send(char* message, uint16_t length, uint16_t conn_handle)
{
ret_code_t err_code;
err_code = ble_nus_data_send(&m_nus, message, &length, conn_handle);
APP_ERROR_CHECK(err_code);
return err_code;
}
This is always returning err_code 8 which says NRF_ERROR_INVALID_STATE and this is where it is failing
if (!p_client->is_notification_enabled)
{
return NRF_ERROR_INVALID_STATE;
}
How would I enable notifications on the client end?