From 963556f9ba85c7334ffd4e489ff44ed7479f43b9 Mon Sep 17 00:00:00 2001 From: ViezeVingertjes Date: Fri, 5 Sep 2025 10:46:51 +0200 Subject: [PATCH 1/3] Updated BLE functionality for low power mode in SerialBLEInterface. Updated platformio.ini to enable low power mode and added DC/DC converter support in T1000eBoard for improved power efficiency. --- src/helpers/nrf52/SerialBLEInterface.cpp | 32 +++++++++++++++++++++--- variants/t1000-e/T1000eBoard.cpp | 3 +++ variants/t1000-e/platformio.ini | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/helpers/nrf52/SerialBLEInterface.cpp b/src/helpers/nrf52/SerialBLEInterface.cpp index 170a7331..283fe405 100644 --- a/src/helpers/nrf52/SerialBLEInterface.cpp +++ b/src/helpers/nrf52/SerialBLEInterface.cpp @@ -25,10 +25,28 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) { char charpin[20]; sprintf(charpin, "%d", pin_code); - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.configPrphConn(250, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); // increase MTU + Bluefruit.configPrphBandwidth( +#ifdef BLE_LOW_POWER + BANDWIDTH_NORMAL +#else + BANDWIDTH_MAX +#endif + ); + Bluefruit.configPrphConn( +#ifdef BLE_LOW_POWER + 400, BLE_GAP_EVENT_LENGTH_MIN, 8, 8 +#else + 250, BLE_GAP_EVENT_LENGTH_MIN, 16, 16 // increase MTU +#endif + ); Bluefruit.begin(); - Bluefruit.setTxPower(4); // Check bluefruit.h for supported values + Bluefruit.setTxPower( +#ifdef BLE_LOW_POWER + 0 +#else + 4 +#endif + ); // Check bluefruit.h for supported values Bluefruit.setName(device_name); Bluefruit.Security.setMITM(true); @@ -80,7 +98,13 @@ void SerialBLEInterface::startAdv() { * https://developer.apple.com/library/content/qa/qa1931/_index.html */ Bluefruit.Advertising.restartOnDisconnect(false); // don't restart automatically as we handle it in onDisconnect - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setInterval( +#ifdef BLE_LOW_POWER + 160, 1600 +#else + 32, 244 +#endif + ); // in unit of 0.625 ms Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index a17711db..4bcdf98a 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -11,6 +11,9 @@ void T1000eBoard::begin() { sd_power_mode_set(NRF_POWER_MODE_LOWPWR); + // Enable DC/DC converter for improved power efficiency + NRF_POWER->DCDCEN = 1; + #ifdef BUTTON_PIN pinMode(BATTERY_PIN, INPUT); pinMode(BUTTON_PIN, INPUT); diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index b1826139..88c0b45d 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -100,6 +100,7 @@ build_flags = ${t1000-e.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 + -D BLE_LOW_POWER=1 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 From 7363a4f67dbeb95cbecffde5f6e6ddd2ae6fcfa8 Mon Sep 17 00:00:00 2001 From: ViezeVingertjes Date: Sun, 7 Sep 2025 14:08:26 +0200 Subject: [PATCH 2/3] Few adjustments after testing. --- src/helpers/nrf52/SerialBLEInterface.cpp | 30 ++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/helpers/nrf52/SerialBLEInterface.cpp b/src/helpers/nrf52/SerialBLEInterface.cpp index 283fe405..48708951 100644 --- a/src/helpers/nrf52/SerialBLEInterface.cpp +++ b/src/helpers/nrf52/SerialBLEInterface.cpp @@ -25,28 +25,14 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) { char charpin[20]; sprintf(charpin, "%d", pin_code); - Bluefruit.configPrphBandwidth( + Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); + Bluefruit.configPrphConn(250, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); // increase MTU #ifdef BLE_LOW_POWER - BANDWIDTH_NORMAL + Bluefruit.setTxPower(0); #else - BANDWIDTH_MAX + Bluefruit.setTxPower(4); #endif - ); - Bluefruit.configPrphConn( -#ifdef BLE_LOW_POWER - 400, BLE_GAP_EVENT_LENGTH_MIN, 8, 8 -#else - 250, BLE_GAP_EVENT_LENGTH_MIN, 16, 16 // increase MTU -#endif - ); Bluefruit.begin(); - Bluefruit.setTxPower( -#ifdef BLE_LOW_POWER - 0 -#else - 4 -#endif - ); // Check bluefruit.h for supported values Bluefruit.setName(device_name); Bluefruit.Security.setMITM(true); @@ -98,13 +84,7 @@ void SerialBLEInterface::startAdv() { * https://developer.apple.com/library/content/qa/qa1931/_index.html */ Bluefruit.Advertising.restartOnDisconnect(false); // don't restart automatically as we handle it in onDisconnect - Bluefruit.Advertising.setInterval( -#ifdef BLE_LOW_POWER - 160, 1600 -#else - 32, 244 -#endif - ); // in unit of 0.625 ms + Bluefruit.Advertising.setInterval(32, 1600); Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds From 5370667bd85b9c3c24d7f430a318e975dc9ab5d4 Mon Sep 17 00:00:00 2001 From: ViezeVingertjes Date: Sun, 7 Sep 2025 15:44:24 +0200 Subject: [PATCH 3/3] Replaced BLE_LOW_POWER with BLE_TX_POWER & updated usages. --- src/helpers/nrf52/SerialBLEInterface.cpp | 6 +----- src/helpers/nrf52/SerialBLEInterface.h | 4 ++++ variants/t1000-e/platformio.ini | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helpers/nrf52/SerialBLEInterface.cpp b/src/helpers/nrf52/SerialBLEInterface.cpp index 48708951..4bc9d10a 100644 --- a/src/helpers/nrf52/SerialBLEInterface.cpp +++ b/src/helpers/nrf52/SerialBLEInterface.cpp @@ -27,11 +27,7 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) { Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); Bluefruit.configPrphConn(250, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); // increase MTU -#ifdef BLE_LOW_POWER - Bluefruit.setTxPower(0); -#else - Bluefruit.setTxPower(4); -#endif + Bluefruit.setTxPower(BLE_TX_POWER); Bluefruit.begin(); Bluefruit.setName(device_name); diff --git a/src/helpers/nrf52/SerialBLEInterface.h b/src/helpers/nrf52/SerialBLEInterface.h index 12a4f46a..239cf6c4 100644 --- a/src/helpers/nrf52/SerialBLEInterface.h +++ b/src/helpers/nrf52/SerialBLEInterface.h @@ -3,6 +3,10 @@ #include "../BaseSerialInterface.h" #include +#ifndef BLE_TX_POWER +#define BLE_TX_POWER 4 +#endif + class SerialBLEInterface : public BaseSerialInterface { BLEUart bleuart; bool _isEnabled; diff --git a/variants/t1000-e/platformio.ini b/variants/t1000-e/platformio.ini index 88c0b45d..8978ec15 100644 --- a/variants/t1000-e/platformio.ini +++ b/variants/t1000-e/platformio.ini @@ -100,7 +100,7 @@ build_flags = ${t1000-e.build_flags} -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=8 -D BLE_PIN_CODE=123456 - -D BLE_LOW_POWER=1 + -D BLE_TX_POWER=0 ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1