I need help with my ESP32 Proximity Feature

i am trying to do a BLE proximity feature using ESP32. So, basically I have 2 ESP32, one is the transmitter and the other is receiver. What I am trying to do is, when I bring the transmitter further away from the receiver, the RSSI value received by the receiver should drop and when it drops below -90 I want he Builtin LED on the receiver to turn ON when the transmitter is brought back nearer to the receiver the LED should turn OFF.

What I have done so far is, I have the code for the receiver and the transmitter. So when I bring the transmitter further away the builtin LED on the receiver turn ON. However, the ESP32 receiver detects all the BLE device that near and not specifically my ESP32 transmitter. Now I am trying to amend the code for the receiver so that it only detects my ESP32 transmitter and not other BLE devices. I searched online and I understand that I get the BLE address of the transmitter and put a condition on the receiver to detect this specific address. So this where I am stuck, I am not sure where to and how to put this condition on the receiver.

This is the code for the receiver:

#include <BLEAdvertisedDevice.h>
#include <BLEDevice.h>
#include <BLEScan.h>
#include <Arduino.h>
int playing = 0;
//const int buzzer = 5;
const int PIN = 2;
const int CUTOFF = -90;

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;
    }
  }
  if(best>CUTOFF){

    digitalWrite(PIN,LOW);
  }
  else{
    digitalWrite(PIN,HIGH);

  }
 
}

This is the code for the transmitter:

#include "sys/time.h"
#include "BLEDevice.h"
#include "BLEUtils.h"
#include "BLEServer.h"
#include "BLEBeacon.h"
#include "esp_sleep.h"

#define GPIO_DEEP_SLEEP_DURATION     1  // sleep x seconds and then wake up
RTC_DATA_ATTR static time_t last;        // remember last boot in RTC Memory
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory


BLEAdvertising *pAdvertising;   // BLE Advertisement type
struct timeval now;

#define BEACON_UUID "87b99b2c-90fd-11e9-bc42-526af7764f64" // UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/)

void setBeacon()
{

  BLEBeacon oBeacon = BLEBeacon();
  oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!)
  oBeacon.setProximityUUID(BLEUUID(BEACON_UUID));
  oBeacon.setMajor((bootcount & 0xFFFF0000) >> 16);
  oBeacon.setMinor(bootcount & 0xFFFF);
  BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
  BLEAdvertisementData oScanResponseData = BLEAdvertisementData();

  oAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED 0x04

  std::string strServiceData = "";

  strServiceData += (char)26;     // Len
  strServiceData += (char)0xFF;   // Type
  strServiceData += oBeacon.getData();
  oAdvertisementData.addData(strServiceData);

  pAdvertising->setAdvertisementData(oAdvertisementData);
  pAdvertising->setScanResponseData(oScanResponseData);
}

void setup() {

  Serial.begin(115200);

  gettimeofday(&now, NULL);
  Serial.printf("start ESP32 %d\n", bootcount++);
  Serial.printf("deep sleep (%lds since last reset, %lds since last boot)\n", now.tv_sec, now.tv_sec - last);
  last = now.tv_sec;

}

void loop() {

    Serial.println("Continuous mode");
    // Create the BLE Device
    BLEDevice::init("My Proximity Feature"); // Name of your Beacon Device 
    // Create the BLE Server
    BLEServer *pServer = BLEDevice::createServer(); // <-- no longer required to instantiate BLEServer, less flash and ram usage
    pAdvertising = BLEDevice::getAdvertising();
    BLEDevice::startAdvertising();
    setBeacon();
    // Start advertising
    pAdvertising->start();
    Serial.println("Advertizing started...");
    delay(1000);
    pAdvertising->stop();
    Serial.printf("enter deep sleep\n");
    esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
    Serial.printf("in deep sleep\n");
  
}

The BLE Address of my transmitter is "6E:bc:55:18:cf:7b"

Any help would be much appreciated.

RSSI depends on many things, and is almost useless to determine distance from transmitter to receiver.

Right now your goal is pretty vague. Describe in more detail just what it is you want to do, and there are bound to be suggestions.

It is quite difficult to measure distance using simple radios, but these modules work well.

Okay, so what i am trying to do is implement a system (Consisting of two devices, lets call them Node A and Node B). Node B would ideally be a small device which carried by the user while the Node A would be device mounted on to a table. So when the user moves away from the table (Lets say a few meters away) the Node A on the table will trigger an Alarm.

So what I am trying to do is something similar to the car key proximity feature, where while the vehicle is running, if the driver walks away with key, the vehicle wont be able to move.

Unfortunately that goal is very difficult to achieve with any reliability, especially with respect to range of detection.

If the user or conductive objects block the direct line of sight between the two devices, reception range is greatly reduced. Similar questions crop up on this forum every week or so, and I've never seen a successful implementation.

I did a just search online and a came across this "Product" called the i-Tell.
https://itellalert.com/
So it is basically a 2 module system (Similar to what I am trying to achieve) where the user carries 1 module and the other module is mounted on to a walking frame. If the user walks away from the walking frame, it will trigger a vibration.

So I want to replicate this exact feature and tune it to slightly different

However, they did not mention how it works. Do you have idea on how this feature works?

Would really appreciate your advice.

I watched the video, which appears to be a fundraising promotion. From that website:

i-Tell Alert is pre-revenue. We have developed and tested our third phase proof of concept prototypes and are currently developing our MVP prototypes. We've received an extremely positive response from geriatric care professionals, caregivers, and our elder end-users.

I have seen other attempts at vaguely similar products and don't know of any that are recognized as truly reliable, with a well-defined range of detection. Tile is one, with mixed reviews. Try it and judge for yourself.