ESP32 BLE Range


I have a ESP32 flashed with Openmqttgateway to read Mijia Temperature and humiduty sensor and convert to MQTT. After weeks triing to compile and flash, finally did it…But now the Bluetooth range is only 1 or 2 meters…
There is som way to change the power of BLE in code and how to do it???


Ricardo Santos


This is strange that you get a so poor range, could you indicate the ESP32 board used? Do you have other board to test with your hum & temp sensor?


Thanks for quick answer.
The board is

I dont have other board… But the sensor works with raspberry pi at 10 meters. I wanted to use this board because the raspberry cant reach the 1st floor. I have read that esp32 has several ble tx power…


This discussion talks about power and range. I cant figured out if it aplies to openmqttgateway…

Thanks for the info, you can try to add :

esp_err_t errRc=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);
 esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN ,ESP_PWR_LVL_P9); 

Into ZgatewayBT.ino


I will try that next week, now i cant…


Sorry cant do it, dont know were to put the code…
Coud you help me??

Try maybe after this line :

Hi, this is my first post so i would like to congratulate for the great idea!
I also experienced the same issue between ESP32 and ble 4.0 keyrings. Measured signal level is -80 at 1 meter of distance.
I tried as you suggested to include the esp_ble_tx_power_set but the configuration i had to set is ESP_PWR_LVL_P7 because with ESP_PWR_LVL_P9 i got the error:

\ZgatewayBT.ino: In function ‘void setupBT()’:

ZgatewayBT:129:73: error: ‘ESP_PWR_LVL_P9’ was not declared in this scope

     esp_err_t errRc = esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT,ESP_PWR_LVL_P9);

anyway also with the P7 setup i didn’t experience any change in quality of signal (still between -70 or -80).

The purpose of my implementation is to set up a reliable presence detection to my openhab.

I configured:

#define TimeBtw_Read 500 //define the time between 2 scans
#define Scan_duration 10 //define the time for a scan

And i configured my openhab to set the person as “not at home” if i dont recieve updates for 2 minutes from the mqtt item.
Unfortunately it still looks like i got frequent offline messages. What can i do to improve my application?
Thank you!

Same range , no improove…

also saw this…

In in this case if we take this into account :


 * @brief Set the transmission power.
 * The power level can be one of:
 * * ESP_PWR_LVL_N14
 * * ESP_PWR_LVL_N11
 * @param [in] powerLevel.

Add after this line :

This code : BLEDevice::setPower(ESP_PWR_LVL_P7) ;

Thank you!
Done, still between -70 and -80 so no change at all :frowning:

Could you indicate where does these values of 70 and 80 comes from ?

Hello, between - 70 and - 80 is the signal value that I read on mqtt for my ble keyrings, when they are 1-2 meters from my esp32. If I go more far I start to not discover anymore the devices

No improvement. the range is only 2-3 meters.
Maybe its my hardware…

Do you have hardware that recomen? with guarantee better range in Bluetooth??


which hardware do you have?
This is mine:

this is mine…

I have the same board, i m going to do some range test and post the results.

1 Like

Hello any update on this issue? Thank you!

Hello,i didn’t had the time yet unfortunately. I will keep you updated