bluetooth signal detection

Hey,
I am trying to detect bluetooth connection by sending signals from bt to arduino.
Every 500ms i send '8' to arduino from app,(tested, it works) that is supposed to increase the cas(time) and delaying the condition coming true.
value by 500(ms)...
I want to print "stop" after 1 sec after the connection is lost( no more increasing the cas value)
However, after some time it prints the "stop" even if i dont disconnect bluetooth and it is sending signals...It happens about after 1 minute in program.
If i disconnect bt while the program is working as it should, it prints stops but not after 1 second...

I would be really grateful for any help with this because i cant figure this out. Thanks

unsigned long cas = 0;
int interval = 1000;
int data = 0;

void setup() {
Serial.begin(9600);
cas = millis();
}

void loop() {
  
if (Serial.available()> 0){
  data = Serial.read();
  
}

if (data == '8'){
  cas += 500;
  data = 0;
}

if ( millis() > (cas + interval)){
  Serial.println("stop");
}

Serial.println(cas); 

}

i think that if you want to recognize the lack of a “heartbeat”, you need to update a timestamp each time you receive a heartbeat or any other data that may be appropriate. instead of incrementing cas, set cas to millis().

If you want an answer to your question you will need to provide some information.

How does your hardware look like (which Arduino, what Bluetooth hardware, how are they connected)?

Please provide links to the description and datasheets for all non-Arduino modules

What library are you using?

Often it is also useful to describe what you want to achieve from an applications point of view and why. This helps offering alternative approaches to a problem.

gcjr:
i think that if you want to recognize the lack of a "heartbeat", you need to update a timestamp each time you receive a heartbeat or any other data that may be appropriate. instead of incrementing cas, set cas to millis().

It works now. Thank you!