Can't split String when using BlutoothSerial

ameurbilel
Posts: 1
Joined: Mon Feb 22, 2021 5:17 pm

Can't split String when using BlutoothSerial

Postby ameurbilel » Mon Feb 22, 2021 5:26 pm

I am using the BlutoothSerial library to connect and send data via my android app to ESP32.
Till now i am able to connect and send some characters to the esp32 but when i try to split that data nothing happens.
I am using the StringSplitter library to split data. I am able to use it with a String that i initialize in my code but couldn't do that with the data that i got from my phone app.
herer is my code :

Code: Select all

void connectBluetooth (){
  String message = "";
  String btInput = "";
  String mySsid;
  
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
     char incomingChar = SerialBT.read();
    if (incomingChar != '\n'){
      message += String(incomingChar);
    }
    else{
      message = "error#erreur";
    }
    //Serial.write(incomingChar);  // here i am able to write the data before converting it to String and split it
  
  delay(20);
  btInput += String(incomingChar);
  //writeString(btInput);  // writeString() is a method to print the String value
  StringSplitter *splitter = new StringSplitter(btInput, '#',3);
  int itemCount = splitter->getItemCount();
  for(int i = 0; i < itemCount; i++){
    mySsid = splitter->getItemAtIndex(1);
  }
  writeString(mySsid);
  }
}

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 79 guests