Watch
0
0
Fork
You've already forked esp32-c_its-companion
0

ble: Set short name in advertisement

This commit is contained in:
Jannik Beyerstedt 2026-09-29 15:25:16 +02:00
commit 9a820356ff
2 changed files with 12 additions and 6 deletions

View file

@ -110,6 +110,7 @@ pub async fn run(
CONTROLLER_SLOTS,
>,
name: alloc::string::String,
short_name: alloc::string::String,
) {
let mut resources: HostResources<DefaultPacketPool, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX> =
HostResources::new();
@ -120,6 +121,7 @@ pub async fn run(
..
} = stack.build();
info!("BLE name: {name} (short: {short_name})");
info!(
"Starting advertising and GATT service for {}",
crate::util::get_rx_feature_list().join(",")
@ -132,7 +134,7 @@ pub async fn run(
let _ = embassy_futures::join::join(ble_task(runner), async {
loop {
match advertise(&mut peripheral, &server).await {
match advertise(&mut peripheral, &server, &short_name).await {
Ok(conn) => {
info!("BLE: New client connected");
@ -176,16 +178,19 @@ pub fn update(payload: BleSendable) {
async fn advertise<'values, 'server, C: Controller>(
peripheral: &mut Peripheral<'values, C, DefaultPacketPool>,
server: &'server Server<'values>,
// name in advertisement, max. 8 characters
short_name: &'values str,
) -> Result<GattConnection<'values, 'server, DefaultPacketPool>, BleHostError<C::Error>> {
let mut advertiser_data = [0; 35];
let mut advertiser_data = [0; 31]; // 37 bytes payload - 6 byte address
let service_uuid = Uuid::from(0xc0b7_0000_d4f4_4000_ada8_f99a_02ee_315c_u128)
.as_raw()
.try_into()
.unwrap();
let len = AdStructure::encode_slice(
&[
AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED),
AdStructure::ServiceUuids128(&[service_uuid]),
AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), // 2+ 1 byte
AdStructure::ServiceUuids128(&[service_uuid]), // 2+16 byte = 21
AdStructure::ShortenedLocalName(short_name.as_bytes()), // 2+ 8 byte = 31
],
&mut advertiser_data[..],
)?;