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!