How do I send values to the app invento

Hello guys, I am facing trouble with the ECG bluetooth app inventor.
the app can connect with the bluetooth but it cannot receive the values measured from the arduino monitor. Is my code incorrect or the block is..?
Thank you.

--------------------------------------------------------------------------------------------------------------This is my code:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(0, 1);
const int ECG_PIN = A0; // Ad8232 출력 핀
const int THRESHOLD = 400; // 피크 감지 임계값(필요시 조정)

unsigned long lastBeatTime = 0;
unsigned long currentTime;
int heartRate = 0;
int heartRateSum = 0;
const int numReadings = 10;
int readings[numReadings];
int readIndex = 0;

const int MAX_TIME = 2000; // 최대 심박수 감지 시간 간격
const int MIN_BEAT_INTERVAL = 300; // 최소 심박수 간격

bool debounce = false;

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  pinMode(10, INPUT);
  pinMode(11, INPUT);

  // readings 배열 초기화
  for (int i = 0; i < numReadings; i++) {
    readings[i] = 0;
  }
}

void loop() {
  currentTime = millis();
  // 블루투스 시리얼 데이터 처리
  if (BTSerial.available()) {
    char received = BTSerial.read();
    Serial.print("Received: ");
    Serial.println(received);
  }

  // 핀 10과 11 읽기
  if (digitalRead(10) == HIGH || digitalRead(11) == HIGH) {
    Serial.println("!");
  } else {
    int ecgValue = analogRead(ECG_PIN); // ECG 값 읽기
    Serial.print("ECG Value: ");
    Serial.println(ecgValue); // ECG 값 출력

    if(ecgValue > THRESHOLD && !debounce) {
      unsigned long beatInterval = currentTime - lastBeatTime;
      if(beatInterval > MIN_BEAT_INTERVAL) {
        lastBeatTime = currentTime;

        heartRate = 60000 / beatInterval;

        // 이동 평균 계산
        heartRateSum -= readings[readIndex];
        readings[readIndex] = heartRate;
        heartRateSum += readings[readIndex];
        readIndex = (readIndex + 1) % numReadings;

        int averageHeartRate = heartRateSum / numReadings;
        
        Serial.print("심박수: ");
        Serial.println(averageHeartRate);

        // 심박수를 블루투스로 전송
      
        BTSerial.print(averageHeartRate);

        // 디바운싱 활성화
        debounce = true;
      } else {
        Serial.println("심박 감지됨, 하지만 너무 빠름");
      }
    }

    // 디바운싱 해제 (500ms 후)
    if (debounce && (currentTime - lastBeatTime > 500)) {
      debounce = false;
    }

    if (currentTime - lastBeatTime > MAX_TIME) {
      heartRate = 0; // 심박수 0으로 설정 (비정상적인 긴 간격)
      Serial.println("2초 이상 심박수 감지가 안됩니다. reset 해주세요.");
      lastBeatTime = currentTime; // 추가: 간격이 너무 길면 타이머 리셋
    }
  }

  delay(100); // 블루투스 데이터 수신 체크 주기
}

arduino_newnew_copy_copy_copy_copy (1).aia (157.4 KB)

I see by your Clock Timer you are not using Delimiters to grab complete messages from BlueTooth.

Also, you are not assembling them into lists to feed any type of graph.

Here is the part to receive one number at a time:

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.