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

NimBLEServerCallbacks won't call onConnect(BLEServer*, NimBLEConnInfo&) #638

Open
bmedici opened this issue Feb 3, 2024 · 2 comments
Open

Comments

@bmedici
Copy link

bmedici commented Feb 3, 2024

Hi,

I'm using this library in version 1.4.1 and identified an unexpected behaviour with server callbacks.

Here is the init code I'm using:

class ServerCallbacks: public NimBLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;
    };

void loop() {
  log("deviceConnected: " + std::to_string(deviceConnected));
  }
}

BLEServer *pServer;
NimBLEDevice::init(BLE_NAME);
pServer = NimBLEDevice::createServer();
pServer->setCallbacks(new ServerCallbacks());

I implemented the server callbacks as shown and, in this situation, the deviceConnected variable is correctly set when my android device connects:

ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
// Android device connecting
ble-master | deviceConnected: 1
// The callback is called
ble-master | deviceConnected: 1
ble-master | deviceConnected: 1

On the other hand, while using the complete prototype for onConnect(BLEServer*, NimBLEConnInfo&), the callback is not called at all. With:

class ServerCallbacks: public NimBLEServerCallbacks {
    void onConnect(BLEServer* pServer, NimBLEConnInfo& connInfo) {
      deviceConnected = true;
    };
}

nothing happens

ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
// Android device connecting
ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
ble-master | deviceConnected: 0
// Nothing happens

I double checked that the only difference between both tests is changing the function prototype from
onConnect(BLEServer* pServer) to onConnect(BLEServer* pServer, NimBLEConnInfo& connInfo).

As I need the connInfoparameter, this bug is a bit annoying.

Any idea ?

@h2zero
Copy link
Owner

h2zero commented Feb 6, 2024

You are using v1.4.1, try switching to the master branch if you want to use the latest function signature, otherwise change to the old sig that takes the ble_conn_desc struct.

@REEASD
Copy link

REEASD commented Apr 29, 2024

you can add override.
class ServerCallbacks: public NimBLEServerCallbacks {
void onConnect(BLEServer* pServer,BLEConnInfo& connInfo) override {
deviceConnected = true;
};

void loop() {
log("deviceConnected: " + std::to_string(deviceConnected));
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants