-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ba4180
Added methods + example to retrive local MAC for BT
PilnyTomas c6f8658
Added .skip files in the new example folder
PilnyTomas a9d1219
Fixed typos and formatting + added doxygen comments
PilnyTomas 51c34aa
changed std::string to String
PilnyTomas 7268d13
another std::string -> String
PilnyTomas f186d67
Changed std::string to String
PilnyTomas a9ba46a
chaged string type in example
PilnyTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
46 changes: 46 additions & 0 deletions
46
libraries/BluetoothSerial/examples/GetLocalMAC/GetLocalMAC.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This example demonstrates usage of BluetoothSerial method to retrieve MAC address of local BT device in various formats. | ||
// By Tomas Pilny - 2023 | ||
|
||
#include "BluetoothSerial.h" | ||
|
||
String device_name = "ESP32-example"; | ||
|
||
#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; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
SerialBT.begin(device_name); //Bluetooth device name | ||
|
||
uint8_t mac_arr[6]; // Byte array to hold the MAC address from getBtAddress() | ||
BTAddress mac_obj; // Object holding instance of BTAddress with the MAC (for more details see libraries/BluetoothSerial/src/BTAddress.h) | ||
String mac_str; // String holding the text version of MAC in format AA:BB:CC:DD:EE:FF | ||
|
||
SerialBT.getBtAddress(mac_arr); // Fill in the array | ||
mac_obj = SerialBT.getBtAddressObject(); // Instantiate the object | ||
mac_str = SerialBT.getBtAddressString(); // Copy the string | ||
|
||
Serial.print("This device is instantiated with name "); Serial.println(device_name); | ||
|
||
Serial.print("The mac address using byte array: "); | ||
for(int i = 0; i < ESP_BD_ADDR_LEN-1; i++){ | ||
Serial.print(mac_arr[i], HEX); Serial.print(":"); | ||
} | ||
Serial.println(mac_arr[ESP_BD_ADDR_LEN-1], HEX); | ||
|
||
Serial.print("The mac address using BTAddress object using default method `toString()`: "); Serial.println(mac_obj.toString().c_str()); | ||
Serial.print("The mac address using BTAddress object using method `toString(true)`\n\twhich prints the MAC with capital letters: "); Serial.println(mac_obj.toString(true).c_str()); // This actually what is used inside the getBtAddressString() | ||
|
||
Serial.print("The mac address using string: "); Serial.println(mac_str.c_str()); | ||
} | ||
|
||
void loop(){ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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"