I am playing with esp_ble_tx_power_set API to set maximum BLE TX power during advertisement and communication.
I run my code on WROVER-I module acting as BLE peripheral, latest IDF version, however I observe the issue for at least six months with latest IDF version.
What I have noticed is that changing esp_ble_tx_power_set has no effect on advertised TX level and also very limited (if any) effect on BLE connection distance (it is always around 10 meters indoors).
In my esp_ble_adv_data_t I set .include_txpower = true, and can observe advertised TX power using NRF Connect, however it is always -21dbm regardless of the value passed to esp_ble_tx_power_set.
Also, as I mentioned I do not notice any significant difference between ESP_PWR_LVL_P9 and ESP_PWR_LVL_N12, while I expect it to be clearly noticeable by communication distance.
Below is the code I use to change the TX level. Use both together with WiFi and without it. Can anyone suggest if this API has bugs, should I do it differently, or my expectations are just wrong?
Code: Select all
esp_err_t ret;
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(BLE_TAG, "%s initialize controller failed\n", __func__);
return;
}
ESP_LOGI(BLE_TAG, "%s initialize controller success\n", __func__);
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
ESP_LOGE(BLE_TAG, "%s enable controller failed\n", __func__);
return;
}
ESP_LOGI(BLE_TAG, "%s enable controller success\n", __func__);
ESP_LOGI(BLE_TAG, "%s Successfully set BLE Tx power level\n", __func__);
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE(BLE_TAG, "%s init bluetooth failed\n", __func__);
return;
}
ESP_LOGI(BLE_TAG, "%s init bluetooth success\n", __func__);
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(BLE_TAG, "%s enable bluetooth failed\n", __func__);
return;
}
ESP_LOGI(BLE_TAG, "%s enable bluetooth success\n", __func__);
ret = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9);
if (ret) {
ESP_LOGE(BLE_TAG, "%s Unable to set BLE Tx power level\n", __func__);
return;
}
ESP_LOGI(BLE_TAG, "%s Successfully set BLE Tx power level\n", __func__);
ret = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
if (ret) {
ESP_LOGE(BLE_TAG, "%s Unable to set BLE Tx power level\n", __func__);
return;
}