jjoe64 / esp32_ble_light

Stripped version of the ESP32 BLE library, to only support server logic and reduce size
24 stars 12 forks source link

How to measure esp32 to beacon distance #2

Open sw-tt-parasshah opened 6 years ago

sw-tt-parasshah commented 6 years ago

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