BLE GATT Client in peripheral role

barbibulle
Posts: 2
Joined: Sun Oct 21, 2018 3:41 am

BLE GATT Client in peripheral role

Postby barbibulle » Sun Oct 21, 2018 3:51 am

I'm trying to figure out how I can run the ESP32 as a BLE peripheral, while *also* using the BLE GATT Client functions. The context is that I have a mobile phone that will connect to the ESP32, but also make some GATT characteristics available to the peripheral (i.e the phone acts as a GATT Server). This is, for example, one of the modes that's possible with the ANCS service on iPhones.
The issue I'm facing is that the API seems to assume that a peripheral is always a GATT server, and that a central is always a GATT client. In my experiments, I'm able to start the ESP32 in peripheral mode, advertise, and allow a phone to connect to it. At that point, I try to register a GATT client, and then perform a service discovery to find the services on the phone, by calling

Code: Select all

esp_ble_gattc_search_service()
. But that does nothing. No callback is every invoked as a result. I've tried using the GATT server's gatt_if and conn_id with the client, but that doesn't help either.

NOTE: this is a different problem from running as a Central and Peripheral at the same time (which I've seen mentioned in some forum topics). In this case, I want to run only as a Peripheral, but also have a GATT Client.

Any clue? Is that even possible?

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE GATT Client in peripheral role

Postby chegewara » Sun Oct 21, 2018 4:47 pm

Yes, it should be possible. As fas i did 3 of 4 possible role mix, this is the last one i still have to build example.
All you have to do is to make sure you are connected with your smartphone before you start searching for services, and my advice is to turn of nvs caching when you start (it gave me headache, and im still not sure if its properly working).

barbibulle
Posts: 2
Joined: Sun Oct 21, 2018 3:41 am

Re: BLE GATT Client in peripheral role

Postby barbibulle » Tue Oct 23, 2018 12:04 am

I would love to see an example if you write one. In my case, I do wait until the phone is connected, but calling esp_ble_gattc_search_service(gatt_if, conn_id, NULL) never results in any callback.

chegewara
Posts: 2210
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE GATT Client in peripheral role

Postby chegewara » Tue Oct 23, 2018 4:24 pm

@barbibulle The problem is i am using Kolban's library to write all my examples, but You could reverse engineer it.

Who is online

Users browsing this forum: No registered users and 121 guests