Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to obtain client from existing server connection? #665

Closed
gkoh opened this issue May 4, 2024 · 3 comments
Closed

How to obtain client from existing server connection? #665

gkoh opened this issue May 4, 2024 · 3 comments

Comments

@gkoh
Copy link
Contributor

gkoh commented May 4, 2024

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
  • 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 of ble_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

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
Copy link
Owner

h2zero commented Jun 4, 2024

Work in progress here: h2zero/esp-nimble-cpp#156

@h2zero
Copy link
Owner

h2zero commented Jun 4, 2024

API added to master branch here: 6db0368

@h2zero h2zero closed this as completed Jun 4, 2024
@gkoh
Copy link
Contributor Author

gkoh commented Jun 5, 2024

API added to master branch here: 6db0368

Nice!
Once again, much thanks and appreciation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants