BLE Tx Power Setting Error

Jackie
Posts: 3
Joined: Fri May 13, 2022 6:45 am

BLE Tx Power Setting Error

Postby Jackie » Sun May 15, 2022 5:22 pm

ESP IDF:4.4.1 with Espressif ide Version: 2.4.2
Sourcecode: BLE Mesh - OnOffServer Example
Chip:ESP32-C3

While trying to set
err = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV,ESP_PWR_LVL_P9);

Following error comes:
error: implicit declaration of function 'esp_ble_tx_power_set'

Code compiles with warning when function modified as below:
esp_err_t esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV,ESP_PWR_LVL_P9);

warning: parameter names (without types) in function declaration

How to find whether tx power was applied successfully?
How to find the actual tx power in use?



Code (part only)
void app_main(void) {
esp_err_t err;

ESP_LOGI(TAG, "Initializing...");

board_init();

err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK(err);

err = bluetooth_init();
if (err) {
ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err);
return;
}

ble_mesh_get_dev_uuid(dev_uuid);

/* Initialize the Bluetooth Mesh Subsystem */
err = ble_mesh_init();

//int v = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, 8);

if (err) {
ESP_LOGE(TAG, "Bluetooth mesh init failed (err %d)", err);
} else {
err = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV,ESP_PWR_LVL_P9);
}
}

User avatar
OpenSushi
Posts: 1
Joined: Thu Jun 23, 2022 5:33 am

Re: BLE Tx Power Setting Error

Postby OpenSushi » Thu Jul 14, 2022 10:24 am

Hi,

You can try checking the method return value with [ESP_ERROR_CHECK(x)](https://docs.espressif.com/projects/esp ... RROR_CHECK) macro.

Code: Select all

} else {
   ESP_ERROR_CHECK(esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV,ESP_PWR_LVL_P9));
   # Check current Tx power
   esp_pwr_level_t min, max;
   esp_bredr_tx_power_get(&min, &max);
   ESP_LOGI(TAG, "Tx Power %d min, %d max", min, max);
}
Answering to the error from compilation, you must add the header file for

Code: Select all

esp_ble_power_set()
in your file, otherwise the compiler won't find the function when it's needed.

EDIT:
Check that if you are using an ESP32 you won't have problems calling

Code: Select all

esp_bredr_tx_power_get()
, but, if you are using any other development or chip, aka ESP32C3/S3/C2/S2/H2 you have to use other functions as

Code: Select all

esp_ble_tx_power_get
because

Code: Select all

esp_bredr_tx_power_get()
does not exists for them.

An example would be next:

Code: Select all

// #define ESP32
#define ESP32C3
// ... other code
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL0, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL1, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL2, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL3, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL4, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL5, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL6, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL7, DEFAULT_PWR_LVL);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_CONN_HDL8, DEFAULT_PWR_LVL);
#ifdef ESP32
    // Estas funciones no existen para el esp32c3/s3/c2/s2/h2 aunque la documentación diga que sí. En el código fuente no aparecen
    esp_power_level_t min, max;
    esp_bredr_tx_power_set(ESP_PWR_LVL_P6, ESP_PWR_LVL_P9);
    esp_bredr_tx_power_get(&min, &max);
    ESP_LOGI(TAG, "Tx Power: %d min, %d max", min, max);
#else 
    esp_power_level_t powerindex = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT);
    ESP_LOGI(TAG, "BT Tx Power index: %d", powerindex);
#endif
--
Gina

Who is online

Users browsing this forum: Baidu [Spider] and 146 guests