Repository navigation
Device Discovery
When you start the A2DP Source, it searches for Bluetooth devices that provide an audio service and connects to the device you have selected.
a2dp_source.start("MyMusic");You can also indicate multiple alternative names. The source connects to the first one that is available:
static std::vector<const char*> bt_names = {"MyMusic", "RadioPlayer", "MusicPlayer"};
a2dp_source.start(bt_names);A device matches if its name starts with the indicated name.
If you call start() without any names, you can decide yourself with the ssid callback: it is called for each device that has been found. Return true to connect, or false to continue scanning. You can also use this to build a list of the available devices.
bool isValid(const char* ssid, esp_bd_addr_t address, int rssi) {
Serial.print("available SSID: ");
Serial.println(ssid);
return strcmp(ssid, "MyMusic") == 0;
}
void setup() {
Serial.begin(115200);
a2dp_source.set_ssid_callback(isValid);
a2dp_source.set_data_callback_in_frames(get_data_frames);
a2dp_source.start();
}See the bt_music_sender_ssid_callback example.
Only devices whose class of device indicates an audio service are considered. By default these are ESP_BT_COD_SRVC_RENDERING | ESP_BT_COD_SRVC_AUDIO | ESP_BT_COD_SRVC_TELEPHONY. You can change this filter with set_valid_cod_service().
-
set_discovery_mode_callback(): is called when the discovery starts or stops -
is_discovery_active(): returns true while the discovery is running -
cancel_discovery(): stops the discovery
-
set_local_name(): the name of the ESP32 that is shown on the sink -
set_pin_code()andset_ssp_enabled(): pairing, see Access Protection - Reconnecting to the last device: see Auto Reconnect
Getting Started
A2DP Sink (Receiver)
- Overview & Examples
- Audio Output & DACs
- Sample Rate
- Volume Control
- AVRC: Controlling your Phone
- Metadata & Notifications
- Performance Optimizations
A2DP Source (Sender)
Common
Background
Help