nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.36k stars 710 forks source link

Connect to BLE server without scanning #1074

Open Murtaza7745 opened 3 years ago

Murtaza7745 commented 3 years ago

I am new to ESP32 BLE programming, I want to connect ESP32 BLE client to only one particular server, I have the server ble address and its charac UUID and service UUID.

PLEASE HELP

chegewara commented 3 years ago

https://github.com/nkolban/esp32-snippets/issues/1072#issuecomment-825633790

Murtaza7745 commented 3 years ago

Thanks so much for replying so fast @chegewara. Let me explain you in a different way, I have a esp32 BLE acting as a client, i have a smart ble watch which is acting as a server. I want the client to connect to that server only, without scanning or anything, just use "static BLEClient*pClient->connect("60:35:0d:6c:79:21");"

PLEASE HELP

chegewara commented 3 years ago

In post i linked you can read its not possible. You have to scan.

Murtaza7745 commented 3 years ago

so how do I increase the memory size? if there are so many ble scan results, esp32 reboots.

I have attached my code.

include "BLEDevice.h"

define addr "60:35:0d:6c:79:21"

static BLEAddress Address (addr); static BLEClient* pClient; static boolean connected = false;

class MyClientCallback : public BLEClientCallbacks { void onConnect(BLEClient* pclient) { connected = true; Serial.println("Connected"); }

void onDisconnect(BLEClient* pclient) {
  connected = false;
  Serial.println("Disconnected");
}

}; void connectToServer(BLEAddress pAddress) { Serial.print("Forming a connection to "); pClient = BLEDevice::createClient(); Serial.println(" - Created client");

pClient->setClientCallbacks(new MyClientCallback());

// Connect to the remove BLE Server. pClient->connect(pAddress); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private) Serial.println(" - Connected to server"); } void setup() { // put your setup code here, to run once: Serial.begin(115200); BLEDevice::init(""); connectToServer(Address); }

void loop() { // put your main code here, to run repeatedly: Serial.println("."); delay(2000); }

PLEASE HELP

chegewara commented 3 years ago

There is few options.

Murtaza7745 commented 3 years ago

Thanks @chegewara :)