Hello everyone hope you doing all well, i was trying to set a BLE connection between two arduino rp 2040 in my app ( depending on user input it will chose which technology to start), the BLE peripheral is working just fine and connected to it via bluetooth scanner app, the problem is that my code for the central which needs to detect the peripheral and retrieve RSSI doesn t work, any help please ? , here s the code :
if (strcmp(selectedMode, "Mode 7") == 0 && !isScanDone) {
BLEDevice peripheral;
do {
// Start scanning for BLE peripherals with the specific service UUID
BLE.scanForUuid("180D");
// Check if a peripheral has been discovered
peripheral = BLE.available();
// Print a dot to indicate scanning
Serial.print(".");
// Delay to throttle the scanning process and allow some CPU time for other operations
delay(100);
} while (!peripheral); // Continue until a peripheral is found
// Stop scanning
BLE.stopScan();
if (peripheral) {
// Check if the peripheral actually has the service UUID
if (peripheral.hasService("180D")) {
int rssi = peripheral.rssi();
Serial.print("RSSI: ");
Serial.println(rssi);
} else {
Serial.println("Device found, but does not have the required service.");
// Optional: Restart the scanning if necessary
isScanDone = false; // Set to false to allow rescanning
}
} else {
Serial.println("No device found.");
}
// Set the flag to true to prevent re-entry if no need to rescan
isScanDone = true;
}