Skip to content

Conversation

@h2zero
Copy link
Owner

@h2zero h2zero commented Dec 2, 2024

This allows the NimBLEServer instance to create a NimBLEClient instance to read/write form/to a connected peer. Only one instance is supported subsequent calls will overwrite the previous client connection information and data.

@h2zero
Copy link
Owner Author

h2zero commented Dec 2, 2024

@finger563 You may be interested in reviewing this, your feedback would be greatly appreciated.

@finger563
Copy link
Contributor

@finger563 You may be interested in reviewing this, your feedback would be greatly appreciated.

@h2zero It looks like a net improvement to the API for sure, and I like not having to manage the client pointer myself just to talk to the connected client.

One question I do have though is that In my code previously I would unset the client connection (calling clearConnection()) after using it, so that the client could be properly deleted / deinitialized (e.g. when calling NimBLEDevice::deinit(clear_all=true)). I remember getting a hang or crash of some kind if I didn't call the clear connection on the client before calling that, is that something that would still need to be done or would this automatically take care of it now?

@h2zero
Copy link
Owner Author

h2zero commented Dec 2, 2024

That shouldn't be necessary now because the client is created and managed by the server and NimBLEDevice::deint(true) will only manage the clients created through that interface. The server will delete the client instance when it is deleted so there should be no issues.

@h2zero h2zero force-pushed the client-from-server branch from e4234d2 to 5910c10 Compare December 3, 2024 18:06
@h2zero
Copy link
Owner Author

h2zero commented Dec 4, 2024

@finger563 Did you perhaps test this at all?

@finger563
Copy link
Contributor

@h2zero Unfortunately, I've not had time to yet. If you need, I'll be able to test late today or tomorrow.

@finger563
Copy link
Contributor

finger563 commented Dec 5, 2024

@h2zero one change in behavior I'm seeing when using the new client instead of the one I was using before is that the initial connection (before auth is complete) now returns failure to get generic access service from the client:

Disconnect and reconnect and it works fine.

CleanShot 2024-12-05 at 08 07 37

So that's something that ideally could be fixed?

Code I'm using:

    // since this connection is handled by the server, we won't manually
    // connect, and instead inform the client that we are already connected
    // using this conn handle
    auto client = server_->getClient(conn_info);
    // refresh the services
    client->getServices(true);
    // now get Generic Access Service
    auto gas = client->getService(NimBLEUUID("1800"));
    if (!gas) {
      logger_.error("Failed to get Generic Access Service");
      return {};
    }

@h2zero
Copy link
Owner Author

h2zero commented Dec 5, 2024

Thanks, not sure why that errored, would need to see logging with info messages on.

@finger563
Copy link
Contributor

finger563 commented Dec 5, 2024

@h2zero

Here are some additional (debug) logs turned on esp-nimble-cpp:
CleanShot 2024-12-05 at 10 13 59

@h2zero
Copy link
Owner Author

h2zero commented Dec 5, 2024

Thanks, found the issue.

@finger563 Just pushed the fix if you could please confirm when you have time?

@finger563
Copy link
Contributor

finger563 commented Dec 5, 2024

@h2zero Thanks, confirmed it's fixed :)

CleanShot 2024-12-05 at 13 19 42

This allows the NimBLEServer instance to create a NimBLEClient instance to read/write form/to a connected peer.
Only one instance is supported subsequent calls will overwrite the previous client connection information and data.
@h2zero h2zero force-pushed the client-from-server branch from 09f4c15 to 081fdc6 Compare December 5, 2024 20:40
Copy link
Contributor

@finger563 finger563 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well in my testing :)

@h2zero
Copy link
Owner Author

h2zero commented Dec 5, 2024

Great, thanks! I'm considering removing the server name read to go along with this as it seems redundant and bloats the code.

With the implementation of the NimBLEServer::getClient function this is now redundant.
@h2zero h2zero merged commit c547733 into master Dec 5, 2024
59 checks passed
@h2zero h2zero deleted the client-from-server branch December 5, 2024 23:03
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

Successfully merging this pull request may close these issues.

3 participants