diff --git a/ESPBMS.ino b/ESPBMS.ino index 0c99c2e..302164b 100644 --- a/ESPBMS.ino +++ b/ESPBMS.ino @@ -48,8 +48,20 @@ void loop() { BLEClient* pClient = BLEDevice::createClient(); Serial.println("Connecting to: " + String(advertisedDevice.getName().c_str())); - if(!pClient->connect(&advertisedDevice)) { - Serial.println("Failed to connect."); + int retryCount = 0; + 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; }