How to obtain client from existing server connection?
gkoh opened this issue · 3 comments
gkoh commented
Use Case
NimBLE device is configured as a server and advertises.
Smartphone client scans, can see peripheral device name and connects.
After connection, would like server to use existing connection to query (and display) client device name via service 0x1800
and characteristic 0x2A00
.
What I've tried
- record peer ota address during server
onConnect()
- try
NimBLEClient::connect()
to this address - get 'already connected' due to
ble_gap_conn_find_by_addr()
finding the existing underlying connection
- try
- looked for others way to get a valid client object from the existing server handle, failed
What I hacked to prove it's possible
- modified
NimBLEClient::connect()
to:- use the
ble_gap_conn_desc
output ofble_gap_conn_find_by_addr()
check - make the
NimBLEClient
connected with the details from the gap conn desc - used this client to get remote service and characteristic from the central
- success
- use the
Possible Solutions
- Nothing, I'm doing something crazy and weird
- Modify
NimBLEClient::connect()
to allow and succeed with an already connected OTA address - Add a method to
NimBLEServer
for getting a properly connectedNimBLEClient
based on the underlying connection - Something else?