Skip to content

Allow BluetoothSerial::connect() with specified channel and more options #6380

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

Merged
merged 9 commits into from
Apr 26, 2022

Conversation

ferbar
Copy link
Contributor

@ferbar ferbar commented Mar 6, 2022

By completing this PR sufficiently, you help us to improve the quality of Release Notes

Checklist

  1. Please provide specific title of the PR describing the change, including the component name (eg. „Update of Documentation link on Readme.md“)
  2. Please provide related links (eg. Issue, other Project, submodule PR..)
  3. Please check Contributing guide

This entire section above can be deleted if all items are checked.


Summary

Improve options of BluetoothSerial::connect(), improve error handling

Impact

BTAddress constification, BTAdvertisedDevice;
Add: connect with channel, sec_mask (auth/no-auth), role options(master/slave)
Add: getChannels() - list remote SPP channels
Add: isClosed - connection aborted by remote side, no need to wait for a connection.
Add: setTimeout - set timeout for read() or peek()
Add: Example for discover, getChannels(), connect() with options, isClosed()

Existing code should not be affected.

Related links

Please provide links to related issue, PRs etc.

@CLAassistant
Copy link

CLAassistant commented Mar 6, 2022

CLA assistant check
All committers have signed the CLA.

@mrengineer7777
Copy link
Collaborator

Intriguing addition. First time I've seen use of const after a function name. I'm a 'C' guy. Can you tell me what "const" does here? e.g.
bool haveRSSI() const;

@ferbar
Copy link
Contributor Author

ferbar commented Mar 7, 2022

Intriguing addition. First time I've seen use of const after a function name. I'm a 'C' guy. Can you tell me what "const" does here? e.g. bool haveRSSI() const;

This is a good example of a const method:
https://www.cplusplus.com/reference/string/string/size/

That means that you are allowed to call this method even if the object is a const std::string. In case of bool haveRSSI() const; it means that BTAdvertisedDevice could be a const - object. In general are you using this for methods which do not modify the object.

@mrengineer7777
Copy link
Collaborator

That means that you are allowed to call this method even if the object is a const std::string

Ah, that makes sense. Thank you.

@me-no-dev me-no-dev added Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing labels Mar 10, 2022
@@ -50,6 +51,7 @@ class BluetoothSerial: public Stream
size_t write(const uint8_t *buffer, size_t size);
void flush();
void end(void);
void setTimeout(int timeoutMS);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to ask why the timeout should be set globally, and not for each peek or read call individually.

Copy link
Member

Choose a reason for hiding this comment

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

Because that is how it's done in Arduino for Streams

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2022

Unit Test Results

0 files  0 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0

Results for commit f43f196.

♻️ This comment has been updated with latest results.

@SuGlider
Copy link
Collaborator

SuGlider commented Apr 6, 2022

@ferbar - please check some errors when CI tries to compile it. Thanks.

https://github.com/espressif/arduino-esp32/runs/5856471430?check_suite_focus=true

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this test as well (it is in every SPP example in order to warn users that try to run it in any chip but ESP32).

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

@SuGlider
Copy link
Collaborator

SuGlider commented Apr 6, 2022

@ferbar - Thanks for this PR. It improves SPP functionality and API.
I'll try it as well, but in general it looks good to me.
As soon as the CI issues are fixed, and I finish testing it, we shall merge it.

please add also .skip.esp32s3 file to the examples folder. This shall solve the CI issue.

@SuGlider SuGlider self-assigned this Apr 6, 2022
@ferbar
Copy link
Contributor Author

ferbar commented Apr 8, 2022

@SuGlider may I ask you to start the CI. Thanks!

@VojtechBartoska
Copy link
Contributor

@ferbar started :)

@me-no-dev me-no-dev merged commit b88a70a into espressif:master Apr 26, 2022
Jason2866 added a commit to tasmota/arduino-esp32 that referenced this pull request Apr 26, 2022
* LittleFs is working with C3

* Delete .skip.esp32c3

* Add support for extra flash images (espressif#6625)

This PR adds support for uploading additional flash images (e.g. Adafruit Tiny UF2 bootloader) specified in board manifests.

Additionally, the PR switches the PlatformIO CI script to the upstream version of the ESP32 dev-platform (basically reverts changes introduced in espressif#5387 as they are no longer required).

* publish.yml: Remove a leftover parenthesis that was making the workflow (espressif#6620)

Description of Change

Remove a leftover parenthesis that was making the workflow that was making the workflow invalid.

Tests scenarios

Github Workflow.

Related links

https://github.com/espressif/arduino-esp32/actions/runs/2213167501

Signed-off-by: Abdelatif Guettouche <[email protected]>

* Enable LittleFs sketches for C3 (espressif#6618)

* LittleFs is working with C3

* Delete .skip.esp32c3

* Update LittleFS PlatformIO example (espressif#6617)

* Added RainMaker support on Arduino IDE for ESP32-C3/S2/S3 (espressif#6598)

* Added RainMaker support on Arduino IDE for ESP32-C3/S2/S3

Closes espressif#6573
Note related to the issue espressif#6435

* Touch change to init only selected GPIO. (espressif#6609)

* Separated init for touch / channel called by touchRead()

* compile error

* Fixed touch_V2 + ISR

* Allow BluetoothSerial::connect() with specified channel and more options (espressif#6380)

* BTAddress const, add bool()

* BTAdvertisedDevice: const functions

* BluetoothSerial: add: getChannels, add isClosed, add read/peek timeout, add connect with channel#

* BluetoothSerial: add sec_mask, role in ::connect

* BluetoothSerial add discover and connect with channel number example

* DiscoverConnect: add SPP_ENABLED check

* DiscoverConnect: disable on esp32s3

* Fixes stream load memory leak in WifiSecureClient for SSL CACert, Certificate, and (espressif#6387)

Private Key. Issue presented during any subsequent invocation of loadCACert, loadCertificate, and
loadPrivateKey, respectively, after the first invocation.

* Call i2c_set_timeout in i2cSetClock (espressif#6537)

* Uniform behaviour of WiFiClientSecure and WiFiClient setTimeout() (espressif#6562)

* Uniform timeout WiFiClient-WiFiClientSecure

* Added missing prototype

* Add socket check on setTimeout

* enh(log) salvage TAG from ESP_IDF log-statements > (espressif#6567)

by converting result log-rows from the 1st line to the 2nd (`NET` is the tag):
```
[ 73419][D][telelogger.cpp:915] telemetry(): state: 33C

[ 73419][D][telelogger.cpp:915] telemetry(): [NET] state: 33C
```

Co-authored-by: Me No Dev <[email protected]>

* add AirM2M_CORE_ESP32C3 board (espressif#6613)

* add AirM2M_CORE_ESP32C3 board

* Added Unexpected Maker Reflow Master Pro (UM RMP) board (espressif#6630)

Fixed wrong SCK and MISO pins for TinyS2

* Tasmota changes (#24)

* Update install-arduino-core-esp32.sh

* Update CMakeLists.txt

* Update Esp.cpp

* Update Updater.cpp

Co-authored-by: Valerii Koval <[email protected]>
Co-authored-by: Abdelatif Guettouche <[email protected]>
Co-authored-by: Pedro Minatel <[email protected]>
Co-authored-by: Jan Procházka <[email protected]>
Co-authored-by: Christian Ferbar <[email protected]>
Co-authored-by: Billy <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Gonzalo Brusco <[email protected]>
Co-authored-by: Kostis Anagnostopoulos <[email protected]>
Co-authored-by: Me No Dev <[email protected]>
Co-authored-by: Darren Cheng <[email protected]>
Co-authored-by: Unexpected Maker <[email protected]>
@ferbar
Copy link
Contributor Author

ferbar commented Apr 27, 2022

Thanks!

@cattledogGH
Copy link

Nice new example.

SerialBT.setPin("1234"); // doesn't seem to change anything
SerialBT.enableSSP(); // doesn't seem to change anything

Unfortunately, even with these lines uncommented, this new example does not solve the issue of failure to connect to a device with a pin like an HC-05 with pin "1234".

#6061

espressif/esp-idf#8394

Is there any update on when the underlying issue in IDF will be resolved?

@ferbar
Copy link
Contributor Author

ferbar commented May 7, 2022

@cattledogGH I'm sorry this PR is not related to esp32 => BT 2.0 device.

also see: #6193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Test needed Issue needs testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants