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

Added methods + example to retrive local MAC for BT #7778

Merged
merged 7 commits into from
Feb 13, 2023

Conversation

PilnyTomas
Copy link
Contributor

It was not easy or obvious how to retrieve a MAC address of a local BT device.
There is an IDF function esp_bt_dev_get_address which accomplishes that and is used in this solution.
However, there was no BluetoothSerialmethod that would facilitate this.
This PR adds three new methods, slightly extends the BTAddress::toString, and adds a new example GetLocalMAC which demonstrates the usage of the new additions.

@PilnyTomas PilnyTomas added the Area: BT&Wifi BT & Wifi related issues label Jan 31, 2023
@PilnyTomas PilnyTomas requested a review from SuGlider January 31, 2023 13:18
@PilnyTomas PilnyTomas self-assigned this Jan 31, 2023
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

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

@PilnyTomas please check my comments (typo and format issues), example is working great! Thank for the PR. After fixes it will be ready to merge.

libraries/BluetoothSerial/src/BTAddress.cpp Outdated Show resolved Hide resolved
libraries/BluetoothSerial/src/BTAddress.cpp Outdated Show resolved Hide resolved
libraries/BluetoothSerial/src/BluetoothSerial.cpp Outdated Show resolved Hide resolved
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

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

LGTM!

@VojtechBartoska VojtechBartoska added this to the 2.0.7 milestone Feb 1, 2023
* @return The string representation of the address.
*/
std::string BTAddress::toString() const {
std::string BTAddress::toString(bool capital) const {
Copy link
Member

Choose a reason for hiding this comment

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

I see that originally the method returns std::string, but please change it to Arduino String instead.

*
* @return The BT MAC address string.
*/
std::string BluetoothSerial::getBtAddressString() {
Copy link
Member

Choose a reason for hiding this comment

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

Same here std::string =>> String

@VojtechBartoska VojtechBartoska added the Type: Example Issue is related to specific example. label Feb 6, 2023
@PilnyTomas PilnyTomas requested a review from me-no-dev February 8, 2023 13:10
@@ -85,6 +85,9 @@ class BluetoothSerial: public Stream
const int MAX_INQ_TIME = (ESP_BT_GAP_MAX_INQ_LEN * INQ_TIME);

operator bool() const;
void getBtAddress(uint8_t *mac);
BTAddress getBtAddressObject();
std::string getBtAddressString();
Copy link
Member

Choose a reason for hiding this comment

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

you forgot to change the type here

@@ -24,12 +24,12 @@ class BTAddress {
public:
Copy link
Member

Choose a reason for hiding this comment

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

up in the includes, you need to change #include <string> to #include "Arduino.h"

Copy link
Member

@me-no-dev me-no-dev left a comment

Choose a reason for hiding this comment

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

Change include and left over std::string in BluetoothSerial.h

@PilnyTomas PilnyTomas requested a review from me-no-dev February 11, 2023 11:56
@me-no-dev me-no-dev merged commit 2ddce3c into espressif:master Feb 13, 2023
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 Type: Example Issue is related to specific example.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants