BLE Connection isn't predictable

Hi Folks,

I was stress testing my BLE device with a mobile app I have built and the use case I was testing is continuous Connect/Disconnect the device.

After 4-5 times the Arduino Nano IoT 33 device and mobile app doesn't handle the disconnect signal well and the mobile app get's stuck waiting for device to be found again after disconnect.

Arduino code:

void loop() {
 
  // BLE handler
  // wait for a Bluetooth® Low Energy central
  BLEDevice central = BLE.central();

  // if a central is connected to the peripheral:
  if (central) {

    // turn on the LED to indicate the connection:
    digitalWrite(LED_BUILTIN, HIGH);
    tone(buzzer_pin, 450, 1000);

    // while the central is connected:
    while (central.connected()) {
     // My device logic
      }

    // when the central disconnects, turn off the LED:
    digitalWrite(LED_BUILTIN, LOW);
    tone(buzzer_pin, 250, 1000);
  }
}

I am using MIT app inventor to build my mobile app and have handled the following events

BLE.ConnectWithAddress
BLE.Connected
BLE.ConnectionFailed
BLE.Disconnect
BLE.Disconnected

App Inventor code:

Can you show more blocks? How is "deviceaddress" designed?

The device address is the mac address of BLE device. Just use Arduino serial to print of even print through App Inventor display options.