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

Multilink client GATTC event handler not working

Hi! I am working on a project that uses the Multilink example. On the client (nRF51422 w. SD 120) my program crashes and starts the main loop again after a few seconds. I have narrowed it down to in the client_handling.c file in the client_handling_ble_evt_handler().

The p_ble_evt->header.evt_id is 27. Then of course none of the cases is entered. What is causing this?

The problem has occured after I changed my server to send data with sd_ble_gatts_hvx() instead of sd_ble_gatts_value_set(), to preserve battery life. But with the nRF Master app the server data transfer and notification seems to work just fine.

Any suggestions?

Thanks!

/Christian

void client_handling_ble_evt_handler(ble_evt_t * p_ble_evt)

{

client_t * p_client = NULL;
	uint32_t err_code;
	uint8_t z;
  char buffer[10];
uint32_t index = client_find(p_ble_evt->evt.gattc_evt.conn_handle);
if (index != MAX_CLIENTS)
{
   p_client = &m_client[index];
}
switch (p_ble_evt->header.evt_id)
{
    case BLE_GATTC_EVT_WRITE_RSP:  
			if ((p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION) ||
            (p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION))
        {
            uint32_t err_code = dm_security_setup_req(&p_client->handle);
            APP_ERROR_CHECK(err_code);

        }
        on_evt_write_rsp(p_ble_evt, p_client);
        break;

    case BLE_GATTC_EVT_HVX:
					
        on_evt_hvx(p_ble_evt, p_client, index);
        break;

    case BLE_GATTC_EVT_TIMEOUT:
        on_evt_timeout(p_ble_evt, p_client);
        break;
			
			case BLE_GATTC_EVT_CHAR_DISC_RSP:
						//err_code = sd_ble_gattc_read(p_ble_evt->evt.gatts_evt.conn_handle,17,0);
						APP_ERROR_CHECK(err_code);
						break;
									
			case BLE_GATTC_EVT_READ_RSP:
					if(p_ble_evt->evt.gattc_evt.params.read_rsp.handle==17)
					{
						z = p_ble_evt->evt.gattc_evt.params.read_rsp.data[0];		
						p_client->client_acc_z_value = z;
					
						err_code = sd_ble_gattc_read(p_ble_evt->evt.gatts_evt.conn_handle,17,0);
						APP_ERROR_CHECK(err_code);
					}
					break;
					
    default:
				debug_printf("Evt not found\n\r");
        break;
}


if (p_client != NULL)
{
    ble_db_discovery_on_ble_evt(&(p_client->srv_db), p_ble_evt);
}

}

  • 0x27 is BLE_GAP_EVT_ADV_REPORT which is handled in on_ble_evt(...). I don't understand what you have changed, because the multilink peripheral code uses sd_ble_gatts_hvx(...) by default and not sd_ble_gatts_value_set(...), and the client_handling_ble_evt_handler(...) you have is not the same as in the multilink central example. You have an APP_ERROR_CHECK(...) on an uninitialized variable, which is not safe, but err_code is probably zero (NRF_SUCCESS). You need to pinpoint more exactly where the code fails. If you define DEBUG in the preprocessor symbols and set a breakpoint in app_error_handler(...) you can go into debug and check where the error happened and which error code it is.

  • Thank you, I'll look into it. On a side note; How would you normally go from at sd_ble_gatts_value_set(...) to a sd_ble_gatts_hvx(...), central side? I have tried:

    1. Added a new notify_enable() function in the db discovery handle that finds the custom characteristic.
    2. In on_evt_hvx i have added a if statement that looks for the custom characteristic handle
    3. In client_handling_init() I add ble_db_discovery_evt_register() with the custom uuid and the custom handler

    Anything I have done wrong, or am missing?

    As mentioned in OP, the server seems to work fine when I test it with the master control app. The characteristic value is only updated when there is a change. And in the log i can see that the app gets the notifications.

    Thanks!

  • sd_ble_gatts_hvx(...) will do sd_ble_gatts_value_set(...) and send the value as a notification (if this is enabled). It looks fine to me. Could you update your post with the code (both peripheral and central) so I can try it here?

Related