🛠 Publicité BLE 5 en longue portée (Coded PHY)
Objectives
The ESP32-C3 is a Bluetooth 5.0 radio: it supports the coded PHY (Coded PHY, 125 or 500 kbit/s), which doubles or quadruples the advertising range compared to classic BLE 4.2 at 1 Mbit/s. You will configure the Bluedroid stack to transmit on this extended PHY and verify it with a compatible central device.
Hardware
- 1 ESP32-C3 board
- 1 recent smartphone or nRF dongle with nRF Connect (BLE 5 support)
- Arduino-ESP32 core 2.0.14 or newer
Full code
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include "esp_gap_ble_api.h"
// Publicite : drapeau LE General + nom "C3 LONGRANGE"
static uint8_t adv_data[] = {
0x02, 0x01, 0x06,
0x0D, 0x09, 'C','3',' ','L','O','N','G','R','A','N','G','E'
};
void setup {
Serial.begin(115200);
BLEDevice::init("C3-LONGRANGE");
// BLE 5 : emission sur PHY code 125 kbit/s (longue portee)
esp_ble_gap_config_own_le_phy(BLE_LE_CODED_PHY);
esp_ble_gap_config_adv_data_raw(adv_data, sizeof(adv_data));
esp_ble_adv_params_t params = {
.adv_int_min = 0x100,
.adv_int_max = 0x160,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
esp_ble_gap_start_advertising(¶ms);
Serial.println(F("Publicite emise sur PHY code (BLE 5)"));
}
void loop { delay(1000); }
Expected verification
nRF Connect on a BLE 5 central displays “C3 LONGRANGE”; by moving the board several tens of meters away outdoors, the advertising remains received where classic 1 Mbit/s advertising would have disappeared. The controller log indicates the coded PHY used.
Common errors
- Older central or BLE 4.x USB dongle: it does not scan the coded PHY, so the advertising appears “invisible” even though it is being transmitted.
- Forgetting to enable BLE 5 features (extended advertising / coded PHY) in the stack configuration: the call to use the coded PHY is silently ignored.
- Expecting high throughput: the Coded PHY changes range, not bandwidth — 125 kbit/s is low by design.
- Comparing distances without the same transmit power: also adjust the TX power for a fair comparison.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino