h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
667 stars 138 forks source link

How to obtain client from existing server connection? #665

Closed gkoh closed 1 month ago

gkoh commented 2 months ago

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

What I hacked to prove it's possible

Possible Solutions

  1. Nothing, I'm doing something crazy and weird
  2. Modify NimBLEClient::connect() to allow and succeed with an already connected OTA address
  3. Add a method to NimBLEServer for getting a properly connected NimBLEClient based on the underlying connection
  4. Something else?
h2zero commented 1 month ago

Work in progress here: https://github.com/h2zero/esp-nimble-cpp/pull/156

h2zero commented 1 month ago

API added to master branch here: https://github.com/h2zero/NimBLE-Arduino/commit/6db036830c58ae85e3f691ceebada96e6d8ba4af

gkoh commented 4 weeks ago

API added to master branch here: 6db0368

Nice! Once again, much thanks and appreciation.