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

Adds BLE Characteristic User Description 0x2901 Descriptor #9883

Merged
merged 8 commits into from
Jun 18, 2024

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Jun 17, 2024

Description of Change

This PR adds a new BLE Descriptor Class 0x2901: characteristic user description.

The value of this description is a user-readable string describing the characteristic.
The Characteristic User Description descriptor provides a textual user description for a characteristic value.
If the Writable Auxiliary bit of the Characteristics Properties is set then this descriptor is written.
Only one User Description descriptor exists in a characteristic definition.

Modifies the Notify.ino example to use this new descriptor. It will help on detecting issues with HIL CI.

Tests scenarios

Tested with ESP32 and ESP32-C6. It can be tested using the code below or by using the modified Notify.ino example from this PR.

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

BLEServer *pServer = NULL;
BLECharacteristic *pCharacteristic = NULL;
BLE2901 *descriptor_2901 = NULL;

bool deviceConnected = false;
bool oldDeviceConnected = false;
uint32_t value = 0;

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID        "0000ff00-0000-1000-8000-00805f9b34fb"
#define CHARACTERISTIC_UUID "0000ff01-0000-1000-8000-00805f9b34fb"

class MyServerCallbacks : public BLEServerCallbacks {
  void onConnect(BLEServer *pServer) {
    deviceConnected = true;
  };

  void onDisconnect(BLEServer *pServer) {
    deviceConnected = false;
  }
};

void setup() {
  Serial.begin(115200);

  // Create the BLE Device
  BLEDevice::init("ESP32");

  // Create the BLE Server
  pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);

  // Create a BLE Characteristic
  pCharacteristic = pService->createCharacteristic(
    CHARACTERISTIC_UUID,
    BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_INDICATE
  );

  // Create a BLE Descriptor: Client Characteristic Configuration" Descriptor (CCCD) 
  pCharacteristic->addDescriptor(new BLE2902());
  // Add also the Characteristic User Description - 0x2901 descriptor
  descriptor_2901 = new BLE2901();
  descriptor_2901->setDescription("My own description for this characteristic.");
  descriptor_2901->setAccessPermissions(ESP_GATT_PERM_READ); // enforce read only - default is Read|Write 
  pCharacteristic->addDescriptor(descriptor_2901);

  // Start the service
  pService->start();

  // Start advertising
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(false);
  pAdvertising->setMinPreferred(0x0);  // set value to 0x00 to not advertise this parameter
  BLEDevice::startAdvertising();
  Serial.println("Waiting a client connection to notify...");
}

void loop() {
  // notify changed value
  if (deviceConnected) {
    pCharacteristic->setValue((uint8_t *)&value, 4);
    pCharacteristic->notify();
    value++;
    delay(300);
  }
  // disconnecting
  if (!deviceConnected && oldDeviceConnected) {
    delay(500);                   // give the bluetooth stack the chance to get things ready
    pServer->startAdvertising();  // restart advertising
    Serial.println("start advertising");
    oldDeviceConnected = deviceConnected;
  }
  // connecting
  if (deviceConnected && !oldDeviceConnected) {
    // do stuff here on connecting
    oldDeviceConnected = deviceConnected;
  }
}

Related links

Used to simulate the issue described in #9768

Adds a class for 0x2901 - Characteristic User Descriptor.

This Descriptor is usual in BLE and describes with text what each characteristic is about.
Adds Descriptor 0x2901

This is the Characteristic User Description, commomnly used in BLE. Adds the implementation for make it easier to be used.
Improve Notify.ino example by adding the 0x2901 descriptor

This also prevents and helps to find issues when testing CI.
@SuGlider SuGlider added the Area: BLE Issues related to BLE label 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 "feat(BLE): Update Notify.ino":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "feat(ble): Adds Characteristic User Description":
    • body's lines must not be longer than 100 characters
  • the commit message "fix(BLE): adds library code to the CMakeLists.txt":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "fix(BLE): fixes the UUIDs used in the example":
    • 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).

⚠️ Please consider squashing your 8 commits (simplifying branch history).
⚠️

The source branch "SuGlider-BLE-add_0x2901_descriptor" incorrect format:

  • contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS).
    Please rename your branch.

👋 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.
- 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 f095335

Fixes the UUIDs to used the ame as in BLE Client example.

Makes sure that all examples use the same UUIDs.
@SuGlider SuGlider requested review from lucasssvaz and removed request for lucasssvaz June 17, 2024 20:49
@SuGlider SuGlider marked this pull request as draft June 17, 2024 20:50
@SuGlider SuGlider marked this pull request as ready for review June 17, 2024 20:51
@SuGlider SuGlider marked this pull request as draft June 17, 2024 20:51
Adds the necessary new Library code to CMake.

Solves CI issue.
Copy link
Contributor

github-actions bot commented Jun 17, 2024

Test Results

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

Results for commit f095335.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Jun 17, 2024

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
ESP32S30⚠️ +6800.00⚠️ +0.07000.000.00
ESP32C30⚠️ +5380.00⚠️ +0.05000.000.00
ESP32C60⚠️ +5400.00⚠️ +0.05000.000.00
ESP32H20⚠️ +5380.00⚠️ +0.05000.000.00
ESP320⚠️ +6840.00⚠️ +0.06000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
BLE/examples/BLE5_extended_scan⚠️ +840000000--
BLE/examples/BLE5_multi_advertising⚠️ +840000000--
BLE/examples/BLE5_periodic_advertising⚠️ +840000000--
BLE/examples/BLE5_periodic_sync⚠️ +840000000--
BLE/examples/Beacon_Scanner⚠️ +840000000⚠️ +840
BLE/examples/Client⚠️ +840000000⚠️ +840
BLE/examples/EddystoneTLM_Beacon⚠️ +8400000--⚠️ +840
BLE/examples/EddystoneURL_Beacon⚠️ +8400000--⚠️ +840
BLE/examples/Notify⚠️ +6800⚠️ +5380⚠️ +5400⚠️ +5380⚠️ +6840
BLE/examples/Scan⚠️ +840000000⚠️ +840
BLE/examples/Server⚠️ +840000000⚠️ +840
BLE/examples/Server_multiconnect⚠️ +840000000⚠️ +840
BLE/examples/UART⚠️ +840000000⚠️ +840
BLE/examples/Write⚠️ +840000000⚠️ +840
BLE/examples/iBeacon⚠️ +840000000⚠️ +840

@SuGlider SuGlider marked this pull request as ready for review June 17, 2024 21:36
@lucasssvaz lucasssvaz added the Status: Pending Merge Pull Request is ready to be merged label Jun 18, 2024
@SuGlider SuGlider merged commit 99750cd into master Jun 18, 2024
56 checks passed
@SuGlider SuGlider deleted the SuGlider-BLE-add_0x2901_descriptor branch June 18, 2024 17:45
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
Projects
Development

Successfully merging this pull request may close these issues.

4 participants