ESP-32 disconnects from BLE device after 5 seconds

Hello!
I am trying to read data from a BLE device using an ESP-32. It works in my setup function and about 5 seconds of loop. After 5 seconds, though, it disconnects and starts displaying false values.
I have this in void setup:

char* deviceMacAddress1 = "C4:7C:8D:67:6A:23";
BLEAddress floraAddress1(deviceMacAddress1);
BLEClient* floraClient1 = getFloraClient(floraAddress1);
BLERemoteService* floraService1 = getFloraService(floraClient1);

This is the loop:

void loop() {
  delay(100);

if(floraClient1->isConnected()) Serial.println("Connected to BLE");
 else Serial.println("Disconnected from BLE"); 
  Serial.println("The temperature is: ");
  Serial.println(readFloraTemperature(floraService1));
}

To connect to a client and to get a service I need these getFloraClient() and getFloraService():

BLEClient* getFloraClient(BLEAddress floraAddress) 
  BLEClient* floraClient = BLEDevice::createClient();
  if (!floraClient->connect(floraAddress)) {
    Serial.println("- Connection failed, skipping");
    return nullptr;
  }
  Serial.println("- Connection successful");
  return floraClient;
}[
BLERemoteService* getFloraService(BLEClient* floraClient) {
  BLERemoteService* floraService = nullptr;

  try {
    floraService = floraClient->getService(serviceUUID);
  }
  catch (...) {
    // something went wrong
  }
  if (floraService == nullptr) {
    Serial.println("- Failed to find data service");
  }
  else {
    Serial.println("- Found data service");
  }
  return floraService;
}

And finally, here is my readFloraTemperature() function:

int readFloraTemperature(BLERemoteService* floraService) {
  BLERemoteCharacteristic* floraCharacteristic = nullptr;

  // get the main device data characteristic
  try {
    floraCharacteristic = floraService->getCharacteristic(uuid_sensor_data);
  }
  catch (...) {
    // something went wrong
  }
  if (floraCharacteristic == nullptr) {
    return 200;// false;
  }

  // read characteristic value
  std::string value;
  try{
    value = floraCharacteristic->readValue();
  }
  catch (...) {
    // something went wrong
 
    return 200;// false;
  }
  const char *val = value.c_str();

  int16_t* temp_raw = (int16_t*)val;
  float temperature = (*temp_raw) / ((float)10.0);
  return temperature;
}

What could be the solution to this problem?

try increasing the delay(100) to delay(5000) to see if there is a change in behavior

in the example you copied from, they added a test for incoherent data

 if (temperature > 200 || temperature < -30 || conductivity > 2000) {
Serial.println("-- Unreasonable values received, skip publish +++++++++++++++++++++++++++++");
return false;
}

without much reasonable explanations on why that would occur

J-M-L:
try increasing the delay(100) to delay(5000) to see if there is a change in behavior

in the example you copied from, they added a test for incoherent data

 if (temperature > 200 || temperature < -30 || conductivity > 2000) {

Serial.println("-- Unreasonable values received, skip publish +++++++++++++++++++++++++++++");
return false;
}



without much reasonable explanations on why that would occur

Thank you for the response! When I change the delay from 100 to 5000, the second value that is returned is wrong and the device is disconnected. I have also tried using their function without changing anything, but it also disconnects after 5 seconds. They call their readFloraDataCharacteristic function only in setup and it works there for me, as well.

are you very close to the device?

can you check with a BT reader from your smartphone if you see the relevant characteristic / Service?

J-M-L:
are you very close to the device?

can you check with a BT reader from your smartphone if you see the relevant characteristic / Service?

Yes, I am close to the device. My smartphone reads the data well. My ESP-32 also does when I reboot it or reenter the setup.

I don't have the way to reproduce unfortunately. Seems in the example they are getting bogus data from time to time, so that might indicate a bogus subsystem...

J-M-L:
I don't have the way to reproduce unfortunately. Seems in the example they are getting bogus data from time to time, so that might indicate a bogus subsystem...

Ok. Thank you for the help.

It happens because Flora disconnects after 5 seconds. I've checked the disconnection reason and it says: Disconnect reason: 19. The smartphone confirms it.