Possible problem with BLE Extensions Method WriteStrings

Hello everybody, in my project I use the BluetoothLE extension 20200828,
and I found something strange for me.
I use an ESP32 as BLE it has one Service and one Characteristic set for read and write.
If I use nRF Connect to write on the Characteristic everything works fine.
If I use the BLE WriteStrings method of AppInventor I find nothing on the ESP32 Characteristic.
However if I use the BLE ReadStrings and then WriteStrings the write operation works fine.
I do not why I have to Read before to Write, I am missing something or it is a bug?


Thank You very much.
Best Regards
Marco

Sounds like a time interval issue Marco, whereby using ReadString 'buys' the time necessary for WriteString. Cannot tell what is going on with only a % of the info though.

Hi Chris, thank You for your reply I attach You a simple project to explain better.
BLETest.aia (190.7 KB)
After the connection if click send to make a WriteStrings I do not find the data on the ESP32 side.
If I try the same thing with nRF Connect i can write text without problem
I show my test sketch on the esp32 side:

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

BLEServer* pServer = NULL;
BLECharacteristic* pChar_Evento = NULL;
BLEAdvertising *pAdvertising = NULL;

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

int DevConn = 0;
bool deviceConnected = false;
std::string Value_Evento;

class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
DevConn++;
Serial.print("DevConn: ");
Serial.println(DevConn);
};

void onDisconnect(BLEServer* pServer) {
  deviceConnected = false;
  DevConn--;  
  Serial.print("DevConn: ");
  Serial.println(DevConn);
}

};

class Callbacks_Evento: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pChar_Evento)
{
Value_Evento = pChar_Evento->getValue();
Serial.print("Callbacks_Evento: ");
Serial.println(Value_Evento.c_str());
}
void onRead(BLECharacteristic *pChar_Addr)
{

}

};

void setup() {
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("MyBLEDevice");
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());

// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);

// Create a BLE Characteristic Evento
pChar_Evento = pService->createCharacteristic(
                 CHAR_UUID_EVENTO,
                 BLECharacteristic::PROPERTY_READ   |
                 BLECharacteristic::PROPERTY_WRITE);

pChar_Evento->setAccessPermissions(ESP_GATT_PERM_READ_ENCRYPTED | ESP_GATT_PERM_WRITE_ENCRYPTED);
// Create a BLE Descriptor
pChar_Evento->addDescriptor(new BLE2902());
pChar_Evento->setCallbacks(new Callbacks_Evento());
// Start the service
pService->start();

// Start advertising
pAdvertising = pServer->getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->start();
Serial.println("BLE SERVER Started!");

}

void loop() {

}

As workaround i found that if I add a BLE ReadStrings for example on when Ble Connected , the method WriteString works, but I do not understand why I have to do!
I hope this is helpful.
Best Regards Marco