Page 1 of 1

BLE GATT_Server and GATT_Client at the same time possible?

Posted: Mon Jan 23, 2017 3:49 am
by Lucas.Hutchinson
Hi all!

I apologize if this question has already been asked and answered, but I couldn't seem to find an answer.

I am looking to use the ESP32 with both WiFi and BLE.
I know that as of the ESP-IDF v2.0-RC1 Bluetooth and WIFI concurrency is now possible.

However I am wanting to setup the ESP32 as both a BLE Peripheral and a BLE central.

Use Case:
3 BLE sensor nodes distributed in one room.
ESP32 acts as BLE Central and connects to all of the sensor nodes.
The ESP32 also acts as a BLE Peripheral so a user can connect to a single BLE device (ESP32) and see all of the data from the 3 different sensor nodes.
The ESP32 will also be setup as a WiFi AP to control lights and other connected devices based on the data from the sensor nodes.

So the overarching question is:
Can the ESP32 currently be setup as both a BLE peripheral and as a BLE Central?

If this is not currently possible, are there any plans to implement this in the future?

Thanks in advance!
- Lucas

Re: BLE Concurrent Central and Peripheral possible?

Posted: Thu Jan 26, 2017 7:24 pm
by Lucas.Hutchinson
Bump.
Just checking if anyone has any idea if this is possible?

Thanks in advance!

Re: BLE Concurrent Central and Peripheral possible?

Posted: Wed Mar 01, 2017 10:47 pm
by Lucas.Hutchinson
Hi All,

After testing out the Gatt server and client separately, I am now trying to integrate both projects into the same app.

It seems that at the moment you cant have both running at the same time.
If the Client is initialized first, the server fails to start advertising.
If the Server is initialized first, the client fails to scan.

My code is as follows:

Code: Select all

        esp_bt_controller_init();
	if (esp_bt_controller_enable(ESP_BT_MODE_BTDM))
	{
		ESP_LOGE(SYRP_GATT_TAG, "Fatal Error! %s enable controller failed\n", __func__);
		return;
	}

	if (esp_bluedroid_init())
	{
		ESP_LOGE(SYRP_GATT_TAG, "Fatal Error! %s init bluetooth failed\n", __func__);
		return;
	}

	if (esp_bluedroid_enable())
	{
		ESP_LOGE(SYRP_GATT_TAG, "Fatal Error! %s enable bluetooth failed\n", __func__);
		return;
	}

	gatt_client_main();
	gatt_server_main();
Were 'gatt_client_main' does:

Code: Select all

    esp_err_t status;
    //register the scan callback function to the gap moudule
    if ((status = esp_ble_gap_register_callback(esp_gap_cb)) != ESP_OK) {
        ESP_LOGE(GATTC_TAG, "gap register error, error code = %x\n", status);
        return;
    }

    //register the callback function to the gattc module
    if ((status = esp_ble_gattc_register_callback(esp_gattc_cb)) != ESP_OK) {
        ESP_LOGE(GATTC_TAG, "gattc register error, error code = %x\n", status);
        return;
    }
    esp_ble_gattc_app_register(PROFILE_A_APP_ID);
    esp_ble_gattc_app_register(PROFILE_B_APP_ID);
}
and 'gatt_server_main' does:

Code: Select all

esp_ble_gatts_register_callback(gatts_event_handler);
esp_ble_gap_register_callback(gap_event_handler);
esp_ble_gatts_app_register(SYRP_PROFILE_APP_IDX);
ESP_LOGI(SYRP_GATT_TAG, "%s Bluetooth Server Setup Complete\n", __func__);
Is there anything that i seem to be doing incorrectly here?
Is this a feature that is not supported?
If so, will this feature ever be supported?

Thanks in advance!

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Fri Mar 03, 2017 3:15 am
by Lucas.Hutchinson
Hi all, @ESP_iggr @ESP_Angus @WiFive

Can anyone provide any answers on this.
If this is not supported, then how I am using the ESP32 in my application will likely have to change dramatically.

It would be good to know now, rather than later if and/or when this feature will be implemented.

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Wed Mar 08, 2017 7:27 pm
by Narmor
I have tried to implement this for nearly 10 hours as well and couldnt find a solution. It would be nice to get an official statement if this is even possible API wise.

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Thu Mar 09, 2017 3:37 am
by Lucas.Hutchinson
Hi Narmor,

https://github.com/espressif/esp-idf/issues/404

I posted this on the github issues and got a response. It looks like it should support both modes, however you cant advertise and scan at the same time.

TianHao also said that they will do some more work on this.

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Tue Jul 11, 2017 7:02 pm
by kokonuts
Lucas.Hutchinson wrote:
Use Case:
3 BLE sensor nodes distributed in one room.
ESP32 acts as BLE Central and connects to all of the sensor nodes.

Hi Lucas, would you provide the sample of ESP32 Central and connected to 3 ble devices ? As far as I know it is not possible to connect to more than one ble peripheral

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Fri Jul 21, 2017 6:43 am
by heyinling
Hi Lucas.Hutchinson

I think the limitation should be that we can't use (adv) and (scan connect) at the same time. I first let ESP32 work as GATTS, connected by a GATTC (adv auto switched off now), then connect to a GATTS. it works well on both connections with both role.

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Mon Jun 18, 2018 9:40 pm
by chrismerck
Can anyone comment on the current status of simultaneous BLE peripheral and central?

I did not see any comment on this in the "ESP32 Bluetooth Architecture" document (which, by the way, is very nicely done. Very useful guide to the platform. I wish all vendors did this for their platforms...)

Re: BLE GATT_Server and GATT_Client at the same time possible?

Posted: Tue Jun 19, 2018 12:16 am
by chegewara
I did not build any device that requiring ble central + peripheral, but i did quick and simple test with Neil Kolban's library and it works. What i did:
- esp32 server for testing,
- esp32 client that is connecting to esp32 server and sending messages every 1000ms + server that allows to connect another client,
- android device with nRF connect that is connecting to dual mode esp32 device.
Looking at putty logs in real time everything worked, but like i said, it was only test case and i cant say how it will works in real app. Also i have to mention it was few months ago.