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 get current PHY mode #668

Open henkelis opened 1 month ago

henkelis commented 1 month ago

Hi,

For my use case I want to get the current mode of a connection, to be able to display it (from the client side, but could also be from the server side). I also want to be able to change the mode after connection.

I've added functions to NimbleClient and NimbleServer to do that as follows (based on existing functions):

The functions work and I can get and set modes. Unfortunately when getting the modes for coded PHY, the BLE spec states to return just that it is coded, and not the actual mode (S2 or S8). The mode appears to be available in the low level connection data, but I can't work out how to get to that.

I can see HCI code that gets the PHY (ble_ll_conn_hci_le_rd_phy) and could cheat and return the mode in the top 4 bits alongside the phy, but my board (Adafruit Feather esp32-s3) provides precompiled bt libs so I would have to edit that source and recompile those libs.

Is there another way to get the actual mode?

Mark.

h2zero commented 1 month ago

Hello, you can assume it to be S8, S2 is almost never used.

henkelis commented 1 month ago

Thanks.

I might actually set it to S2, it's a shame I can't prove that that's what it's set to at any point in the future (obviously I get a success code when I set it).

h2zero commented 1 month ago

Not sure why you'd want to use S2, you get half the data rate and almost no detectable difference in range, that's why it's not commonly used.

henkelis commented 1 month ago

All the more reason to be able to detect if it's set :)