Code: Select all
#include <BluetoothSerial.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define BT_DISCOVER_TIME 10000
static bool btScanAsync = true;
static bool btScanSync = true;
void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) {
Serial.printf("Found a device asynchronously: %s\n", pDevice->toString().c_str());
}
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
if (btScanAsync) {
Serial.print("Starting discoverAsync...");
if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) {
Serial.println("Findings will be reported in \"btAdvertisedDeviceFound\"");
delay(10000);
Serial.print("Stopping discoverAsync... ");
SerialBT.discoverAsyncStop();
Serial.println("stopped");
} else {
Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
}
}
if (btScanSync) {
Serial.println("Starting discover...");
BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME);
if (pResults)
pResults->dump(&Serial);
else
Serial.println("Error on BT Scan, no result!");
}
}
void loop() {
delay(100);
}
Code: Select all
Arduino:1.8.15 (Windows 10), 开发板:"ESP32C3 Dev Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 160MHz (WiFi), QIO, 80MHz, 4MB (32Mb), 921600, None"
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `.L0 ':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:651: undefined reference to `esp_spp_deinit'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `_stop_bt':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:674: undefined reference to `esp_spp_disconnect'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `.LVL35':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:116: undefined reference to `esp_bt_gap_resolve_eir_data'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `get_name_from_eir':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:118: undefined reference to `esp_bt_gap_resolve_eir_data'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `.L0 ':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:177: undefined reference to `esp_spp_write'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:141: undefined reference to `esp_bt_gap_set_pin'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:595: undefined reference to `esp_bt_gap_register_callback'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `_init_bt':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:588: undefined reference to `esp_spp_register_callback'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:608: undefined reference to `esp_spp_init'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:625: undefined reference to `esp_bt_gap_set_cod'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:641: undefined reference to `esp_bt_gap_set_security_param'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `BluetoothSerial::disconnect()':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:907: undefined reference to `esp_spp_disconnect'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `BluetoothSerial::discover(int)':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:953: undefined reference to `esp_bt_gap_set_scan_mode'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:956: undefined reference to `esp_bt_gap_start_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:962: undefined reference to `esp_bt_gap_cancel_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `BluetoothSerial::discoverAsyncStop()':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:950: undefined reference to `esp_bt_gap_cancel_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `.LVL318':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:324: undefined reference to `esp_bt_gap_set_scan_mode'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `esp_spp_cb':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:259: undefined reference to `esp_spp_start_srv'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:271: undefined reference to `esp_spp_disconnect'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:339: undefined reference to `esp_spp_connect'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:350: undefined reference to `esp_spp_disconnect'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `std::_Function_base::~_Function_base()':
c:\users\lyon\appdata\local\arduino15\packages\esp32\tools\riscv32-esp-elf-gcc\gcc8_4_0-esp-2021r1\riscv32-esp-elf\include\c++\8.4.0\bits/std_function.h:256: undefined reference to `esp_bt_gap_set_scan_mode'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `BluetoothSerial::discoverAsync(std::function<void (BTAdvertisedDevice*)>, int)':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:981: undefined reference to `esp_bt_gap_start_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:983: undefined reference to `esp_bt_gap_start_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `.L0 ':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:413: undefined reference to `esp_bt_gap_cancel_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: libraries\BluetoothSerial\BluetoothSerial.cpp.o: in function `esp_bt_gap_cb':
C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:414: undefined reference to `esp_spp_start_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:397: undefined reference to `esp_bt_gap_cancel_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:397: undefined reference to `esp_spp_start_discovery'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:480: undefined reference to `esp_bt_gap_pin_reply'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:485: undefined reference to `esp_bt_gap_pin_reply'
c:/users/lyon/appdata/local/arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/gcc8_4_0-esp-2021r1/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: C:\Users\Lyon\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0-rc1\libraries\BluetoothSerial\src/BluetoothSerial.cpp:493: undefined reference to `esp_bt_gap_ssp_confirm_reply'
collect2.exe: error: ld returned 1 exit status
exit status 1
为开发板 ESP32C3 Dev Module 编译时出错。