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

Setting PHY=2M #16

Open
travisjayday opened this issue Nov 6, 2023 · 2 comments
Open

Setting PHY=2M #16

travisjayday opened this issue Nov 6, 2023 · 2 comments

Comments

@travisjayday
Copy link

How can I set the PHY configuration to 2M? My connections are only 1M phy and I'm not sure how to update it. Is 2M PHY supported?

I'm looking into the source code and the only references to PHY are in node_modules/ble-host/lib/internal/adapter.js. Without documentation, it's hard to figure out what's going on.

Any insight from someone more experienced is greatly appreciated!

@Emill
Copy link
Owner

Emill commented Nov 6, 2023

Currently the library is using the "legacy" HCI API which is guaranteed to be supported on all Bluetooth >= 4.0 controllers. The extended/enhanced API was introduced in Bluetooth 5.0 which added support for creating connections or advertising using other PHYs than 1M.

The adapter.js file contains the low level HCI serialiser/deserialiser functions as well as some callback infrastructure to easily issue HCI commands. The more high level ble-manager.js makes use of this functionality internally.

You can find the HCI specification in the Bluetooth Core specification, Vol 4 Part E. As you can see in section 3.1.1, a host must either use only legacy commands/events or only extended/enhanced commands/events, which is a bit annoying.

However, the LE Set PHY Command, which can be called on an already established connection, is not part of the above restrictions. You can thus use the leSetPhy method in adapter.js to send this command. To receive the complete callback, you need to make sure the mask sent into leSetEventMask has bit 11 set. You should then wrap this functionality in ble-manager.js in some way.

If you want to use another PHY already at the point a connection is created, much more work would be needed since that requires all legacy commands/events to be replaced with the extended versions.

@travisjayday
Copy link
Author

travisjayday commented Nov 7, 2023

Okay, thank you for that information, that all makes sense. For now, I'm getting enough throughput with 1M phy but in the future, I'll look into making those changes you mentioned (don't know much about HCI/BLE so I don't really want to go down that rabbit hole right now but I might have to later). Thanks so much for your detailed and fast answer and thank you for this great library (l2cap COC works great :))

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