Hello
As I am a beginner on App Inventor and the Esp32, I have a problem that I cannot solve.
I made a program that I scaled down just to show the problem.
I manage to send a text from the smartphone to the esp32 with a classic bluetooth but not the other way around.
I am using a nodemcu esp32 from Az delivery
https://www.az-delivery.de/en/.../
and I configured the arduino IDE as indicated on their site
https://www.az-delivery.de/en/...
For App Inventor, I started with @Juan_Antonio 's examples
https://community.appinventor.mit.edu/...
testBT.aia (716.0 KB)
By pressing the Test button, the bluetooth connection is created and the message 'SendToEsp32' is sent to the esp32. It works.
Then the esp32 sends the message "SendToSmartphone" is sent to the smartphone, but there I do not receive anything and I do not understand.
Any help would be much appreciated
[EDIT] Solved, I miss to put a delimiter to 10 for the bluetooth client!
Esp32 light code:
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
void connectBluetooth() {
; //Bluetooth device name
if (SerialBT.begin("Horloge")) {
Serial.println("Bluetooth initialized");
SerialBT.register_callback(btCallback);
Serial.println("The device started, now you can pair it with bluetooth");
} else {
Serial.println("An error occurred initializing Bluetooth");
}
}
void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) {
if (event == ESP_SPP_SRV_OPEN_EVT) {
Serial.println("Client Connected!");
} else if (event == ESP_SPP_DATA_IND_EVT) {
Serial.printf("ESP_SPP_DATA_IND_EVT len=%d, handle=%d\n\n", param->data_ind.len, param->data_ind.handle);
String received = bluetoothReadLine();
Serial.println(received);
SerialBT.println("SendToSmartphone");
SerialBT.flush();
}
}
String bluetoothReadLine() {
String text_received = "";
while (SerialBT.available()) {
byte r = SerialBT.read();
if (r != 13 && r != 10 && char(r) != '\0')
text_received = text_received + char(r);
}
return text_received;
}
void writeSerialBT(String respuesta) {
SerialBT.println(respuesta);
SerialBT.flush();
}
void setup() {
Serial.begin(115200);
connectBluetooth();
}
void loop() {
}```