retries
This commit is contained in:
parent
14bd3f1da8
commit
3e6460b820
16
ESPBMS.ino
16
ESPBMS.ino
@ -48,8 +48,20 @@ void loop() {
|
|||||||
BLEClient* pClient = BLEDevice::createClient();
|
BLEClient* pClient = BLEDevice::createClient();
|
||||||
Serial.println("Connecting to: " + String(advertisedDevice.getName().c_str()));
|
Serial.println("Connecting to: " + String(advertisedDevice.getName().c_str()));
|
||||||
|
|
||||||
if(!pClient->connect(&advertisedDevice)) {
|
int retryCount = 0;
|
||||||
Serial.println("Failed to connect.");
|
const int maxRetries = 5; // Maximum number of retries
|
||||||
|
while(retryCount < maxRetries) {
|
||||||
|
if(pClient->connect(&advertisedDevice)) {
|
||||||
|
Serial.println("Connected successfully.");
|
||||||
|
break; // Exit the loop if the connection is successful
|
||||||
|
} else {
|
||||||
|
Serial.println("Failed to connect. Retrying...");
|
||||||
|
retryCount++; // Increment the retry counter
|
||||||
|
delay(1000); // Optional: Wait for a second before retrying
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(retryCount == maxRetries) {
|
||||||
|
Serial.println("Failed to connect after retries.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user