Take certain characters from Arduino Serial Output BLE

I am trying to create a ble scanner but only want the device address to be displayed

The device address is the 12 characters before the :-0 in the outputs. In my code shown below I have tried to run the output through a list of 12 bytes and stop the list recording the data at :-0 so it will record the 12 bytes before this

#include <SoftwareSerial.h>

String inputTXT;

SoftwareSerial mySerial(10, 11); // RX, TX  

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {  
 Serial.begin(9600);

 mySerial.begin(9600);

 //setup
 mySerial.write("AT");
 delay(100);
 mySerial.write("AT+ROLE1"); // Master mode
 delay(100);
 mySerial.write("AT+IMME1"); //wait for a connection command before connecting 
 delay(100);
 mySerial.write("AT+RESET");
 delay(50);

}
 void recvWithEndMarker() {
   static byte ndx = 0;
   char endMarker = ":-0";
   char rc;

   while (Serial.available() > 0 && newData == false) {
       rc = Serial.read();

       if (rc != endMarker) {
           receivedChars[ndx] = rc;
           ndx++;
           if (ndx >= numChars) {
               ndx = numChars - 1;
           }
       }
       else {
           receivedChars[ndx] = '\0'; // terminate the string
           ndx = 0;
           newData = true;
       }
   }
}

void showNewData() {
   if (newData == true) {
       Serial.print("This just in ... ");
       Serial.println(receivedChars);
       newData = false;
   }}

void loop() {  

 delay(3000);

 mySerial.write("AT+DISI?");

 recvWithEndMarker(); //Put in at end
 showNewData();

 if (mySerial.available()) {
   inputTXT = mySerial.readString();

   Serial.println(inputTXT);

  // inputTXT = ""; 

 }

}

The serial output is as such:

OK+DISCEOK+DISISOK+DISC:00000000:00000000000000000000000000000000:0000000000:6DB9F38898FF:-081OK+DISC:00000000:00000000000000000000000000000000:0000000000:485E425C5B3A:-075OK+DISC:00000000:00000000000000000000000000000000:0000000000:4CAA0DE091B7:-069OK+DISC:00000000:00000000000000000000000000000000:0000000000:38F9D379C9E5:-070OK+DISC:00000000:00000000000000000000000000000000:0000000000:47C4C908CFB4:-073OK+DISC:
OK+DISCEOK+DISISOK+DISC:00000000:00000000000000000000000000000000:0000000000:485E425C5B3A:-060OK+DISC:00000000:00000000000000000000000000000000:0000000000:47C4C908CFB4:-066OK+DISC:00000000:00000000000000000000000000000000:0000000000:38F9D379C9E5:-071OK+DISC:00000000:00000000000000000000000000000000:0000000000:4CAA0DE091B7:-069OK+DISC:00000000:00000000000000000000000000000000:0000000000:6DB9F38898FF:-077OK+DISC:
OK+DISC:00000000:00000000000000000000000000000000:0000000000:DFOK+DISISOK+DISC:00000000:00000000000000000000000000000000:0000000000:DF12A8020D32:-051OK+DISC:00000000:00000000000000000000000000000000:0000000000:38F9D379C9E5:-069OK+DISC:00000000:00000000000000000000000000000000:0000000000:485E425C5B3A:-063OK+DISC:00000000:00000000000000000000000000000000:0000000000:47C4C908CFB4:-082OK+DISC:00000000:00000000000000
OK+DISCEOK+DISISOK+DISC:00000000:00000000000000000000000000000000:0000000000:38F9D379C9E5:-069OK+DISC:00000000:00000000000000000000000000000000:0000000000:47C4C908CFB4:-067OK+DISC:00000000:00000000000000000000000000000000:0000000000:DF12A8020D32:-051OK+DISC:00000000:00000000000000000000000000000000:0000000000:485E425C5B3A:-065OK+DISC:00000000:00000000000000000000000000000000:0000000000:6DB9F38898FF:-078OK+DISC:

The code I have written does not seem to have affected the output, am I on the right lines to getting the output as just the addresses like:

DF12A8020D32
38F9D379C9E5

Any help would be very appreciated!

This won't work for a start

char endMarker = ":-0";

In my code an end-marker must be a single character and I'm not sure which of the 4 characters in ":-0" (there is also a '\0') will be assigned to endMarker.

Try using a colon as the end marker. The data you want seems to be like this

:38F9D379C9E5:-

...R

So a : is both your stop and end marker.

My suggested approach:

  • read data until you see a ':'
  • start buffering the incoming characters, up to 12 characters (use a 13-character char array to have space left for the \0 terminator).
  • if less or more than 12 characters before you see the next ':', this was not the address. Restart buffering if you have had less than 12, ignore characters if you have more than 12 and still no ':'. It looks like characters should also be one of '0' to '9' or 'A' to 'F' to be a valid address.
  • if you had exactly 12 characters before the :, check whether the next one (the 14th) is a -. If so, your buffer now contains the address. Otherwise, start buffering again, starting with this character.

You're going to need a form of finite state machine to keep track of where in the process you are.