Page 1 of 1

Hardcoding BLE TX Power

Posted: Mon Feb 10, 2020 6:43 pm
by forum_user
I'm interested in hardcoding the maximum supported TX power value for BLE scans for hardware testing. According to a recent post, +9db is the max supported value via the esp-idf API:

https://github.com/espressif/esp-idf/is ... -493992705

It seems this has been briefly discussed previously and is a planned feature:

https://github.com/micropython/micropyt ... -503046267
https://github.com/micropython/micropyt ... -540526800

I don't need to modify it on the fly, so hardcoding this prior to firmware compilation is fine. Could anyone give me some basic guidance on how to achieve this?

Re: Hardcoding BLE TX Power

Posted: Sat Feb 15, 2020 5:11 am
by jimmo
I think you should be able to add the call to esp_ble_tx_power_set in ports/esp32/nimble.c / mp_bluetooth_nimble_port_preinit()

Re: Hardcoding BLE TX Power

Posted: Tue Nov 16, 2021 3:31 pm
by Lobo-T
jimmo wrote:
Sat Feb 15, 2020 5:11 am
I think you should be able to add the call to esp_ble_tx_power_set in ports/esp32/nimble.c / mp_bluetooth_nimble_port_preinit()
This file and function does not seem to exist anymore.
Where would I do this in the latest version?

Re: Hardcoding BLE TX Power

Posted: Thu Nov 18, 2021 9:33 pm
by Lobo-T
I sorted it out.

In case someone else finds this post:
In the file ports/esp32/mp_nimbleport.c i added an #include "esp_bt.h" and in the function mp_bluetooth_nimble_port_hci_init(void) after esp_nimble_hci_and_controller_init() i added the following:

Code: Select all

    
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9);
    esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, ESP_PWR_LVL_P9);
Seems to work.

I wish I knew enough about how this all fits together to make a function to set it from Micropython, but I'm not there yet.