From 3e6460b82048a3f30444d7c6ea62a2b2cfee1350 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 25 Apr 2024 22:47:54 +0100 Subject: [PATCH] retries --- ESPBMS.ino | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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; }