Make two events to receive diferents datas (Esp32 + BT+ App inventor)

Hey guys!
I would like to make a code to receive and execute two different data from the bluetooth connection, but I can use an event. How can I work?
Follow code:

#include "BluetoothSerial.h"

//#define DEBUG_ESP_CORE_DISABLE_COREDUMP_TO_SERIAL

BluetoothSerial SerialBT;

#define botao1 14

#define led1 23

void setup() {

Serial.begin(115200);

initBT();

pinMode(botao1, INPUT);

pinMode(led1, OUTPUT);

}

void initBT(){

if(!SerialBT.begin("ESP32_0")){

Serial.println("Um erro aconteceu com dispositivo Bluetooth");

ESP.restart();

}else{

Serial.println("Bluetooth inicializado");

}

SerialBT.register_callback(btCallback);

Serial.println("Dispositivo iniciado, pode parear");

}

void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){

if(event == ESP_SPP_SRV_OPEN_EVT){

Serial.println("Cliente conectado!");

}else if(event == ESP_SPP_DATA_IND_EVT){

while(SerialBT.available()){

  String received = SerialBT.readStringUntil('\n');

  Serial.println(received);

  SerialBT.println(received); // Return

  processReceivedData(received); // Chama a função para processar os dados recebidos

}

}

}

void processReceivedData(String data){

// Realize as rotinas de teste com os dados recebidos

if(digitalRead(botao1) == HIGH) { // Verificar se o botão foi pressionado

    digitalWrite(led1, HIGH); // Ligar o led1

    Serial.println("Aprovado "+ data);

}

else if(digitalRead(botao1) == LOW){

    digitalWrite(led1, LOW); // Ligar o led1

    Serial.println("Reprovado "+ data);

}

// ... outras rotinas de teste aqui

}

void loop() {

}

I think this part of your code should be inside the Loop:

while(SerialBT.available()){

  String received = SerialBT.readStringUntil('\n');

  Serial.println(received);

  SerialBT.println(received); // Return

  processReceivedData(received); // Chama a função para processar os dados recebidos

}

I don't understand why you need two events to receive different data. Please tell us what the data is and the data type. In your code, you receive a string 'received', are both items of data strings?

Here an example

An event will receive the barcode and another event will receive a string and call a function.

The data can be received by one and passed to the relevant function. Just prefix each item of data with a character or number that will be read first to discern.

I modified the code to work in this way:

#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#define botao1 14
#define led1 23
void setup() {
Serial.begin(115200);
initBT();
pinMode(botao1, INPUT);
pinMode(led1, OUTPUT);
}
void initBT(){
if(!SerialBT.begin("ESP32_0")){
Serial.println("Um erro aconteceu com dispositivo Bluetooth");
ESP.restart();
}else{
Serial.println("Bluetooth inicializado");
}
SerialBT.register_callback(btCallback);
Serial.println("Dispositivo iniciado, pode parear");
}
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){
if(event == ESP_SPP_SRV_OPEN_EVT){
Serial.println("Cliente conectado!");
}else if(event == ESP_SPP_DATA_IND_EVT){
while(SerialBT.available()){
String received = SerialBT.readStringUntil('\n');
Serial.println(received);
//SerialBT.println(received); // Return
if(digitalRead(botao1) == HIGH) { // Verificar se o botão foi pressionado
digitalWrite(led1, HIGH); // Ligar o led1
Serial.println("Aprovado "+ received);
SerialBT.println("Aprovado"); // Return
}
else{
digitalWrite(led1, LOW); // Ligar o led1
Serial.println("Reprovado "+ received);
SerialBT.println("Reprovado"); // Return
}
}
// ... outras rotinas de teste aqui
}
}
void loop() {
}
Now I will to make the blocs.
I'll get back to you if it worked.

#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#define botao1 14
#define led1 23
char z; // variável global
void setup() {
Serial.begin(115200);
initBT();
pinMode(botao1, INPUT);
pinMode(led1, OUTPUT);
}
void initBT(){
if(!SerialBT.begin("ESP32_0")){
Serial.println("Um erro aconteceu com dispositivo Bluetooth");
ESP.restart();
}else{
Serial.println("Bluetooth inicializado");
}
SerialBT.register_callback(btCallback);
Serial.println("Dispositivo iniciado, pode parear");
}
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){
if(event == ESP_SPP_SRV_OPEN_EVT){
Serial.println("Cliente conectado!");
}else if(event == ESP_SPP_DATA_IND_EVT){
while(SerialBT.available()){
String received = SerialBT.readStringUntil('\n');
Serial.println(received);
//SerialBT.println(received); // Return
if(digitalRead(botao1) == HIGH) { // Verificar se o botão foi pressionado
digitalWrite(led1, HIGH); // Ligar o led1
Serial.println("Aprovado "+ received);
}
else{
digitalWrite(led1, LOW); // Ligar o led1
Serial.println("Reprovado "+ received);
if (z=='A'){SerialBT.println("Aprovado");} // Return
else {SerialBT.println("Reprovado");} // Return
}
}
}
// ... outras rotinas de teste aqui
}
void loop() {
if (SerialBT.available()) {
z = SerialBT.read();
}
}

didn't work as expected ;[
In the first one, the button should read the barcode and then run a test with the button and show it passed or failed on the serial monitor. Right after, clicking on "Submit" would show the approved message in the application.
But the application is not showing the result.