Chat freely about anything...

User avatar
By derek bernsen
#93048 Hi all,
I am looking for project advice.

I am trying to program an ESP32 to scan for new BLE devices, if it detects a new one with a strong RSSI, send alert to Android phone. The message would contain the BLE ID of the newly detected BLE device.

The tricky part is that I would prefer to do this without a WiFi connection on the ESP32 since otherwise I would need to use my phone as a hotspot for the ESP32.

I do not know where to start. I was looking at using Blynk for the alerts, but it looks like that would require an internet connection.

The initial context of the project is an alert device to detect when our regular delivery service person delivers to our building.
User avatar
By derek bernsen
#93062 I would prefer that it is not dependent on WiFi at all for internet connection.

I have this version working using WiFi and Blynk. I read somewhere that Blynk can be used with purely bluetooth, but I did not find any example code.

Here is what I have so far:

Code: Select all[code]
//#include <BlynkSimpleEsp32_BLE.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "blynk auth code here";


#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 5; //In seconds
String oldCount = "";
String newCount = "";
String notifyAlert = "";
BLEScan* pBLEScan;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      //Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
      notifyAlert = ("New Device Detected: %s \n", advertisedDevice.toString().c_str());
    }
};

void setup()
{
  Serial.begin(115200);
  Serial.println("Scanning...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);  // less or equal setInterval value
  Serial.println("Waiting for connections...");
  Blynk.begin(auth, "mywifissid", "mywifipassword"); // Replace with your WiFi network name and password.
  while (Blynk.connect() == false) { }

}

void loop()
{
  Blynk.run();
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  Serial.print("Devices found: ");
  Serial.println(foundDevices.getCount());
  newCount = (foundDevices.getCount());
  Serial.println("Scan done!");
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
  delay(2000);
  if (oldCount < newCount) {
    Serial.println("New device detected!");
    Blynk.notify(notifyAlert);
    Serial.println(notifyAlert);
    oldCount = newCount;
  }
}

[/code]
User avatar
By QuickFix
#93068 Let me get this straight: how do you want to let your phone know (using what transport system) that a new BT device was found?
You don't want to use WiFi/Internet, so what then: a wire to your phone, quantum teleportation, Bluetooth?