Esp32-snippets: BLE server tx power

Created on 13 Nov 2017  路  23Comments  路  Source: nkolban/esp32-snippets

Hello, I'm following this example of a BLE server

https://github.com/nkolban/ESP32_BLE_Arduino/tree/master/examples/BLE_server

however, the default tx power of this server is -21dBm.

I've seen that this value is standardized to -21(ultra low power) -15(low power), -7 and -4 (medium) and 0,1 and 4 (high power). Is it possible to adjust this value?

enhancement waiting

Most helpful comment

All 23 comments

I think this is question to espressif team, because i dont see any option to setup tx power in esp-idf stack.

While I believe you are after the function on Arduino BLE, we have implemented a solution for ESP-IDF. What this means is that the next time we cut an Arduino build (or if you build an Arduino BLE library yourself) it should be present. We have implemented:

BLEDevice::setPower(powerLevel)

This sets the "default" power level of the ESP32. The available choices are as documented here:

http://esp-idf.readthedocs.io/en/latest/api-reference/bluetooth/controller_vhci.html?highlight=esp_ble_tx_power_set#_CPPv220esp_ble_tx_power_set20esp_ble_power_type_t17esp_power_level_t

We haven't tested these yet but the code changes compile cleanly.

I tried building from source and adding this, but I can't seem to figure it out, what am I doing wrong?

The file states,

/**
 * @brief Set the transmission power.
 * The power level can be one of:
 * * ESP_PWR_LVL_N14
 * * ESP_PWR_LVL_N11
 * * ESP_PWR_LVL_N8
 * * ESP_PWR_LVL_N5
 * * ESP_PWR_LVL_N2
 * * ESP_PWR_LVL_P1
 * * ESP_PWR_LVL_P4
 * * ESP_PWR_LVL_P7
 * @param [in] powerLevel.
 */

So I add,

BLEDevice::setPower(ESP_PWR_LVL_P1);
which renders,

In file included from /home/d3cline/devl/Arduinos/Luci-ESP32/Luci-ESP32.ino/Luci-ESP32.ino.ino:23:0:
/home/d3cline/Arduino/libraries/ESP32_BLE/src/BLEDevice.h: In function 'void setup()':
/home/d3cline/Arduino/libraries/ESP32_BLE/src/BLEDevice.h:56:14: error: 'static void BLEDevice::setPower(esp_power_level_t)' is private
  static void setPower(esp_power_level_t powerLevel);
              ^
Luci-ESP32.ino:101: error: within this context
   BLEDevice::setPower(ESP_PWR_LVL_P1);
                                     ^
exit status 1
within this context

I understand the general error and can read the h and cpp file for BLEDevice, but I don't understand why I suppose, where would I specify it in arduino if it is a private function in the library?

You do nothing wrong. For some reason, @nkolban, this is private function https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLEDevice.h#L56

Since it was a private function I decided to just edit line 272 of BLEDevice.cpp,

esp_err_t errRc = ::esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P1);

This is of course very hacky, but it builds. Will report my findings if it fixes radio issues.

Adjusting these values does seem to change dBm using nfc toolbox to verify, and it seems to reduce the bug I was having, fyi.

I did quick fix and PR is ready to merge. Thanks for finding it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glatteis picture glatteis  路  10Comments

HarrisonOfTheNorth picture HarrisonOfTheNorth  路  8Comments

d3cline picture d3cline  路  4Comments

mkol5222 picture mkol5222  路  5Comments

minwinmin picture minwinmin  路  9Comments