Skip to content
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

fix(BLE): Arduino String shall not be used within std::map<> #9875

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

SuGlider
Copy link
Collaborator

Description of Change

This PR partially reverts changes done in PR #8724 related to using Arduino String, as a Key, within std::map<>.
It replaces Arduino String by std::string which is a C++ class compatible with std::map<> template, that must implement std::less in order to allow necesary comparation when inserting <Key, T> into the map.

Tests scenarios

Tested using ESP32, ESP32-S3 and ESP32-C6.

In order to test it, it is possible to use the BLE Client example running in one ESP32 SoC
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/Client/Client.ino

The second ESP32 SoC shall run a modified version of the BLE Server that adds a second characteristic in the same service.
Based on the code of https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/Server/Server.ino

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID_1 "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHARACTERISTIC_UUID_2 "beb5483e-36e2-4688-b7f5-ea07361b26a8"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic1 =
    pService->createCharacteristic(CHARACTERISTIC_UUID_1, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);

  pCharacteristic1->setValue("Characteristic 1");

  BLECharacteristic *pCharacteristic2 =
    pService->createCharacteristic(CHARACTERISTIC_UUID_2, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);

  pCharacteristic2->setValue("Characteristic 2");

  pService->start();
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

Related links

Fix #9768

@SuGlider SuGlider added Type: Bug 🐛 All bugs Type: Regression Result of unforeseen consequences of a previous change Area: BLE Issues related to BLE labels Jun 17, 2024
@SuGlider SuGlider added this to the 3.0.2 milestone Jun 17, 2024
@SuGlider SuGlider self-assigned this Jun 17, 2024
Copy link
Contributor

github-actions bot commented Jun 17, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Update libraries/BLE/src/BLERemoteService.cpp":
    • summary looks empty
    • type/action looks empty
  • the commit message "fix(BLE): std::map()":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

Messages
📖 You might consider squashing your 4 commits (simplifying branch history).

👋 Hello SuGlider, we appreciate your contribution to 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.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- 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.

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 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.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 88ea692

Copy link
Contributor

github-actions bot commented Jun 17, 2024

Test Results

 56 files   56 suites   5m 16s ⏱️
 21 tests  21 ✅ 0 💤 0 ❌
135 runs  135 ✅ 0 💤 0 ❌

Results for commit 88ea692.

♻️ This comment has been updated with latest results.

Copy link
Contributor

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32S3000.000.00000.000.00
ESP32C3000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32H2000.000.00000.000.00
ESP32000.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
BLE/examples/BLE5_extended_scan----------
BLE/examples/BLE5_multi_advertising----------
BLE/examples/BLE5_periodic_advertising----------
BLE/examples/BLE5_periodic_sync----------
BLE/examples/Beacon_Scanner----------
BLE/examples/Client----------
BLE/examples/EddystoneTLM_Beacon----------
BLE/examples/EddystoneURL_Beacon----------
BLE/examples/Notify----------
BLE/examples/Scan----------
BLE/examples/Server----------
BLE/examples/Server_multiconnect----------
BLE/examples/UART----------
BLE/examples/Write----------
BLE/examples/iBeacon----------

@SuGlider SuGlider added the Status: Review needed Issue or PR is awaiting review label Jun 17, 2024
@lucasssvaz lucasssvaz added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Jun 17, 2024
@me-no-dev me-no-dev merged commit 32def87 into espressif:master Jun 17, 2024
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BLE Issues related to BLE Status: Pending Merge Pull Request is ready to be merged Type: Bug 🐛 All bugs Type: Regression Result of unforeseen consequences of a previous change
Projects
Development

Successfully merging this pull request may close these issues.

Exception on BLERemoteService::getCharacteristic
3 participants