52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include <BluetoothSerial.h>
|
|
#include "esp_bt.h"
|
|
#include "esp_bt_main.h"
|
|
#include "esp_bt_device.h"
|
|
|
|
BluetoothSerial SerialBT;
|
|
|
|
void setBluetoothTxPower(esp_power_level_t powerLevel) {
|
|
esp_err_t err = esp_bredr_tx_power_set(powerLevel, powerLevel);
|
|
if (err != ESP_OK) {
|
|
Serial.printf("Failed to set TX Power: %s\n", esp_err_to_name(err));
|
|
} else {
|
|
Serial.printf("TX Power set to level %d\n", powerLevel);
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(1000);
|
|
|
|
Serial.println("Initializing Bluetooth...");
|
|
|
|
if (!btStart()) {
|
|
Serial.println("Failed to start BT controller");
|
|
return;
|
|
}
|
|
|
|
// Disable and re-enable the classic BT stack to safely set TX power
|
|
esp_bluedroid_disable();
|
|
esp_bluedroid_deinit();
|
|
|
|
// Set Classic BT TX power (e.g., ESP_PWR_LVL_P9 = highest)
|
|
//setBluetoothTxPower(ESP_PWR_LVL_P9);
|
|
setBluetoothTxPower(ESP_PWR_LVL_N12);
|
|
|
|
|
|
esp_bluedroid_init();
|
|
esp_bluedroid_enable();
|
|
|
|
if (!SerialBT.begin("ESP32-TXPowerTest")) {
|
|
Serial.println("Bluetooth Serial failed to start");
|
|
return;
|
|
}
|
|
|
|
Serial.println("Bluetooth initialized and ready!");
|
|
}
|
|
|
|
void loop() {
|
|
SerialBT.println("Hello from ESP32 with boosted TX power!");
|
|
delay(1);
|
|
}
|