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

BLE won't reconnect after bluetooth is stopped and restarted. #39

Open
pjenks-accudyne opened this issue Apr 28, 2022 · 4 comments
Open

Comments

@pjenks-accudyne
Copy link

Board: ESP32-C3

If I use the code template below I am unable to reconnect to the board with my PC. The board auto-connects fine with the first instance of bleMouse.begin() but does not reconnect after bluetooth is stopped and restarted. If I use deep sleep or reset the board it will reconnect without issues. The mouse commands are still sent and bleMouse.isConnected returns true after bluetooth is restarted, but there is no connection shown on my PC and it does not receive the mouse commands. I also receive the error message shown below after bluetooth is restarted.

Code template:

bleMouse.begin();
while(bleMouse.isConnected) {
  // send mouse commands
}
bleMouse.end();
btStop();
// do something else
btStart();
bleMouse.begin();
while(bleMouse.isConnected) {
  // send mouse commands
}

Error message:
E (80831) BT_HCI: command_timed_out hci layer timeout waiting for response to a command. opcode: 0x2008

@jellybins
Copy link

jellybins commented Apr 29, 2022

the bleMouse.end() is an empty func; i have same problem and resolved it by soft restart the dev board ;detail in #37

@pjenks-accudyne
Copy link
Author

I noticed that too and updated the bleMouse.end() function to kill the task created by bleMouse.begin(), but that didn't fix the problem either. I'd like to avoid a soft restart if possible.

From BleMouse.cpp:

void BleMouse::begin(void)
{
  xTaskCreate(this->taskServer, "server", 20000, (void *)this, 5, &this->taskHandle);
}

void BleMouse::end(void)
{
  vTaskDelete(this->taskHandle);
}

From BleMouse.h:

class BleMouse {
private:
  // some declarations
public:
  // some declarations
  TaskHandle_t taskHandle;
protected:
  // some declarations
};

@Apofus2018
Copy link

I used the solution from above and added the following
if(bleMouse.isConnected()) { //blah //blah } else { bleMouse.end(); delay(1000); bleMouse.begin(); }
Mouse connected fine .....

@SmuleFlash
Copy link

I tired the solution above, but it nonstop doing bleMouse.begin() after I cycle the iPhone Bluetooth on/off. Therefore I add isConnect() while loop to wait for connection after bleMouse.begin() but it never get out of the isConnected loop. Although Bluetooth connection indicate connected on iPhone after switch off, this solution still unable to reconnect properly. Anyone can help?

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

4 participants