Fix bluetooth scan loop bug and add robust device matching

This commit is contained in:
Sebastián Nieto 2026-09-07 20:46:49 -03:00
parent 5e2b27f3a0
commit 2fecf43275

View file

@ -57,8 +57,19 @@ void scanBTdevice() {//scan bluetooth device
Terminal(txt,0,48,320,191);//list devices
delay(100) ;
if (deviceName[i] == client_name || deviceName[i] == "debian" || deviceName[i].indexOf("OBD") != -1 || deviceAddr[i] == "e8:48:b8:c8:20:00") {//match name.
//found device name "OBDII"
String dName = deviceName[i];
dName.toUpperCase();
String dAddr = deviceAddr[i];
dAddr.toLowerCase();
bool isMatch = (dName == "OBDII") ||
(dName.indexOf("OBD") != -1) ||
(dName.indexOf("ELM") != -1) ||
(dName == "DEBIAN") ||
(dAddr == "e8:48:b8:c8:20:00");
if (isMatch) {//match name.
//found device name "OBDII" or emulator
foundOBD2 = true;
//00:1d:a5:00:12:92 -> {0x00,0x1d,0xa5,0x00,0x12,0x92};
//copy match bt mac address to client_name to connect
@ -80,8 +91,10 @@ void scanBTdevice() {//scan bluetooth device
pref.putBytes("recent_client",client_addr,sizeof(client_addr));//save new bt addr to pref.
Serial.println(F("Save a new BT client address"));
}
} else //not match
break; // Stop scanning once a matching device is found!
} else {
foundOBD2 = false;
}
}//for loop list device