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

Resume advertising after the disconnect #57

Open
windmaomao opened this issue Sep 26, 2023 · 4 comments
Open

Resume advertising after the disconnect #57

windmaomao opened this issue Sep 26, 2023 · 4 comments

Comments

@windmaomao
Copy link

windmaomao commented Sep 26, 2023

It occurred to me, sometimes the mouse gets disconnected. And afterwards we can't initialize the connection anymore. So I dug into the code and learned from another bluetooth server code. Can I suggest to add the following lines to the disconnect code.

  void onDisconnect(BLEServer *pServer)
  {
    deviceConnected = false;

    BLEAdvertising *pAdvertising;
    pAdvertising = pServer->getAdvertising();
    pAdvertising->start();
  }

In our repo, it'll be inside BleConnectionStatus. I can raise a PR if you think this is not a bad idea, I can even add a flag to enable/disable it.

@windmaomao windmaomao changed the title Stop advertising after the disconnect Continue advertising after the disconnect Sep 26, 2023
@windmaomao windmaomao changed the title Continue advertising after the disconnect Resume advertising after the disconnect Sep 26, 2023
@alextrical
Copy link

Hi, I'm having the same issue as you have mentioned here. However I'm struggling to see how to apply the fixed code that you have quoted.

the contents of BleConnectionStatus.cpp are the following

#include "BleConnectionStatus.h"

BleConnectionStatus::BleConnectionStatus(void) {
}

void BleConnectionStatus::onConnect(BLEServer* pServer)
{
  this->connected = true;
  BLE2902* desc = (BLE2902*)this->inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(true);
}

void BleConnectionStatus::onDisconnect(BLEServer* pServer)
{
  this->connected = false;
  BLE2902* desc = (BLE2902*)this->inputMouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
  desc->setNotifications(false);
}

@windmaomao
Copy link
Author

i created this PR to address this, and I have used this for a while, it's quite stable after this change.

https://github.com/T-vK/ESP32-BLE-Mouse/pull/62/files

@alextrical
Copy link

Awesome, thank you for clarifying. I think i was close but was missing the final piece to get it working reliably.

Its also helped me solve connecting one "Mouse" to multiple clients, by appending the same snippet into the onConnect block

@coofercat
Copy link

I just tried your patch, and also found things work much better this way - random and intentional disconnects all seem to be handled gracefully with it in place.

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