some power savings

This commit is contained in:
2025-10-19 20:11:22 +02:00
parent 7c741c42dc
commit 8bb48daf6c

View File

@@ -8,6 +8,7 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "host/ble_gap.h"
#include "host/ble_gatt.h" #include "host/ble_gatt.h"
#include "host/ble_hs.h" #include "host/ble_hs.h"
#include "host/util/util.h" #include "host/util/util.h"
@@ -152,9 +153,7 @@ void startAdvertising() {
ble_hs_adv_fields rspFields{}; ble_hs_adv_fields rspFields{};
std::memset(&rspFields, 0, sizeof(rspFields)); std::memset(&rspFields, 0, sizeof(rspFields));
rspFields.tx_pwr_lvl_is_present = 1; rc = ble_gap_adv_rsp_set_fields(&rspFields);
rspFields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
rc = ble_gap_adv_rsp_set_fields(&rspFields);
if (rc != 0) { if (rc != 0) {
ESP_LOGE(kLogTag, "ble_gap_adv_rsp_set_fields failed: %d", rc); ESP_LOGE(kLogTag, "ble_gap_adv_rsp_set_fields failed: %d", rc);
return; return;
@@ -162,8 +161,11 @@ void startAdvertising() {
ble_gap_adv_params advParams{}; ble_gap_adv_params advParams{};
std::memset(&advParams, 0, sizeof(advParams)); std::memset(&advParams, 0, sizeof(advParams));
advParams.conn_mode = BLE_GAP_CONN_MODE_UND; advParams.conn_mode = BLE_GAP_CONN_MODE_UND;
advParams.disc_mode = BLE_GAP_DISC_MODE_GEN; advParams.disc_mode = BLE_GAP_DISC_MODE_GEN;
const uint16_t advIntervalMin = BLE_GAP_ADV_ITVL_MS(3000);
advParams.itvl_min = advIntervalMin;
advParams.itvl_max = BLE_GAP_ADV_ITVL_MS(4200);
rc = ble_gap_adv_start(g_ownAddrType, nullptr, BLE_HS_FOREVER, &advParams, gapEventHandler, nullptr); rc = ble_gap_adv_start(g_ownAddrType, nullptr, BLE_HS_FOREVER, &advParams, gapEventHandler, nullptr);
if (rc != 0) { if (rc != 0) {
@@ -189,6 +191,21 @@ void onSync() {
addrVal[2], addrVal[1], addrVal[0]); addrVal[2], addrVal[1], addrVal[0]);
} }
rc = ble_gap_set_prefered_default_le_phy(BLE_HCI_LE_PHY_1M_PREF_MASK, BLE_HCI_LE_PHY_1M_PREF_MASK);
if (rc != 0) {
ESP_LOGW(kLogTag, "Failed to set preferred PHY (rc=%d)", rc);
}
if (esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_N24) != ESP_OK) {
ESP_LOGW(kLogTag, "Failed to set default TX power level");
}
if (esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_N24) != ESP_OK) {
ESP_LOGW(kLogTag, "Failed to set advertising TX power level");
}
if (esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, ESP_PWR_LVL_N24) != ESP_OK) {
ESP_LOGW(kLogTag, "Failed to set scan TX power level");
}
startAdvertising(); startAdvertising();
} }