Changing Supervision timeout on BLE

frostyowned
Posts: 20
Joined: Wed Jun 28, 2017 1:22 pm

Changing Supervision timeout on BLE

Postby frostyowned » Wed Jul 19, 2017 6:35 pm

I am trying to change the timeout for the esp32 to drop the connection to the device, but I'm unsure how to do that. I have seen a timeout entry in one of the structs ( esp_ble_conn_update_params_t ) but I'm unsure where I would apply it in the initialization.

To be clear, I think the android device I am connecting to the ESP32 is being timed out and dropped by the esp32 ( android phone is the client )

Lucas.Hutchinson
Posts: 79
Joined: Tue Apr 26, 2016 5:10 am

Re: Changing Supervision timeout on BLE

Postby Lucas.Hutchinson » Wed Jul 19, 2017 9:04 pm

hi @frostyowned

A function like the following should help you configure the timeout. This is configurable on the GATT Sever side only.

Code: Select all

void gatt_perihperal_update_connection_params(uint8_t* client_addr)
{
	esp_ble_conn_update_params_t conn_params;
	memcpy(conn_params.bda, client_addr, BLE_MAC_ADDR_LEN);
	conn_params.min_int = 0x06; // x 1.25ms
	conn_params.max_int = 0x40; // x 1.25ms
	conn_params.latency = 0x00; //number of skippable connection events
	conn_params.timeout = 0xA0; // x 6.25ms, time before peripherial will assume connection is dropped.

	esp_ble_gap_update_conn_params(&conn_params);
}

frostyowned
Posts: 20
Joined: Wed Jun 28, 2017 1:22 pm

Re: Changing Supervision timeout on BLE

Postby frostyowned » Thu Jul 20, 2017 2:46 pm

Thank you for that! I have tried putting it in my code and have gotten an error ( second line ). The first line is to show the mac address was successfully obtained using the parameters from the connection

Code: Select all

I (63594) wOS: SERVICE_START_EVT, conn_id 0, remote e4:12:1d:a3:f2:2f:, is_conn 1
E (63594) BT: bta_dm_ble_update_conn_params error: Invalid connection bd_addr.
It was placed in the event handler under this case:

Code: Select all

    case ESP_GATTS_CONNECT_EVT:
        ESP_LOGI(GATTS_TAG, "SERVICE_START_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d\n",
                 param->connect.conn_id,
                 param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
                 param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5],
                 param->connect.is_connected);
        gl_profile.conn_id = param->connect.conn_id;
		uint8_t client_addr[6] = { param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2], param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5] };
		gatt_perihperal_update_connection_params( client_addr );
        break;
and finally here is the edited version of the function you gave me:

Code: Select all

void gatt_perihperal_update_connection_params(uint8_t* client_addr)
{
   esp_ble_conn_update_params_t conn_params;
   memcpy(conn_params.bda, client_addr, sizeof( 6 ) );
   conn_params.min_int = 0x06;
   conn_params.max_int = 0x40;
   conn_params.latency = 0x00;
   conn_params.timeout = 0x0C80; // Maximum value to test if timeout is the issue with Android

   esp_ble_gap_update_conn_params(&conn_params);
}

Lucas.Hutchinson
Posts: 79
Joined: Tue Apr 26, 2016 5:10 am

Re: Changing Supervision timeout on BLE

Postby Lucas.Hutchinson » Thu Jul 20, 2017 8:21 pm

Hi Frostyowned

Hmm that is quite strange. I have placed the function in essentially the same location and it works well for me.
Not sure why this would be erroring, unless for some reason the connection event was not successful?

FYI you can just pass

Code: Select all

param->connect.remote_bda
to the function without doing this bit of code

Code: Select all

uint8_t client_addr[6] = { param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2], param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5] };

heyinling
Posts: 19
Joined: Thu Mar 23, 2017 7:21 am

Re: Changing Supervision timeout on BLE

Postby heyinling » Fri Jul 21, 2017 6:31 am

hi frostyowned,

you may try with the latest IDF. There was a bug that slave can't update conn param.

@Lucas.Hutchinson update conn param should be a function available both for master and slave.

frostyowned
Posts: 20
Joined: Wed Jun 28, 2017 1:22 pm

Re: Changing Supervision timeout on BLE

Postby frostyowned » Mon Jul 24, 2017 2:14 pm

heyinling wrote:hi frostyowned,

you may try with the latest IDF. There was a bug that slave can't update conn param.

@Lucas.Hutchinson update conn param should be a function available both for master and slave.
I tried to update to latest IDF but am now seeing this error when I try to compile

Code: Select all

C:\msys32\opt\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc-ar.exe: Cannot find plugin 'liblto_plugin-0.dll'
The installation is fresh as well, no idea why this is happening

Lucas.Hutchinson
Posts: 79
Joined: Tue Apr 26, 2016 5:10 am

Re: Changing Supervision timeout on BLE

Postby Lucas.Hutchinson » Mon Jul 24, 2017 8:14 pm

This is part of espressif changing the bootloader to use LTO during compilation to save compiled code size.

More details and a solution can be found here:
https://github.com/espressif/esp-idf/issues/828

Alternately switch to using the release/v2.1 branch.

Who is online

Users browsing this forum: Google [Bot] and 88 guests