Error message always popup(Error 515 : not connected to a bluetooth device) even have connected to BT device

hello, can someone help me? I have connected to bluetooth and it is connected. but error keep showed up. after that, I have change my block and set the receive text equal to -1, but the the data from bluetooth cannot be send to mit app. im using RFID and bluetooth. when bluetooth is available, i have to scan the card. and the bluetooth will print my card id at mit apps. here i attach aia files and coding.

#include "SPI.h"
#include "MFRC522.h"
#define SS_PIN 10
#define RST_PIN 9
String command;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  mySerial.begin(9600);
  //mySerial.println("RFID door lock and bluetooth control");//
}
void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }
  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != 5 ? ":" : "");
  }
  strID.toUpperCase();
  Serial.print("Tap card key: ");
  Serial.println(strID);
  delay(1000);
  //*****************************************************************************
  if (strID.indexOf("79:2C:F5:B3") >= 0) {
    mySerial.println("Shopping ID:Shikin123");//
    return;
  }
  //*****************************************************************************
  //*****************************************************************************

  else {

    return;
  }

}

Smartshopping.aia (11.7 KB)

I see you set Delimter = 10 in the Designer (good).

This is the standard advice for receiving complete messages, and some blocks:


global message
(draggable)

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. 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.