In #14579 @vcoubard mentioned that
setTxPower only affects advertising but for connections it has no effect.
Somewhere else i read this is because BLE standards only mention power setting options in regard of advertising but tell no word about that in conjunction with connections. This means with Mbed APIs there is no way to increase the power for connections (meaning level would drop back to 0db once the user establishes a connection).
In addition for some boards there exists vendor specific code that also affects connection power. While that is something good, it also increases inconsistency as on other boards there is no way doing so.
IMHO the BLE standard is not interpreted right or the standard lacks common sense in this regard. Here is why:
If i need to double the range from within BLE is functioning between 2 peers, then for sure i will need to call
setTxPower(6). But wait, that will have no effect for connections…
However if i need to restrict the range and call
setTxPower(-6): now i have just restricted the range to half of the original distance for security reasons, goal reached i can relax at last. But wait, what if i already initialized the connection while i was still within the decreased advertising range…
Right now i think the best possible implementation would be something like this
setTxPower(int dbAdv=0, int dbConn=0) Meaning one could set different power levels for advertising and connection, which would allow any combinations one just can think of. While it would also eliminate differences between boards that have vendor specific code vs boards without such.
There might be technical limitations i am not aware of (am still not mastering BLE) and can not guess how much effort would be needed to change the current implementation, but the new one would remain compatible with the current solution as the first parameter would set advertising power and the second defaults to 0db. So old user code would remain functional without any need to change user code.