BLE self disconnects after timeout

Hello all,

my first post here.
I'm trying to establish communication between my phone (Redmi note 11, Android 13) and an ESP32.
The issue I have is that the devices are disconnecting after timeout (whatever time I set). Below my blocks and my Arduino code.

Any idea how to solve?

Many thanks in advance
Antonio


#include <ArduinoBLE.h>

char* messaggio = {"1010010"}; 

const char * SERVICE_UUID =           "4fafc201-1fb5-459e-8fcc-c5c9c331914b";        
const char * CHARACTERISTIC_UUID_3 =  "beb5483e-36e1-4688-b7f5-ea07361b26a8";      // giorni accensione

BLEService pratoService(SERVICE_UUID);

BLEStringCharacteristic giorni_char(CHARACTERISTIC_UUID_3, BLEWrite|BLERead|BLENotify, 9);

void setup() {
  Serial.begin(9600);

  if(!BLE.begin()){
    Serial.println("avvio BLE non riuscito");
    while(1);
  }

  BLE.setDeviceName("Prato");
  BLE.setLocalName("Prato");

  pratoService.addCharacteristic(giorni_char);
  BLE.addService(pratoService);
  BLE.setAdvertisedService(pratoService);
  
  BLE.advertise();

  Serial.println("Waiting a client connection to notify...");
  delay(1000);
}

void loop() {

  BLEDevice central = BLE.central();

  if (central){
    Serial.println("connesso");
    
    while (central.connected()){
      giorni_char.writeValue(messaggio);
      delay(1000);
      Serial.println("loop");
      // }
    }
    
    Serial.println("disconnesso");
  }
}

I don't really understand Antonio - There is no timer in your Blocks nor the Sketch that I can see - do you mean the connection time-out in Properties? If so, it means that a connection is not made. Better to set that in the Blocks, so you can tell the User.

Also, your test always sends the string "1010010" and that value overwrites the content of the Label in the App, so you can't see any change.

Hi Chris,

yes, I mean in the timeout in the BLE extension properties.

immagine

however it seems the connection is realized, since for 10s both ESP and app say they are connected and I see in the Serial monitor the string "loop" repeating (with correct timestamp), but after 10s (or after the value I set in the properties) connection is dropped.

concerning sending string: I do not see it appearing even for the first time :)...but I was first focusing on a stable connection.

thank you

So you do get as far as selecting the device in the device list. However the App does not verify that a connection has been made, it just assumes it has. The device does not need to be connected to the App in order to print to the Serial Monitor.

Remove:
AfterPicking

Add:
connected

1 Like