esp-idf icon indicating copy to clipboard operation
esp-idf copied to clipboard

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

Open s0be opened this issue 9 months ago • 4 comments

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:

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

s0be avatar Mar 21 '25 22:03 s0be

Messages
:book: 🎉 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 :no_entry_sign: dangerJS against 71a9dbc9671a11985a0d4757a77354d555419d6f

github-actions[bot] avatar Mar 21 '25 22:03 github-actions[bot]

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.

forx157 avatar Mar 31 '25 02:03 forx157

@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 avatar Mar 31 '25 19:03 s0be

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 avatar Mar 31 '25 19:03 s0be

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 avatar Apr 10 '25 18:04 s0be

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

s0be avatar Apr 28 '25 21:04 s0be

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

forx157 avatar Apr 29 '25 02:04 forx157

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

s0be avatar Apr 29 '25 17:04 s0be

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.

forx157 avatar May 06 '25 03:05 forx157

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.

s0be avatar May 06 '25 20:05 s0be

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?

forx157 avatar May 07 '25 04:05 forx157

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.

s0be avatar May 12 '25 17:05 s0be