From 2fecf432752d19fabe9ccbdfe0fcc85f2eab677b Mon Sep 17 00:00:00 2001 From: Sebastian Nieto Date: Mon, 7 Sep 2026 20:46:49 -0300 Subject: [PATCH] Fix bluetooth scan loop bug and add robust device matching --- sketch/obd2_gauge/bluetooth.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sketch/obd2_gauge/bluetooth.h b/sketch/obd2_gauge/bluetooth.h index e65d832..4b8d86e 100644 --- a/sketch/obd2_gauge/bluetooth.h +++ b/sketch/obd2_gauge/bluetooth.h @@ -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