/*
Scan
This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details:
address, local name, advertised service UUID's.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
Serial.println("Bluetooth® Low Energy Central scan");
// start scanning for peripheral
BLE.scan();
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral
Serial.println("Discovered a peripheral");
Serial.println("-----------------------");
// print address
Serial.print("Address: ");
Serial.println(peripheral.address());
// print the local name, if present
if (peripheral.hasLocalName()) {
Serial.print("Local Name: ");
Serial.println(peripheral.localName());
}
// print the advertised service UUIDs, if present
if (peripheral.hasAdvertisedServiceUuid()) {
Serial.print("Service UUIDs: ");
for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
Serial.print(peripheral.advertisedServiceUuid(i));
Serial.print(" ");
}
Serial.println();
}
// print the RSSI
Serial.print("RSSI: ");
Serial.println(peripheral.rssi());
Serial.println();
}
}
Hi Max thanks for your answer! I agree this does work for your example.
I would like to share what finally worked for me, perhaps because my project has a few dependencies that makes it a bit more complex.
Instead of having the ArduinoBLE lib installed by PIO under lib_deps, I have an Arduino IDE installed with all packages that I need, then I’m pointing my PIO project libs to them with lib_extra_dirs.
These are the Arduino libraries that I’m using:
ArduinoBLE
Arduino_BMI270_BMM150
Harvard_TinyMLx
MicroTFLite
Arduino_LSM9DS1
That’s the only way it worked for me (or if I copy these libs locally under my PIO project’s /lib folder and tweak some files then it also works)
If I try to install all these packages using PIO lib manager, I get the error described originally in this thread when I build it.
Another important detail, as I’m in a Windows environment, I also found that I need to have my PIO project folder near the root - e.g. C:\repos\<pio-project>\ - otherwise the path and file names generated during compilation might be too long and become an issue.