-
Notifications
You must be signed in to change notification settings - Fork 415
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
NimBLE-Arduino (optional) and remove of xTaskCreate #111
Conversation
removed xTaskCreate in begin() removed BleConnectionStatus removed KeyboardOutputCallbacks implemented callbacks directly in BleKeyboard
Awesome! Once it has been tested with Windows, Mac OS, Linux, Android and iOS I will accept it. |
I only have the option to test Windows and Android. |
Okay, I will ping some people from other issues to give it a try. If you don't mind, I would like to have that fix added to this PR as well. This way we know that if it doesn't work for someone, it isn't because of the device name. This should do: BleKeyboard.cpp
BleKeyboard.h
|
I also did a test on Android and again encountered timing problems with NimBLE (it is too fast for my Samsung Galaxy 71). What do you think about this and what kind of name would you use for this function? |
I agree, we should have a function like that. I'm not sure what to call that function either. Maybe Edit: Edit:2 |
I have used vTaskDelay only because the arduino
I agree. We just have to find out how high this value has to be.
Perfect :) |
I have changed my mind. My tests have shown the following settings for a stable transmission: For this reason I have taken a default value of 7 ms. However, this may be different on different PCs / Android phones. |
Great, let's go with 7 as a default then. If this doesn't work for everyone, I'll find out eventually and increase it. |
3 milliseconds on my son's iPhone 8. |
Can you add this line to the library.properties file?
Edit: |
I am not sure if this is a good idea as NimBLE-Arduino is optional.
This looks like a Linux problem to me. |
I agree, I'm not sure either. I guess we leave it as is for now. But it might make sense to make NimBLE the default at some point.
If the Windows machine crashed or lost power while being connected you'd probably end up in the same state. So while it would probably seemingly fix the problem if Linux were to send that disconnect signal, I feel like the ESP should be capable of recovering from an unannounced disconnect. But I don't think this issue has anything to do with your PR. |
I don't know how Windows would behave in the event of a crash (the last time was several years ago). I don't know how to determine whether a BLE connection still exists. The problem is probably that the client does not disconnect the connection cleanly. But you can't blame the host for that ;) I don't know enough details about how BLE works on the ESP. I am only a user of the (Nim)BLE library. |
I will find a way to address that issue eventually, I mean other BLE devices manage to do it too, but it's a low priority at the moment. :) |
Yes, I think so too. |
Hi @sivar2311 . I built a BLE keyboard that uses capacitive sensors instead of keys (with Adafruit's MPR121 Sensor Breakout) and Adafruit's ESP32-WROOM-32 as MCU (HUZZAH32). These two communicate over I2C and had noise issues that were fixed on Espressif's Arduino-ESP32 Rel 2.0.0. (that's based on the latest development version of ESP-IDF to attain Thread-Safe I2C, here: https://github.com/espressif/arduino-esp32/releases/tag/2.0.0 ). I'm using T-vK's ESP32-BLE-Keyboard v0.3.0 and everything runs smoothly. When trying to use nimBLE (to save space and add other functions), I got compilation errors from nimBLE files not found. Because the Arduino-ESP32 is based on IDF, I copied the nimBLE files from here https://github.com/h2zero/esp-nimble-cpp but didn't work. h2zero states to install ESP-IDF v4.0+ but I think that could mess up Espressif's Arduino-ESP32 Rel 2.0.0? What combination of Arduino-ESP32 implementation & nimBLE files should I use to run BLE-Keyboard on nimBLE? Many thanks! (just FYI: this is an attempt to create a wireless "RPM Letterboard", something used in some autistic therapies) |
Hi @tahunus I think you have installed the wrong library. If you are on ArduinoIDE, you can simply install the library via the library manager. |
Hi @sivar2311 Follow-up question: I don't see any savings in memory usage. This is the compiling result with regular BLE: This is the compiling result when adding the line #define USE_NIMBLE before the #include <BleKeyboard.h> statement: Below is the full sketch for your reference.
|
It looks like the #define statement in the ArduinoIDE is not working :( |
Workaround for Arduino IDE: With this modifications the result from compiling the example is:
|
Thanks! Works as you mentioned! |
NimBLE-Mode
This implements NimBLE-Mode to reduce memory consumption
ArduinoIDE: Before including the library, insert the line
#define USE_NIMBLE
PlatformIO: Change your
platformio.ini
to the following settingsComparison (SendKeyStrokes.ino at run-time)
ESP.getHeapSize()
ESP.getFreeHeap()
ESP.getSketchSize()
xTaskCreate
xTaskCreate was removed to fix stack issues.