Ajuda para solucionar erro na leitura de informações pelo Bluetooth

Esse é meu primeiro APP no MIT App Inventor e estou com dificuldades de identificar a origem do problema.

Estou enviando informações através do Bluetooth do ESP32 para o APP, são 3 parametros separados por "|"

SerialBT.print(F("RPM|"));
SerialBT.print(infoRPM);
delay(50);
SerialBT.print(F("BAT|"));
SerialBT.print(infoBAT);
delay(50);
SerialBT.print(F("MAP|"));
SerialBT.print(infoMAP);
delay(50);

Mas no app aparece erro e as vezes ele mostra a variável no label.



20220311_132033

Hello Maiko

You have done quiet well but a few errors:

  1. Sketch - do not send Labels, just the data;
  2. Sketch - do not use delay() between values;
  3. Sketch - last line should be SerialBT.println() - tells App "end of data".
  4. Ensure the time interval of the Sketch Loop is reasonable - and experiment with the time interval, starting with, say, 5 seconds and tweaking down if necessary (but note, the human eye cannot tolerate super-fast value changes).
  5. App: On Screen Initialisation, set the BT DelimiterByte to 10
  6. App: "BytesAvaliableToReceive" is a flag to indicate availability, not quantity. Replace with -1 (Receive All Bytes)

Here is a basic template which you can use as-is or plunder for your own Project :grin:

BT_Basic_Setup_ReceiveMulti.aia (8.4 KB)

Example Sketch:

//ArduinoToApp.ino  02/03/2021 02:38:48

//Fake data stream to demo elapased milliseconds timing


//vars
unsigned long lgUpdateTime;

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

void loop()
{
	           if(millis() - lgUpdateTime > 5000)           //Loop approx every 5 seconds
               {
                         lgUpdateTime = millis();

                         if (Serial.connected())
                         {
                                   //Bluetooth to App
                                   Serial.print("Hello");
                                   Serial.print("|");      //Value delimiter
                                   Serial.print("World");
                                   Serial.print("|");
                                   Serial.println();        //This last line tells App "End of Data" = Ascii LineFeed Char Number 10
                         }
               }
}

Note that the Clock Timer interval in the App should be approx 20% faster than the Time Interval of the Sketch Loop.

2 Likes

Dear ChrisWard, thank you very much for your great help.

I'll take a look at this code, but I've managed to get a better idea of ​​how it works.

I'll post news soon.

I am very grateful for your quick help.

Hugs from Brazil.
TKS.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.