Hardcoding BLE TX Power

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
forum_user
Posts: 4
Joined: Thu Jan 30, 2020 11:14 pm

Hardcoding BLE TX Power

Post by forum_user » Mon Feb 10, 2020 6:43 pm

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?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Hardcoding BLE TX Power

Post by jimmo » 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()

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: Hardcoding BLE TX Power

Post by Lobo-T » Tue Nov 16, 2021 3:31 pm

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?

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: Hardcoding BLE TX Power

Post by Lobo-T » Thu Nov 18, 2021 9:33 pm

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.

Post Reply