Skip to content

Conversation

@leon0399
Copy link
Member

@leon0399 leon0399 commented Jul 26, 2025

Example of BLESecurity for #8

@leon0399 leon0399 force-pushed the feature/ble-security branch 5 times, most recently from 0a90a60 to f687967 Compare July 27, 2025 02:29
@leon0399 leon0399 force-pushed the feature/ble-security branch from f687967 to 6009a40 Compare July 27, 2025 02:36
@leon0399 leon0399 marked this pull request as ready for review July 27, 2025 02:41
@leon0399 leon0399 requested a review from Copilot July 27, 2025 02:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new BLE security example demonstrating how to implement secure BLE communication with authentication and encryption features. The example shows how to set up BLE security callbacks, configure encryption settings, and handle passkey authentication.

Key changes:

  • Added a complete secure BLE serial communication example with authentication callbacks
  • Included CI configuration to build the new secure example
  • Demonstrated BLE security features including passkey generation and authentication flow

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
examples/SerialToSerialBLE_Secure/SerialToSerialBLE_Secure.ino New example implementing BLE security with authentication callbacks and encryption
.github/workflows/platformio-ci.yml Added CI build configuration for the new secure BLE example

}

uint32_t onPassKeyRequest(){
ESP_LOGI(LOG_TAG, "PassKeyRequest");
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_TAG is used but not defined. This will cause a compilation error. Define LOG_TAG as a const char* or use a string literal directly.

Copilot uses AI. Check for mistakes.
}

void onPassKeyNotify(uint32_t pass_key){
ESP_LOGI(LOG_TAG, "The passkey Notify number: %d", pass_key);
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_TAG is used but not defined. This will cause a compilation error. Define LOG_TAG as a const char* or use a string literal directly.

Copilot uses AI. Check for mistakes.
}

bool onConfirmPIN(uint32_t pass_key){
ESP_LOGI(LOG_TAG, "The passkey YES/NO number: %d", pass_key);
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_TAG is used but not defined. This will cause a compilation error. Define LOG_TAG as a const char* or use a string literal directly.

Copilot uses AI. Check for mistakes.
}

bool onSecurityRequest(){
ESP_LOGI(LOG_TAG, "SecurityRequest");
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_TAG is used but not defined. This will cause a compilation error. Define LOG_TAG as a const char* or use a string literal directly.

Copilot uses AI. Check for mistakes.
}

void onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl){
ESP_LOGI(LOG_TAG, "Starting BLE work!");
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_TAG is used but not defined. This will cause a compilation error. Define LOG_TAG as a const char* or use a string literal directly.

Copilot uses AI. Check for mistakes.
Comment on lines 21 to 22
uint32_t passKey;

Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This global passKey variable appears to be unused since the AppSecurityCallbacks class has its own private passKey member. Consider removing this unused global variable.

Suggested change
uint32_t passKey;

Copilot uses AI. Check for mistakes.

bool onConfirmPIN(uint32_t pass_key){
ESP_LOGI(LOG_TAG, "The passkey YES/NO number: %d", pass_key);
vTaskDelay(5000);
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded 5000ms delay (5 seconds) is a magic number. Consider defining it as a named constant or adding a comment explaining why this specific delay is needed for the confirmation process.

Suggested change
vTaskDelay(5000);
vTaskDelay(CONFIRMATION_DELAY_MS);

Copilot uses AI. Check for mistakes.

BLEServer* pServer = BLEDevice::createServer();

BLESecurity *pSecurity = new BLESecurity();
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory allocated for BLESecurity is never freed, causing a memory leak. Consider using a smart pointer or ensuring proper cleanup, or making it a stack variable if the lifetime permits.

Copilot uses AI. Check for mistakes.
@leon0399 leon0399 merged commit 0be3625 into main Jul 27, 2025
16 checks passed
@leon0399 leon0399 deleted the feature/ble-security branch July 27, 2025 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants