BLE ESP32. Bluetooth. Send. Receive. Arduino IDE. Multitouch

Try this:

    int aleatorio_1 = random(1,100); // Crea el numero random.
	int aleatorio_2 = random(100,200); // Crea el numero random.
	int aleatorio_3 = random(200,300); // Crea el numero random.
	
    String alea = (String) aleatorio_1 + "," + (String) aleatorio_2 + "," + (String) aleatorio_3; // Lo convierte en String.
    pCharacteristic->setValue(alea.c_str()); // Pone el numero random
    pCharacteristic->notify();

Hi Juan,

I am trying to send audio files from phone to sd card connected on esp32 board via its BT/BLE. Can you please help.

This tutorial is about send/receive image Android/Arduino by BT.

ESP32 works with Bluetooth classic and BLE, try with Bluetoot classic first.
Use small files to try.

Heey i followed the guide to send and receive data but i get this error everytime i run companion.

Error from Companion: java.lang.NoClassDefFoundError: edu.mit.appinventor.ble.BluetoothLEint$1

Then i get this when i press enable BT
invoke: no method named `EnableBluetooth' in class java.lang.Boolean

and goes like that .
Seems its the extensions causing it , i know for sure bluetoothLE is causing me issues cuz i can run the app without it ,but i need the extensions to read and send sensor data .
any ideas what this could be ?

Check that you are using the current version of the Companion, 2.60 or 2.60u
If that's not the problem, export and post your .aia file here.


Please export your project and post it here.

Hey ABG you can find my original post here , Ai2 application has stopped

Hello Juan Antonio,
Thanks for your tutos and developpments.
Completely new with ESP and Mit app Inventor, you gave me the possibility to develop what I needed based on your sketches ( 10.- From App ON/OFF 3 LEDs. Get status of the LEDs.) ie. a remote base with 5 relays and specifically a BLE remote to control 2 relays for an E Scooter. (ON OFF Motor / ON OFF Lights).
Since I need to connect to 4 different EScooter (separately) i registered all 4 x 2 UUIDS and after list picking (with device Name) the connection is done displaying also a picture of each E Scoot model.
Also I get connection infos from the ESP as a returned string to make sure that the order is taken into consideration (instead of displaying from the app when sending ON OFF (A0 A1, B0 , B1,....) "commands.

Hereby the Esp & App Inventor Sketches
Again thank you so much.

I also facing a small difficulty (where I mostly find similar questions on the net) that is proper disconnection from the app with the ESP and its re-connection. For exemple I connect to 1 scooter and change my mind to disconnect and connect to another one to check it and come back to the 1st one the connection is quite tough (even if disconnected on the app with BLE disconect, Disconnect with adress or both. Even with a "reboot" from the ESP (ON OFF). So far I have seen accordingly to several same issue on the net, the solution might be as per your description

""
bool deviceConnected = false;
bool oldDeviceConnected = false;
//uint32_t value = 0;

#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};

void onDisconnect(BLEServer* pServer) {
  deviceConnected = false;
}

};

////////////////////// WriteStrings /////////////////////////////
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();

  if (value.length() > 0) {
    valor = "";
    for (int i = 0; i < value.length(); i++){
      // Serial.print(value[i]); // Presenta value.
      valor = valor + value[i];
    }

    Serial.println("*********");
    Serial.print("valor = ");
    Serial.println(valor); // Presenta valor.
  }
}

};
But.....I have no clue how to implement it with your APP dvlpment 10- ON/OFF 3 Leds with Led status.

If you can help, I would appreciate.
In case not I 'll continue looking around and testing.
In any case thank You for your publications and the way you are helping readers.
It is very helpfull.

Best Regards,
Jean-Luc
Trot1.aia (3.5 MB)
ESP32.pdf (10.8 KB)

Thanks for this relevant informations. What about Firmware OTA Bluetooth? I found for WiFi but I'm still looking for AI2 Bluetooth method. Any cue?

Regards

Martin

I have only used OTA with WiFi, not with BLE.

Try https://learn.sparkfun.com/tutorials/esp32-ota-updates-over-ble-from-a-react-web-application/all

Hola Antonio,

Estoy tratando de hacer funcionar este ejemplo, con algunas modificaciones para lo que necesito. Estoy leyendo un pin nalógico del esp32 en el main loop mediante una interrupción. Estos valores los voy guardando en un array de 500 y después los imprimo en pantalla con un for, fuera de la interrupción.

El problema es que quiero enviar esos datos uno a uno a mit app inventor por BLE, y no logro que le lleguen los datos. Si pongo el pCharacteristic->setValue en ese for dentro del main loop, me salta un error, y necesito declarar pCharacteristic como global. Pero si hago eso, no funciona.

Y si paso todo el código de la interrupción/lectura a la clase Callbacks, no funciona la interrupción.

Dejo acceso al código: https://create.arduino.cc/editor/mvblanco/29bc59b8-e59b-479f-8487-5a4af2bcd5bf/preview

Si pudieras darme una idea sobre cómo seguir, me ayudaría mucho.
Gracias!

@Queenie wrote to me in a PM:

I moved all the code from the loop to setup, and I run it inside a while (1). A workaround solution but it worked perfectly!

Hello,

Don't you need different characteristic for writing (send to BLE), and reading from the BLE. Here it seems that you are using the same characteristics.

Thank you

BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);

1 Like

This is an excellent tutorial on the topic. Thank you for providing this information and for all of the good work.

Unfortunately, the AppInventor application appears to use a BLE extension (20201223) that was specially built to work around an issue. That extension is not available online. I've tried using the available extension (which was dated August 2020) but it won't connect. I will need to take this example application, duplicate it to get the library that's attached to it, and then rewrite pieces for my needs. Hopefully, the BLE connection issue will be resolved soon in a new AppInventor extension.

I have tracked BLE releases at

I see a download link there for the latest.

However the latest version 20201223 is for Testing, it is not as yet released.

Thanks ABG. I had already seen that page and there is no link to a 20201223 release of the BluetoothLE extension. There's a link that is labeled as such, but it leads to a thread that does not have the extension. It may have had it at one time, but it no longer does.

ChrisWard, I figured it was for testing only since it wasn't published at the standard location. However, the existing published extension doesn't work much at all with my BLE peripheral, whereas a test app I had downloaded that uses the test extension connects fairly well. So I am willing to be a guinea pig. :slight_smile:

I have asked if we can make it a formal release..........

Thank you, Juan! This is really helpful.

Unfortunately, I am having trouble using the RegisterForStrings method. For some reason, StringsReceived is never triggered. This happens for both examples 6 and 7. I did not change anything in the code except for upgrading the BLE extension to the latest release, which I have attached. If I do ReadForStrings then everything works fine so I am not sure what is the issue here. I am using Samsung Galaxy A8s. Could you give me some advice?

Thank you!

Jerry

edu.mit.appinventor.ble-20200828.aix (195.3 KB)

@Jerry_Tang

Try changing UUIDs on ESP32 and in the app.

https://www.uuidgenerator.net/