Skip to content

Instantly share code, notes, and snippets.

@wybiral
Created September 19, 2018 12:53
Show Gist options
  • Save wybiral/2a96c1d1605af7efa11b690586c4b13e to your computer and use it in GitHub Desktop.
Save wybiral/2a96c1d1605af7efa11b690586c4b13e to your computer and use it in GitHub Desktop.
#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);
}
@jasnos
Copy link

jasnos commented Jan 6, 2024

Hi, can you tell me how setup to this up to detect a specific device ID? That is, I only want one Bluetooth device to trigger the reaction

Same here...

I want to set up a scenario where a relay is triggered for 30 minutes if my iPhone or Apple Watch is detected within a custom proximity range or signal strength. This scenario should only run in the morning when I am sitting in front of my computer. The trigger will switch on an anti-depression lamp for 30 minutes.

Could you please provide me with some tips on how to achieve this? Thank you.

@StuartJames
Copy link

Hi, Can you post the contents of the Puck.js script? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment