Description
Board
ESP32 Dev Module
Device Description
nothing
Hardware Configuration
only BT-connection
Version
2.0.10
IDE Name
Arduino IDE
Operating System
Win 10
Flash frequency
80Mhz
PSRAM enabled
yes
Upload speed
115200
Description
in my loop(): I want to discover() available clients. after that, i want to connect() to them and after that i want to repeat this.
If I use the discover()-part only, it shows all available clients, works as expected....
If i use connect("DEVICE_NAME") only, it works perfectly. Also with multiple clients....
If I use both, the discover()-function works on the first pass, but after connect(DEVICE_NAME), the discover()-function is broken... (I don't get any "active" devices anymore) so I tried so many different approaches, but I didn't find a solution....
If I put the discover()-part in setup(), everything works fine, but i want to update the list of active clients, so i put this part in loop().
a connect() after discover() will stop discover()!?!
Sketch
// BT
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
BluetoothSerial SerialBT2; // this was only a desperate test...
#include "ListLib.h"
List<String> list;
#define BT_DISCOVER_TIME 10000
void setup() {
Serial.begin(9600);
}
void loop() {
SerialBT.begin("MASTER", true); // normally in setup(), i know...
SerialBT.discover(BT_DISCOVER_TIME);
BTScanResults* pScanResults = SerialBT.getScanResults();
Serial.println(pScanResults->getCount());
for (int i = 0; i < pScanResults->getCount(); i++) {
BTAdvertisedDevice* pDevice = pScanResults->getDevice(i);
String deviceName = pDevice->getName().c_str();
if (deviceName.startsWith("SLAVE")) {
delay(200);
list.Add(deviceName);
Serial.println(list[i]);
}
}
SerialBT.discoverClear();
SerialBT.disconnect();
SerialBT.end();
SerialBT2.begin("MASTER", true);
for (int i = 0; i < list.Count(); i++) {
SerialBT2.connect(list[i]);
SerialBT2.println("REQUEST");
delay(200);
Serial.println(SerialBT2.readStringUntil('\n'));
SerialBT2.disconnect();
}
SerialBT2.end();
list.Clear();
}
Debug Message
none? ;/
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
edit: for now, i have moved the discover part to setup() and every 30minutes the esp is restarted... it's not the best approach, but it works... conclusion: discover and connect do not work together