Esp32 BlueTooth clasic - Some problems

Hi to all friends here.
i want to make an app to use it with my esp32 with Bluetooth

how my app supposed to work :
open the app , choose bluetooth device to connect, after connection you choose a number (1-4) , the app sends that number through Bluetooth to the arduino program, reads it and then the program depending the number sends the sensors values (if you choose 1 you receive values for the first only sensor, if you choose 2 then receiving for the first two sensors etc)

My first problem is that after i choose the number the esp32(program) receive it and doing what must do. The Android app stops there.. dont show the values . i have to close the app and run it again and after i connect to the Bluetooth device start showing them (with the other problem about " select list item: List index too Large " )

here is the arduino code :
esp32_Bt_mitapp.txt (6.1 KB)

and here is the aia :
Esp32_Bt_clasic_Rx_tx.aia (10.4 KB)

Some extra about arduino code :
i am using a loadcell with HX711 sensor , inside the sketch there is the link for the library. You can run the code with no need to have the loadcell or HX711 .
when the code runs for first time initialize the sensor for one time and then waits for incoming message (number). After the received number depending the number value check and report (via Bluetooth) the corresponding sensors

Here an example with ESP32 and Bluetooth classic.

You are failing to check list lengths after splitting the input messages at '|'.

You send a varying number of data per message:

...

  if (SerialBT.available()) {

    if (Sellection == 1) {
      SerialBT.print(cell01);
      SerialBT.println();
      delay(50);
    }

    if (Sellection == 2) {
      SerialBT.print(cell01);
      SerialBT.print("|");
      SerialBT.print(sensorValue_01);
      SerialBT.println();
      delay(50);
    }

    if (Sellection == 3) {
      SerialBT.print(cell01);
      SerialBT.print("|");
      SerialBT.print(sensorValue_01);
      SerialBT.print("|");
      SerialBT.print(sensorValue_02);
      SerialBT.println();
      delay(50);
    }

    if (Sellection == 4) {
      SerialBT.print(cell01);
      SerialBT.print("|");
      SerialBT.print(sensorValue_01);
      SerialBT.print("|");
      SerialBT.print(sensorValue_02);
      SerialBT.print("|");
      SerialBT.println(sensorValue_03);
      SerialBT.println();
      delay(50);
    }
  }
...

but you fail to check length of list after splitting:




Also, you have a delay procedure in AI2, which is inadvisable.
Leave all delays to the Clock Timer.

Thanks for the reply... so i have to check how to checl length of the lists after splitting..
will be my next google search after this post.. thanks for your guideness.

The delay function was embedded later trying to fix the problem that after sending the number to Esp32 didnt read the incoming data from esp32 unless if i was disconnected and connect again to the BlueTooth.

so i will remove the Delay Function from the blocks

Ok thanks to ABG i solved my problem with incoming data ( " select list item: List index too Large " )

here is my new app (added a close button also to disconnect the Bluetooth and close app) :

Esp32_Bt_clasic_Rx_tx(1).aia (10.4 KB)

still looking for help about my first problem.. (after send the number to Esp32 to do special routine based on the number) cant receive - display the incoming data from Esp32, i have to close app and then open it again in order to display the incoming data

Two recommendations:

  • If you receive data, make the corresponding Label Visible
  • Don't muddy your debugging trail.

Any further problems probably need study of your .ino.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See A way to group projects by theme - #10 by ABG
for a demo.