Skip to content

change(ble_mesh): Allow setting the default pb-gatt device name (IDFGH-14914) #15623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

s0be
Copy link
Contributor

@s0be s0be commented Mar 21, 2025

Description

Currently, even if you call esp_ble_mesh_set_unprovisioned_device_name immediately after esp_ble_mesh_init, you can end up sending out an advertisement using the default 'ESP-BLE-MESH' name. Unfortunately, due to iOS limitations, this can be problematic as there's no way for a user app to flush the cached names.

Resolve this by allowing the default name to be set before calling esp_ble_mesh_init.

Testing

Modified our esp_ble_mesh test hardware and confirmed iOS never saw ESP-BLE-MESH advertised. Backported to esp-idf 5.2 for testing.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Currently, even if you call esp_ble_mesh_set_unprovisioned_device_name immediately
after esp_ble_mesh_init, you can end up sending out an advertisement using the default
'ESP-BLE-MESH' name.  Unfortunately, due to iOS limitations, this can be problematic
as there's no way for a user app to flush the cached names.

Resolve this by allowing the default name to be set before calling esp_ble_mesh_init.
Copy link

github-actions bot commented Mar 21, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello s0be, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests via this public GitHub repository.

This GitHub project is public mirror of our internal git repository

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved, we synchronize it into our internal git repository.
4. In the internal git repository we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
5. If the change is approved and passes the tests it is merged into the default branch.
5. On next sync from the internal git repository merged change will appear in this public GitHub repository.

Generated by 🚫 dangerJS against 71a9dbc

@github-actions github-actions bot changed the title change(ble_mesh): Allow setting the default pb-gatt device name change(ble_mesh): Allow setting the default pb-gatt device name (IDFGH-14914) Mar 21, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 21, 2025
@forx157
Copy link
Collaborator

forx157 commented Mar 31, 2025

Currently this part of the functionality is already available, you can learn about the API: esp_ble_mesh_set_unprovisioned_device_name,Thank you for your contribution.

@s0be
Copy link
Contributor Author

s0be commented Mar 31, 2025

@forx157 Unfortunately esp_ble_mesh_set_unprovisioned_device_name, is insufficient. When you call esp_ble_mesh_init it leads to a call to bt_mesh_proxy_server_init, which explicitly sets the name to "ESP-BLE-MESH", and starts advertising. If an iOS devices sees "ESP-BLE-MESH", it caches that name, so calling esp_ble_mesh_set_unprovisioned_device_name will not show up on the iOS device. The goal of this patch is to give the esp-idf APP the opportunity to set what the device name is before the first advertisement can be sent. iOS apps do not have the ability to flush the cache, so the only recovery path if you show the user the advertising name is to reboot the phone.

@s0be
Copy link
Contributor Author

s0be commented Mar 31, 2025

For context, here's the change we made to our app when introducing this patch and it resolved seeing 'ESP-BLE-MESH' as the name:

+    err = esp_ble_mesh_set_default_unprovisioned_device_name(deako_provisioning_get_serial());
+    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
+
     err = esp_ble_mesh_init(get_provisioning_data(), get_composition_data());
     RETURN_ON_ESP_ERROR(err, TAG, "Failed to initialize mesh stack");
 
-    err = esp_ble_mesh_set_unprovisioned_device_name(deako_provisioning_get_serial());
-    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
-

@s0be
Copy link
Contributor Author

s0be commented Apr 10, 2025

Currently this part of the functionality is already available, you can learn about the API: esp_ble_mesh_set_unprovisioned_device_name,Thank you for your contribution.

Any chance you can comment on if there's a better way for us to solve the problem this patch solves? We're fine with carrying a patch to cover deficiencies in esp-idf, but I'm sure we're not the only customer who has or will see this problem.

@s0be
Copy link
Contributor Author

s0be commented Apr 28, 2025

@forx157 Friendly ping. Can you review my comments here? The existing API is not sufficient for our needs for the reasons outlined.

@forx157
Copy link
Collaborator

forx157 commented Apr 29, 2025

Hi, @s0be
Sorry for the delayed reply. Would it meet your needs if we made the DEFAULT_DEVICE_NAME settable via Kconfig?

@s0be
Copy link
Contributor Author

s0be commented Apr 29, 2025

Sadly no, we use our device's serial number as the BLE Gatt Name, and need that as part of our pairing flow.

@forx157
Copy link
Collaborator

forx157 commented May 6, 2025

Hi, @s0be

The following code sequence for mesh initialization may meet your needs:

esp_ble_mesh_init
esp_ble_mesh_set_unprovisioned_device_name
esp_ble_mesh_prov_enable

The node does not start advertising immediately after esp_ble_mesh_init is called, but only after esp_ble_mesh_prov_enable is invoked. Thus, changing the device name before advertising starts can prevent iOS cache issues.

@s0be
Copy link
Contributor Author

s0be commented May 6, 2025

For context, here's the change we made to our app when introducing this patch and it resolved seeing 'ESP-BLE-MESH' as the name:

+    err = esp_ble_mesh_set_default_unprovisioned_device_name(deako_provisioning_get_serial());
+    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
+
     err = esp_ble_mesh_init(get_provisioning_data(), get_composition_data());
     RETURN_ON_ESP_ERROR(err, TAG, "Failed to initialize mesh stack");
 
-    err = esp_ble_mesh_set_unprovisioned_device_name(deako_provisioning_get_serial());
-    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
-

Sadly, that calling path was not sufficient, as I called out above. A small percentage of the time, the BLE stack would send out 1 advertisement with 'ESP-BLE-MESH' which would then get seen by iOS and cached.

@forx157
Copy link
Collaborator

forx157 commented May 7, 2025

For context, here's the change we made to our app when introducing this patch and it resolved seeing 'ESP-BLE-MESH' as the name:

+    err = esp_ble_mesh_set_default_unprovisioned_device_name(deako_provisioning_get_serial());
+    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
+
     err = esp_ble_mesh_init(get_provisioning_data(), get_composition_data());
     RETURN_ON_ESP_ERROR(err, TAG, "Failed to initialize mesh stack");
 
-    err = esp_ble_mesh_set_unprovisioned_device_name(deako_provisioning_get_serial());
-    RETURN_ON_ESP_ERROR(err, TAG, "esp_ble_mesh_set_unprovisioned_device_name failed");
-

Sadly, that calling path was not sufficient, as I called out above. A small percentage of the time, the BLE stack would send out 1 advertisement with 'ESP-BLE-MESH' which would then get seen by iOS and cached.

Theoretically, this situation shouldn't occur. I haven't encountered this issue in my local tests. Would you mind sharing your testing method and logs?

@s0be
Copy link
Contributor Author

s0be commented May 12, 2025

I believe the reason you don't see it is you're invoking prov_enable, while my device was already provisioned and has proxy enabled. I'm putting together a minimal example that repro's it on an esp32s3 devkit board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants