esp32_ble_light icon indicating copy to clipboard operation
esp32_ble_light copied to clipboard

How to measure esp32 to beacon distance

Open sw-tt-parasshah opened this issue 7 years ago • 0 comments

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 <BLEDevice.h> #include <BLEAdvertisedDevice.h> #include <WiFi.h> #include <PubSubClient.h>

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); }

sw-tt-parasshah avatar Jun 25 '18 10:06 sw-tt-parasshah