Closed
Description
I want to build a key bowl which detects whether a certain keychain was placed in it by detecting the attached Tile tag via BLE.
What is the most energy-efficient yet reliable way to observe a peripheral’s RSSI?
Currently, I am scanning repeatedly, limited to 4x per second and the specific peripheral address I am interested in:
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600);
while (!Serial); // wait
Serial.println("setup");
BLE.begin();
BLE.setEventHandler(BLEDiscovered, discovered);
BLE.scanForAddress("xx:yy:zz:aa:bb:cc", true);
}
void logDevice(BLEDevice dev) {
Serial.print("BLE device found: ");
Serial.print("address=");
Serial.print(dev.address());
Serial.print(", rssi=");
Serial.print(dev.rssi());
if (!dev.hasLocalName()) {
Serial.println("");
return;
}
Serial.print(", name=");
Serial.print(dev.localName());
Serial.println("");
}
void discovered(BLEDevice dev) {
BLE.stopScan();
logDevice(dev);
delay(250); // ms
BLE.scanForAddress("xx:yy:zz:aa:bb:cc", true);
}
void loop() {
BLE.poll(1000); // ms
}
I’m a bit hesitant to connect to the device, because I don’t want to disrupt any other functionality of the Tile.
Is there a better way than the approach displayed above?
Thanks,