-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
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.
@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.
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.
LGTM!
* @return The string representation of the address. | ||
*/ | ||
std::string BTAddress::toString() const { | ||
std::string BTAddress::toString(bool capital) const { |
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.
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() { |
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.
Same here std::string
=>> String
@@ -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(); |
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.
you forgot to change the type here
@@ -24,12 +24,12 @@ class BTAddress { | |||
public: |
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.
up in the includes, you need to change #include <string>
to #include "Arduino.h"
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.
Change include and left over std::string
in BluetoothSerial.h
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
BluetoothSerial
method that would facilitate this.This PR adds three new methods, slightly extends the
BTAddress::toString
, and adds a new exampleGetLocalMAC
which demonstrates the usage of the new additions.