-
Notifications
You must be signed in to change notification settings - Fork 3
📝 Add BLESecurity example #11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,86 @@ | ||||||
| #include <BLESerial.h> | ||||||
|
|
||||||
| // FOR ETL: Uncomment the following lines | ||||||
| // #include <Embedded_Template_Library.h> | ||||||
| // #include <etl/queue.h> | ||||||
| // #include <etl/circular_buffer.h> | ||||||
|
|
||||||
| BLESerial SerialBLE; | ||||||
| // If you are using an older version of Arduino IDE or C++ compiler, you may need to use | ||||||
| // an empty template argument (<>), as Class Template Argument Deduction (CTAD) is not | ||||||
| // supported in C++ versions older than C++17. For more details, see: | ||||||
| // https://www.cppreference.com/w/cpp/language/ctad.html | ||||||
| // | ||||||
| // Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler | ||||||
| // BLESerial<> SerialBLE; | ||||||
|
|
||||||
| // FOR ETL: Uncomment one of the following lines | ||||||
| // BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE; | ||||||
| // OR | ||||||
| // BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE; | ||||||
|
|
||||||
| class AppSecurityCallbacks : public BLESecurityCallbacks { | ||||||
| public: | ||||||
| AppSecurityCallbacks() { | ||||||
| this->passKey = random(111111, 999999); | ||||||
| } | ||||||
|
|
||||||
| uint32_t onPassKeyRequest(){ | ||||||
| ESP_LOGI(LOG_TAG, "PassKeyRequest"); | ||||||
|
|
||||||
| // Generate a random passkey | ||||||
| this->passKey = random(111111, 999999); | ||||||
|
|
||||||
| return this->passKey; | ||||||
| } | ||||||
|
|
||||||
| void onPassKeyNotify(uint32_t pass_key){ | ||||||
| ESP_LOGI(LOG_TAG, "The passkey Notify number: %d", pass_key); | ||||||
|
||||||
| } | ||||||
|
|
||||||
| bool onConfirmPIN(uint32_t pass_key){ | ||||||
| ESP_LOGI(LOG_TAG, "The passkey YES/NO number: %d", pass_key); | ||||||
|
||||||
| vTaskDelay(5000); | ||||||
|
||||||
| vTaskDelay(5000); | |
| vTaskDelay(CONFIRMATION_DELAY_MS); |
Copilot
AI
Jul 27, 2025
There was a problem hiding this comment.
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
AI
Jul 27, 2025
There was a problem hiding this comment.
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
AI
Jul 27, 2025
There was a problem hiding this comment.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| name=Serial_BLE | ||
| version=1.2.0 | ||
| version=1.2.1 | ||
| author=Leonid Meleshin <[email protected]> | ||
| maintainer=Leonid Meleshin <[email protected]> | ||
| sentence=Customizable BLE Serial (UART) library. | ||
|
|
||
There was a problem hiding this comment.
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.