Comments on: ESP32 BLE Server and Client (Bluetooth Low Energy) https://randomnerdtutorials.com/esp32-ble-server-client/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Wed, 25 Jun 2025 07:56:55 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Holin Chang https://randomnerdtutorials.com/esp32-ble-server-client/#comment-1060795 Wed, 25 Jun 2025 07:56:55 +0000 https://randomnerdtutorials.com/?p=107720#comment-1060795 Hi Rui / Sara,
I am a freshman for Arduino.
Your website/ tutorial really helped me.

I have a question about the below function:
I guess there is an ” else ” missed.
the statemant I sandwiched with “//////////////////////…” seems always go through ( connectToServer() always delivers true ) no matter previous if result.

bool connectToServer(BLEAddress pAddress) {
BLEClient* pClient = BLEDevice::createClient();

// Connect to the remove BLE Server.
pClient->connect(pAddress);
Serial.println(” – Connected to server”);

// Obtain a reference to the service we are after in the remote BLE server.
BLERemoteService* pRemoteService = pClient->getService(bmeServiceUUID);
if (pRemoteService == nullptr) {
Serial.print(“Failed to find our service UUID: “);
Serial.println(bmeServiceUUID.toString().c_str());
return (false);
}

// Obtain a reference to the characteristics in the service of the remote BLE server.
temperatureCharacteristic = pRemoteService->getCharacteristic(temperatureCharacteristicUUID);
humidityCharacteristic = pRemoteService->getCharacteristic(humidityCharacteristicUUID);

if (temperatureCharacteristic == nullptr || humidityCharacteristic == nullptr) {
Serial.print(“Failed to find our characteristic UUID”);
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Serial.println(” – Found our characteristics”);

//Assign callback functions for the Characteristics
temperatureCharacteristic->registerForNotify(temperatureNotifyCallback);
humidityCharacteristic->registerForNotify(humidityNotifyCallback);
return true;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

]]>
By: David Hughes https://randomnerdtutorials.com/esp32-ble-server-client/#comment-1060004 Sun, 22 Jun 2025 14:03:47 +0000 https://randomnerdtutorials.com/?p=107720#comment-1060004 I am going to ask a really simple question, as I am new to this, so please bear with me.

I have mostly got all this working and have client and server talking to eachother.

I want to send the data between them using numerical data, ie integers, rather than character strings. I have managed to do this at the server end, but can not figure out what I need to change at the client end.

David

]]>
By: Rezeki https://randomnerdtutorials.com/esp32-ble-server-client/#comment-1057136 Fri, 13 Jun 2025 03:33:54 +0000 https://randomnerdtutorials.com/?p=107720#comment-1057136 Hi Sara,
Good day.

Is there any simple sample sketch for Server and Client which both of them can send and receive data between Server and Client. Thanks in advance

]]>
By: Rohith https://randomnerdtutorials.com/esp32-ble-server-client/#comment-1052022 Thu, 29 May 2025 03:46:01 +0000 https://randomnerdtutorials.com/?p=107720#comment-1052022 Hi ,
Thanks for your excellent contents.
I am struggling to add passkey encryption in ESP32 Client. Always getting Pairing failed!”

Added call back.
// Custom Security Callback Class
class MySecurity : public BLESecurityCallbacks {
uint32_t onPassKeyRequest() {
Serial.println(“Requested passkey”);
// Return the passkey expected by the server
return passkey; // Replace with your passkey
}
void onPassKeyNotify(uint32_t pass_key) {
Serial.printf(“Passkey Notify: %d\n”, pass_key);
}
bool onConfirmPIN(uint32_t pass_key) {
Serial.printf(“Confirm Passkey: %d\n”, pass_key);
return true; // Accept the passkey
}
bool onSecurityRequest() {
return true;
}
void onAuthenticationComplete(esp_ble_auth_cmpl_t auth_cmpl) {
if(auth_cmpl.success) {
Serial.println(“Pairing success!”);
} else {
Serial.println(“Pairing failed!”);
}
}
};

Calling this before “LEClient* pClient = BLEDevice::createClient();”
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
BLEDevice::setSecurityCallbacks(new MySecurity());

BLESecurity *pSecurity = new BLESecurity();
pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY); // Secure Connections Only
pSecurity->setCapability(ESP_IO_CAP_OUT); // Display Only (client provides passkey)
pSecurity->setRespEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
pSecurity->setStaticPIN(passkey);
pSecurity->setKeySize(16);

]]>
By: Narasimman.M https://randomnerdtutorials.com/esp32-ble-server-client/#comment-1006765 Mon, 10 Feb 2025 06:32:22 +0000 https://randomnerdtutorials.com/?p=107720#comment-1006765 Hi SARA,
If ESP32 as a server, Mobile BLE application is Client.
In this case after the successful server(ESP32) client(App) conection , ESp32 need to disconnect the BLE connection between the Mobile application.
What should I do?
Thanks.

]]>
By: Gregory https://randomnerdtutorials.com/esp32-ble-server-client/#comment-989838 Sun, 08 Dec 2024 18:39:20 +0000 https://randomnerdtutorials.com/?p=107720#comment-989838 Why the ESP32 with the screen is not the server ?
would this no longer make sense?
especially if we want to manage several sensors and therefore several BLE clients?

]]>
By: danial https://randomnerdtutorials.com/esp32-ble-server-client/#comment-974550 Mon, 21 Oct 2024 15:27:02 +0000 https://randomnerdtutorials.com/?p=107720#comment-974550 Thanks for your work, Sarah.
Can you advise me how to get new RSSi value from connected server every second.
I’m new, and have problem with class or pointer.

]]>
By: Andreas Deckers https://randomnerdtutorials.com/esp32-ble-server-client/#comment-949864 Wed, 21 Aug 2024 15:20:49 +0000 https://randomnerdtutorials.com/?p=107720#comment-949864 Hallo, ich habe 2 ESP32 Wroom mittels BLE als Server und Client verbunden, um die Werte eines BME 280 auf einem Oled Display gemäß Eurem Beispiel Projekt anzuzeigen. Die Bluetooth Verbindung funktioniert und die Werte werden übertragen. Aber auf dem Oled Display erscheint keine Anzeige. Was muss ich ändern? Das Display funktioniert.

]]>
By: Leandro https://randomnerdtutorials.com/esp32-ble-server-client/#comment-948878 Sat, 17 Aug 2024 22:03:40 +0000 https://randomnerdtutorials.com/?p=107720#comment-948878 Por acaso alguém teria um sketch modelo para colocar senha na conexão BLE?

]]>
By: Ken Blanch https://randomnerdtutorials.com/esp32-ble-server-client/#comment-948672 Fri, 16 Aug 2024 18:55:52 +0000 https://randomnerdtutorials.com/?p=107720#comment-948672 In reply to Ken.

Client code is now compiling I Copied and Pasted to the IDE
again and it worked cant explain what was wrong before but all good now
Thanks.

]]>