Skip to content

Best way to observe a peripheral’s RSSI #25

Closed
@stapelberg

Description

@stapelberg

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: supportOT: Request for help using the project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions