-
-
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); | |
} |
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
How do I make this ESP device detect all phones?
For some reaon, I do not see 'most' phones.
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.
Hi, Can you post the contents of the Puck.js script? Thanks.
hello wybiral,
can you help me out, i am not a arduino coder.
i am stuck at this. In the code, the loop never stops.
I want to trigger 2 relays using BLE and also set
the activetion distance area to 5meters from the esp32 so that it
triggers only when the BLE device is 5mtrs away.when it is detected
i want it to stay on, while running the code the relay switches on and
off every 2 seconds. hope you would fix it for me.
Thanks Anand.
(the code is:)
#include <BLEDevice.h> //Header file for BLE
static BLEUUID serviceUUID("0000fff0-0000-1000-8000-00805f9b34fb");
static BLEUUID charUUID("0000fff0-0000-1000-8000-00805f9b34fb");
String My_BLE_Address = "c1:b4:70:74:fb:66";
static BLERemoteCharacteristic* pRemoteCharacteristic;
BLEScan* pBLEScan;
BLEScanResults foundDevices;
static BLEAddress *Server_BLE_Address;
String Scaned_BLE_Address;
boolean paired = false;
boolean chkConnet = false;
bool connectToserver (BLEAddress pAddress)
{
}
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks
{
void onResult(BLEAdvertisedDevice advertisedDevice)
{
Serial.printf("Scan Result: %s \n", advertisedDevice.toString().c_str());
Server_BLE_Address = new BLEAddress(advertisedDevice.getAddress());
Scaned_BLE_Address = Server_BLE_Address->toString().c_str();
}
};
void setup()
{
Serial.begin(115200);
Serial.println("Project-4");
pinMode(12, OUTPUT);
pinMode(14, OUTPUT);
}
void loop()
{
foundDevices = pBLEScan->start(3);
Serial.println(chkConnet);
if(chkConnet == false)
{
while (foundDevices.getCount() >= 1)
{
if (Scaned_BLE_Address == My_BLE_Address && paired == false)
{
Serial.println("connecting .....");
if (connectToserver(Server_BLE_Address))
{
paired = true;
Serial.println("ON");
if(chkConnet == false)
{
digitalWrite (12,HIGH);
digitalWrite (14,HIGH);
chkConnet = true;
Serial.println("On");
}
break;
}
else
{
Serial.println("Pairing failed");
break;
}
}
break;
}
}
while (foundDevices.getCount() == 0)
{
Serial.println("**************");
Serial.println(foundDevices.getCount());
}
}