Using the provided sample code, BLE_extended_scan and BLE_multi_advertising, i modified it to hopefully only advertise on CODED PHY and flashed two devices, one with each code.
But the settings for the TX power have no effect on the RSSI on either device. I have tried N27 to P18 without any change. The RSSI stays at around -50 at a distance of 1m. I read somwhere that the config is precompiled and tried editing the sdkconfig.h in the
C:\Users\rbrak\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-alpha1\tools\sdk\esp32c3\include\config folder and recompile, but this didn´t have any effect either.
What am i missing?
Modified advertiser:
Code: Select all
#include <BLEDevice.h>
#include <BLEAdvertising.h>
uint8_t tx_power;
esp_ble_gap_ext_adv_params_t ext_adv_params_coded = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
.interval_min = 0x50,
.interval_max = 0x50,
.channel_map = ADV_CHNL_ALL,
.own_addr_type = BLE_ADDR_TYPE_RANDOM,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_CODED,
.max_skip = 0,
.secondary_phy = ESP_BLE_GAP_PHY_CODED,
.sid = 3,
.scan_req_notif = false,
};
static uint8_t raw_scan_rsp_data_coded[] = {
0x37, 0x09, 'V', 'E', 'R', 'Y', '_', 'L', 'O', 'N', 'G', '_', 'D', 'E', 'V', 'I', 'C', 'E', '_', 'N', 'A', 'M', 'E', '_',
'S', 'E', 'N', 'T', '_', 'U', 'S', 'I', 'N', 'G', '_', 'E', 'X', 'T', 'E', 'N', 'D', 'E', 'D', '_', 'A', 'D', 'V', 'E', 'R', 'T', 'I', 'S', 'I', 'N', 'G', 0X0
};
uint8_t addr_coded[6] = {0xc0, 0xde, 0x52, 0x00, 0x00, 0x04};
BLEMultiAdvertising advert(1); // max number of advertisement data
void setup() {
Serial.begin(115200);
Serial.println("Multi-Advertising...");
BLEDevice::init("CODEServer +18dBm");
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_DEFAULT);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL0);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL1);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL2);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL3);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL4);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL5);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL6);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL7);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL8);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_ADV);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_SCAN);
esp_ble_gap_set_prefered_default_phy(ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING, ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING);
advert.setAdvertisingParams(0, &ext_adv_params_coded);
advert.setDuration(0);
advert.setScanRspData(0, sizeof(raw_scan_rsp_data_coded), &raw_scan_rsp_data_coded[0]);
advert.setInstanceAddress(0, addr_coded);
delay(1000);
advert.start(1, 0);
}
void loop() {
tx_power=esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT);
Serial.println(tx_power);
delay(2000);
}
Code: Select all
#ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
#warning "Not compatible hardware"
#else
#include <esp_bt.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
uint32_t scanTime = 100; //In 10ms (1000ms)
BLEScan* pBLEScan;
uint8_t tx_power;
class MyBLEExtAdvertisingCallbacks: public BLEExtAdvertisingCallbacks {
void onResult(esp_ble_gap_ext_adv_reprot_t report) {
if(report.event_type & ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY){
// here we can receive regular advertising data from BLE4.x devices
Serial.println("BLE4.2");
} else {
// here we will get extended advertising data that are advertised over data channel by BLE5 divices
Serial.printf("RSSI: data_le: %d, prim phy: %d \n", report.rssi, report.primary_phy);
digitalWrite(8,HIGH);
}
}
};
void setup() {
pinMode(8,OUTPUT);
Serial.begin(115200);
Serial.println("Scanning...");
BLEDevice::init("Coded +18dBm");
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_DEFAULT);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL0);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL1);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL2);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL3);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL4);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL5);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL6);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL7);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_CONN_HDL8);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_ADV);
BLEDevice::setPower(ESP_PWR_LVL_P18, ESP_BLE_PWR_TYPE_SCAN);
esp_ble_gap_set_prefered_default_phy(ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING, ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING);
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setExtendedScanCallback(new MyBLEExtAdvertisingCallbacks());
pBLEScan->setExtScanParams(); // use with pre-defined/default values, overloaded function allows to pass parameters
delay(1000); // it is just for simplicity this example, to let ble stack to set extended scan params
pBLEScan->startExtScan(scanTime, 3); // scan duration in n * 10ms, period - repeat after n seconds (period >= duration)
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
digitalWrite(8,LOW);
tx_power=esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT);
Serial.println(tx_power);
}
#endif // CONFIG_BT_BLE_50_FEATURES_SUPPORTED