Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLEClient connect(BLEAddress..., esp_ble_addr_type_t.., uint32_t timeoutMS..) always returns true (even if the server doesn't exist) #10916

Open
1 task done
dahklfahdkghas opened this issue Jan 29, 2025 · 0 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@dahklfahdkghas
Copy link

Board

ESP32S3 "supermini"

Device Description

It's not attached to anything. I have tested with a bare minimum sketch to verify.

Hardware Configuration

No nothing.

Version

latest master (checkout manually)

IDE Name

Arduino IDE 2.3.4

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

The method with signature:
connect(BLEAddress address, esp_ble_addr_type_t type = BLE_ADDR_TYPE_PUBLIC, uint32_t timeoutMS = portMAX_DELAY);

always returns true, even on an unsuccessful connection (server not even powered on).

Expected behaviour:
true on successful connection
false on unsuccessful connection

The onConnect() callback is however not called on an unsuccessful connection. But pClient->isConnected() does return false, so that's a workaround once the bug is found.

Sketch

#include "BLEScan.h"
#include "BLEDevice.h"

static BLEAddress serverAddress("ea:7f:54:b4:62:2e");
bool isConnected = false;



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

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



bool connectToServer() {
  Serial.print("Forming a connection to: ");
  Serial.println(serverAddress.toString());

  BLEClient *pClient = BLEDevice::createClient();
  Serial.println("Created client");

  pClient->setClientCallbacks(new MyClientCallback());
  Serial.println("set callbacks");

  if (pClient->connect(serverAddress, BLE_ADDR_TYPE_RANDOM, 4000) != true) {
    Serial.println(" !!! failed to connect to server   !!!");
    isConnected = false;
    return false;
  }

  Serial.println("Connected to server");
  isConnected = true;
  return true;
}





void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.printf("Setup Started on Core: %d\n", xPortGetCoreID());
  Serial.printf("ESP_ARDUINO_VERSION_STR =  %s\n", ESP_ARDUINO_VERSION_STR);
  Serial.printf("esp_get_idf_version() = %s\n", esp_get_idf_version());

  
  BLEDevice::init("BLE Connect debugging");
}

void loop() {
  if (!isConnected) {
    connectToServer();
  }
  delay(2000);
}

Debug Message

Sketch printout on successful connection (Server is on):
---------------------------------
Setup Started on Core: 1
ESP_ARDUINO_VERSION_STR =  3.1.1
esp_get_idf_version() = v5.3.2-282-gcfea4f7c98-dirty
Forming a connection to: ea:7f:54:b4:62:2e
Created client
set callbacks
client onConnect
Connected to server
--------------------------------

Sketch printout on unsuccessful connection (Server isn't even plugged in):
---------------------------------
Setup Started on Core: 1
ESP_ARDUINO_VERSION_STR =  3.1.1
esp_get_idf_version() = v5.3.2-282-gcfea4f7c98-dirty
Forming a connection to: ea:7f:54:b4:62:2e
Created client
set callbacks
Connected to server
---------------------------------

NOTE the lack of "client onConnect" from the onConnect() callback!

Other Steps to Reproduce

I've tried on ESP_ARDUINO_VERSION_STR = 3.0.7 before updating, same problem.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@dahklfahdkghas dahklfahdkghas added the Status: Awaiting triage Issue is waiting for triage label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

1 participant