class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
client.publish("esp32", advertisedDevice.getAddress().toString().c_str());
}
};
void setup() {
Serial.begin(115200);
WiFi.begin("hello", "hello@123");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
client.setServer("192.168.4.116", 1883);
while (!client.connected()) {
if (client.connect("ESP32Client", "admin", "admin123" )) {
}
}
BLEDevice::init("");
}
void loop() {
// put your main code here, to run repeatedly:
if(WiFi.status() == WL_CONNECTED)
{
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
BLEScanResults foundDevices = pBLEScan->start(scanTime);
}
delay(2000);
}
I want rssi distance to measure the distance between Estimote beacon to ESP33.
below code will send beacon data to cloud. I want to get distance also.
please suggest.
include
include
include
include
int scanTime = 10; //In seconds BLEScan* pBLEScan = BLEDevice::getScan();
WiFiClient espClient; PubSubClient client(espClient);
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) { client.publish("esp32", advertisedDevice.getAddress().toString().c_str()); } }; void setup() { Serial.begin(115200); WiFi.begin("hello", "hello@123"); while (WiFi.status() != WL_CONNECTED) { delay(500); } client.setServer("192.168.4.116", 1883); while (!client.connected()) { if (client.connect("ESP32Client", "admin", "admin123" )) { } } BLEDevice::init("");
}
void loop() { // put your main code here, to run repeatedly: if(WiFi.status() == WL_CONNECTED) { pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster BLEScanResults foundDevices = pBLEScan->start(scanTime); } delay(2000); }