From 492e2ae5e57b4387070cb3fb9b70e16917877a3b Mon Sep 17 00:00:00 2001 From: Mike Robbins Date: Fri, 17 Oct 2025 21:43:03 -0400 Subject: [PATCH] requestLowerPowerConnection --- src/nimble/NimbleBluetooth.cpp | 43 +++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index a58215a0c..654a0eb8e 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -591,9 +591,15 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks constraints, and recommendations. (Android doesn't have specific constraints, but seems to be compatible with the Apple recommendations.) - minInterval (units of 1.25ms): 7.5ms = 6 (lower than the Apple recommended minimum, but allows faster when the client - supports it.) maxInterval (units of 1.25ms): 15ms = 12 latency: 0 (don't allow peripheral to skip any connection events) - timeout (units of 10ms): 6 seconds = 600 (supervision timeout) + Selected settings: + minInterval (units of 1.25ms): 7.5ms = 6 (lower than the Apple recommended minimum, but allows faster when the client + supports it.) + maxInterval (units of 1.25ms): 15ms = 12 + latency: 0 (don't allow peripheral to skip any connection events) + timeout (units of 10ms): 6 seconds = 600 (supervision timeout) + + These are intentionally aggressive to prioritize speed over power consumption, but are only used for a few seconds at + setup. Not worth adjusting much. */ LOG_INFO("BLE requestHighThroughputConnection"); #ifdef NIMBLE_TWO @@ -602,6 +608,37 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks bleServer->updateConnParams(desc->conn_handle, 6, 12, 0, 600); #endif } + +#ifdef NIMBLE_TWO + void requestLowerPowerConnection(NimBLEConnInfo &connInfo) +#else + void requestLowerPowerConnection(ble_gap_conn_desc *desc) +#endif + { + /* Request a lower power consumption (but higher latency, lower throughput) BLE connection. + + This is suitable for steady-state operation after initial setup is complete. + + See https://developer.apple.com/library/archive/qa/qa1931/_index.html for formulas to calculate values, iOS/macOS + constraints, and recommendations. (Android doesn't have specific constraints, but seems to be compatible with the Apple + recommendations.) + + Selected settings: + minInterval (units of 1.25ms): 30ms = 24 + maxInterval (units of 1.25ms): 50ms = 40 + latency: 2 (allow peripheral to skip up to 2 consecutive connection events to save power) + timeout (units of 10ms): 6 seconds = 600 (supervision timeout) + + There's an opportunity for tuning here if anyone wants to do some power measurements, but these should allow 10-20 packets + per second. + */ + LOG_INFO("BLE requestLowerPowerConnection"); +#ifdef NIMBLE_TWO + bleServer->updateConnParams(connInfo.getConnHandle(), 24, 40, 2, 600); +#else + bleServer->updateConnParams(desc->conn_handle, 24, 40, 2, 600); +#endif + } }; static NimbleBluetoothToRadioCallback *toRadioCallbacks;