Open benjasperson opened 7 months ago
void btDiscover() {
BTScanResults* pScanResults = SerialBT.discover(BT_DISCOVER_TIME);
if (pScanResults != nullptr && pScanResults->getCount() > 0) {
for (int i = 0; i < pScanResults->getCount(); i++) {
BTAdvertisedDevice* pDevice = pScanResults->getDevice(i);
if (pDevice != nullptr) {
String deviceName = pDevice->getName().c_str();
if (deviceName.startsWith(SLAVE_NAME_PATTERN)) {
delay(200); // memory overload
list.Add(deviceName);
}
}
}
}
}
works only in setup, it scans all available slaves and get the data from it via loop
for (int i = 0; i < list.Count(); i++) {
SerialBT.connect(list[i]); // list should changed to string array or char or so
//do some shit
}
its helpful maybe
Board
TTGO LoRa32-OLED
Device Description
NA
Hardware Configuration
NA
Version
v2.0.11
IDE Name
VS Code
Operating System
Windows 10
Flash frequency
80 MHz
PSRAM enabled
yes
Upload speed
921600
Description
Problem seems to be similar to https://github.com/espressif/arduino-esp32/issues/8448, but I don't see that the resolution solved anything (maybe it's actually a different issue). I cannot discover devices after successfully disconnecting. Discover fails because _isRemoteAdressSet is set to true. If however, I try to connect to a bad address (or just fail to connect to a valid address), I can scan again. The reason is because _isRemoteAddressSet is set to false after a failed connection attempt.
Workaround: Don't use disconnect. Instead, attempt connect to a false address, and when it fails, scan will work properly again.
Sketch
Debug Message
Other Steps to Reproduce
Load the sketch, connect to a Serial monitor (baud rate 115200) and send 's' to scan, 'p' to print discovered devices, '-'/'+' to change the selected device index, 'c' to connect, or 'd' to disconnect.
Notice that you can scan as many times as you would like before connecting, but after connecting, the only only way to scan again is by first getting a failed connection attempt.
I have checked existing issues, online documentation and the Troubleshooting Guide