Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created February 20, 2020 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhishekGhosh/b67d5cbf81c27125f22f3d79208c3105 to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/b67d5cbf81c27125f22f3d79208c3105 to your computer and use it in GitHub Desktop.
Samsung Smartwatch as Proximity Switch
#include <BLEAdvertisedDevice.h>
#include <BLEDevice.h>
#include <BLEScan.h>
const int PIN = 2;
const int CUTOFF = -60;
void setup() {
pinMode(PIN, OUTPUT);
BLEDevice::init("");
}
void loop() {
BLEScan *scan = BLEDevice::getScan();
scan->setActiveScan(true);
BLEScanResults results = scan->start(1);
int best = CUTOFF;
for (int i = 0; i < results.getCount(); i++) {
BLEAdvertisedDevice device = results.getDevice(i);
int rssi = device.getRSSI();
if (rssi > best) {
best = rssi;
}
}
digitalWrite(PIN, best > CUTOFF ? HIGH : LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment