esp-nimble-cpp icon indicating copy to clipboard operation
esp-nimble-cpp copied to clipboard

how to peripheral get the services of the central

Open arif-ozcan opened this issue 2 years ago • 4 comments

my use scenario is:

1- start advertising 2- connect to advertising device through nRF Connect from mobile 3- get custom client services of the central device (mobile)

I cannot access the services of the central devices from my advertising-peripheral device. A Client instance always wants to connect to the advertised device.

Please let me know, Am i missing any point ? If not, is there any example to cover my scenario ?

Thanks in Advance !

arif-ozcan avatar May 28 '23 12:05 arif-ozcan

Hello, I can't think of any way to do this currently. It could be done with some significant changes to the code, I do not have time for doing that however. If you'd like to explore this and submit a PR I'd be more than happy to accept it.

h2zero avatar May 28 '23 22:05 h2zero

Hi, thanks for the quick reply.

Actually, i have started some modification on the code yesterday and could get service and characteristics by uuid. I hope i submit a PR on next days after a few test.

int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg)
{
    NIMBLE_LOGD(LOG_TAG, ">> handleGapEvent: %s", NimBLEUtils::gapEventToString(event->type));

    int rc = 0;
    NimBLEConnInfo peerInfo;
    NimBLEServer *pServer = NimBLEDevice::getServer();
    NimBLEClient *pClient = (NimBLEClient *)arg; // arg pointer is not used before in this callback. 
...

...

pClient->setConnID(event->connect.conn_handle); // should be set connID for retrieveServices()
pServer->m_pServerCallbacks->onConnect(pServer, pClient, peerInfo); // a pointer of client instance in addition to server instance
}

arif-ozcan avatar May 29 '23 22:05 arif-ozcan

Interesting approach, glad to see you're making progress. Happy to review when you're ready.

h2zero avatar May 30 '23 01:05 h2zero

@arif-ozcan Did you end up making a fork with the changes needed for this?

finger563 avatar Mar 29 '24 14:03 finger563