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

BluetoothSerial - Reduce bluetooth serial flush delay #9905

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

vincadrn
Copy link
Contributor

Description of Change

Changed

to use delay(2) instead to reduce the flush time.

Tests scenarios

Tested the change on Windows. Found the affected file in C:\Users\<local_machine_name>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3\libraries\BluetoothSerial\src

I used this for testing:

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;
unsigned long takenTime;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  SerialBT.begin("ESP32-Slave");
}

void loop() {
  // put your main code here, to run repeatedly:
  if (!SerialBT.connected(1000)) {
    return;
  }
  
  SerialBT.println("Lorem ipsum dolor sit amet, consectetur adipiscing elit."
  " Fusce in felis vel nunc finibus maximus ut ut mi. In hac habitasse platea dictumst. Etiam ac tincidunt nulla. Curabitur vel dictum enim."
  " Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce viverra neque sit amet erat ultrices, sed dictum sem auctor. Sed eget ultrices justo. Etiam non posuere odio."
  " In dignissim enim sed magna porta cursus. Nulla semper tortor vel sapien pellentesque, quis dapibus diam posuere. Nulla dapibus enim in lacus dictum, vitae blandit purus semper."
  " Proin augue elit, euismod sit amet sem eget, iaculis cursus neque. Proin in placerat diam. Nam hendrerit interdum accumsan. Aliquam et eros sit amet felis varius hendrerit."
  " Sed vel massa fermentum, elementum orci eleifend, consequat arcu. Curabitur viverra mollis tortor ut lobortis. Proin at lobortis tortor. Praesent non est enim."
  " Nullam mattis ultrices dapibus. Integer hendrerit, lacus sed pellentesque pharetra, mauris dui gravida odio, in tempus nisl dolor non nunc. Nullam nec magna a elit molestie blandit."
  " Pellentesque dignissim, arcu id sollicitudin auctor, urna nisl sollicitudin metus, at lobortis arcu enim nec leo. Quisque cursus euismod dolor. Donec id velit et lacus commodo accumsan."
  " Duis cursus bibendum massa, ac viverra risus tempus in."
  " Aenean porta pharetra libero et placerat. Phasellus et lobortis ipsum. Morbi aliquam aliquam accumsan. Praesent sit amet scelerisque nulla."
  " Nam dictum, erat sit amet pulvinar vestibulum, justo turpis lobortis dui, id malesuada magna augue et leo. Donec sit amet elit est."
  " Pellentesque purus ligula, auctor eget ligula at, pharetra congue sapien. Nulla scelerisque eros a semper eleifend."
  " Quisque euismod, justo id ultricies pellentesque, risus urna gravida ante, ut pulvinar nibh est nec mauris.");

  takenTime = millis();

  SerialBT.flush();
  Serial.print("Time spent flushing (in ms): ");
  Serial.println(millis() - takenTime);

  delay(250);
}

Result without the change (100 ms of delay)

21:19:10.328 -> Time spent flushing (in ms): 100
21:19:10.688 -> Time spent flushing (in ms): 100
21:19:11.048 -> Time spent flushing (in ms): 100
21:19:11.409 -> Time spent flushing (in ms): 100
21:19:11.729 -> Time spent flushing (in ms): 100
21:19:12.089 -> Time spent flushing (in ms): 100
21:19:12.450 -> Time spent flushing (in ms): 100
21:19:12.810 -> Time spent flushing (in ms): 100
21:19:13.130 -> Time spent flushing (in ms): 100
21:19:13.490 -> Time spent flushing (in ms): 100
21:19:13.851 -> Time spent flushing (in ms): 100
21:19:14.210 -> Time spent flushing (in ms): 100
21:19:14.530 -> Time spent flushing (in ms): 100
21:19:14.891 -> Time spent flushing (in ms): 100
21:19:15.250 -> Time spent flushing (in ms): 100
21:19:15.610 -> Time spent flushing (in ms): 100
21:19:15.930 -> Time spent flushing (in ms): 100
21:19:16.291 -> Time spent flushing (in ms): 100
21:19:16.652 -> Time spent flushing (in ms): 100
21:19:17.012 -> Time spent flushing (in ms): 100
21:19:17.333 -> Time spent flushing (in ms): 100
21:19:17.693 -> Time spent flushing (in ms): 100
21:19:18.053 -> Time spent flushing (in ms): 100
21:19:18.413 -> Time spent flushing (in ms): 100
21:19:18.733 -> Time spent flushing (in ms): 100
21:19:19.093 -> Time spent flushing (in ms): 100
21:19:19.453 -> Time spent flushing (in ms): 100
21:19:19.813 -> Time spent flushing (in ms): 100
21:19:20.133 -> Time spent flushing (in ms): 100
21:19:20.493 -> Time spent flushing (in ms): 100
21:19:20.853 -> Time spent flushing (in ms): 100
21:19:21.213 -> Time spent flushing (in ms): 100
21:19:21.534 -> Time spent flushing (in ms): 100
21:19:21.894 -> Time spent flushing (in ms): 100
21:19:22.256 -> Time spent flushing (in ms): 100
21:19:22.616 -> Time spent flushing (in ms): 100
21:19:22.936 -> Time spent flushing (in ms): 100
21:19:23.296 -> Time spent flushing (in ms): 100
21:19:23.655 -> Time spent flushing (in ms): 100
21:19:24.016 -> Time spent flushing (in ms): 100

Result with the change (2 ms of delay)

21:17:16.994 -> Time spent flushing (in ms): 8
21:17:17.234 -> Time spent flushing (in ms): 8
21:17:17.514 -> Time spent flushing (in ms): 8
21:17:17.754 -> Time spent flushing (in ms): 8
21:17:18.035 -> Time spent flushing (in ms): 8
21:17:18.275 -> Time spent flushing (in ms): 8
21:17:18.555 -> Time spent flushing (in ms): 8
21:17:18.795 -> Time spent flushing (in ms): 8
21:17:19.035 -> Time spent flushing (in ms): 8
21:17:19.315 -> Time spent flushing (in ms): 8
21:17:19.555 -> Time spent flushing (in ms): 8
21:17:19.836 -> Time spent flushing (in ms): 8
21:17:20.076 -> Time spent flushing (in ms): 8
21:17:20.356 -> Time spent flushing (in ms): 8
21:17:20.596 -> Time spent flushing (in ms): 8
21:17:20.876 -> Time spent flushing (in ms): 8
21:17:21.116 -> Time spent flushing (in ms): 8
21:17:21.397 -> Time spent flushing (in ms): 10
21:17:21.637 -> Time spent flushing (in ms): 8
21:17:21.877 -> Time spent flushing (in ms): 8
21:17:22.157 -> Time spent flushing (in ms): 8
21:17:22.397 -> Time spent flushing (in ms): 8
21:17:22.677 -> Time spent flushing (in ms): 8
21:17:22.917 -> Time spent flushing (in ms): 10
21:17:23.199 -> Time spent flushing (in ms): 8
21:17:23.439 -> Time spent flushing (in ms): 8
21:17:23.719 -> Time spent flushing (in ms): 8
21:17:23.959 -> Time spent flushing (in ms): 8
21:17:24.239 -> Time spent flushing (in ms): 8
21:17:24.479 -> Time spent flushing (in ms): 10
21:17:24.719 -> Time spent flushing (in ms): 8
21:17:24.999 -> Time spent flushing (in ms): 8
21:17:25.239 -> Time spent flushing (in ms): 8
21:17:25.519 -> Time spent flushing (in ms): 8
21:17:25.759 -> Time spent flushing (in ms): 8
21:17:26.039 -> Time spent flushing (in ms): 10
21:17:26.280 -> Time spent flushing (in ms): 8

Related links

Closes #9868

@CLAassistant
Copy link

CLAassistant commented Jun 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello vincadrn, 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.
- 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 c4ab139

Copy link
Contributor

github-actions bot commented Jun 19, 2024

Test Results

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

Results for commit c4ab139.

♻️ This comment has been updated with latest results.

@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Jun 19, 2024
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
ESP32💚 -400.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32
ExampleFLASHRAM
BluetoothSerial/examples/DiscoverConnect💚 -40
BluetoothSerial/examples/GetLocalMAC💚 -40
BluetoothSerial/examples/SerialToSerialBT💚 -40
BluetoothSerial/examples/SerialToSerialBTM💚 -40
BluetoothSerial/examples/SerialToSerialBT_Legacy00
BluetoothSerial/examples/SerialToSerialBT_SSP💚 -40
BluetoothSerial/examples/bt_classic_device_discovery💚 -40
BluetoothSerial/examples/bt_remove_paired_devices💚 -40

@me-no-dev me-no-dev merged commit d708438 into espressif:master Jun 19, 2024
62 of 63 checks passed
@vincadrn vincadrn deleted the shorten-bt-flush branch June 20, 2024 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Merge Pull Request is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BluetoothSerial::flush() takes too long
4 participants