-
-
Notifications
You must be signed in to change notification settings - Fork 174
NimBLE Server - NIMBLE_PROPERTY::READ leads to crash #8
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
Comments
Thanks for reporting, strange behavior indeed. I'll look into this tomorrow. |
I think I found it, at least how to avoid the crash. // Create BLE Characteristic for WiFi settings
pCharacteristicWiFi = pService->createCharacteristic(
BLEUUID(WIFI_UUID),
// WIFI_UUID,
NIMBLE_PROPERTY::READ | // NIMBLE_PROPERTY::READNOTIFY |
NIMBLE_PROPERTY::WRITE); // | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC);
/** Add properties the same way as characteristics now **/
// pCharacteristicWiFi->createDescriptor("2902" /** , NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE **/); But now I got a different problem. This application was working with the server_dev branch before. I just retried yesterday with the final library for confirmation. |
I have located the source of the error and it's actually in the application code. If you create a 2902 descriptor without As for the fix, I would suggest adding one of those properties to the characteristic you are creating the descriptor with as without those set it probably won't function the way you expect. I'm considering adding those properties automatically if a 2902 is created without them but that would be encouraging bad practice. The other option is to ignore it completely but then there would be complaints that it's not working lol. The final option is to allow it to be created anyway but I'm unsure if notifications would even be sent, which may be even more confusing. As for the number of bytes you're receiving I am unsure why that would be other than perhaps your android app has not exchanged MTU info with the esp32. Nothing in that code has changed since merging the ServerDev branch. I'll see what I can find. |
Maybe just add assert, which will crash or at least display error/warning about missing property, because with descriptor you can have either notification or indication.
Indeed it looks like MTU = 23. |
I understand the problem with the 2902 descriptor and will adjust the code. For the 18 bytes, when I compile the same code with the ESP32-Arduino BLE library it works without problems. It happens only with NimBLE. On Android side I use the same app in both cases. @chegewara, just a comment, 18+3 would indicate a MTU of 21, not 25. |
Just tested it and if a 2902 is created without the properties set on the characteristic for notfiy or indicate the client app will not provide a means to subscribe. @chegewara I agree an assert/message is probably best. |
Just thinking.... If I don't use Notify or Indicate, I don't need the 2902 descriptor. Will test tomorrow together with the MTU problem. |
That's correct, if you aren't using notification/indication there is no need for a 2902. If you set log level to debug you will see if/when the MTU is exchanged and what the value is. With my phone I get this:
|
You are correct, write request OP code takes 3 bytes, so it should be 20 bytes of data, unless NimBLE is bugged. |
@h2zero side problem |
Or maybe not, I think I was looking at the log wrong. |
Well, forget the problem for now, it might be related to the Android BLE library I use. I made another test with a customers Android app, which uses nRF52 BLE library and it works just fine there. It uses the same custom characteristic with both READ and WRITE. I will have to dig into the Android BLE library I use for the app causing the problem. |
Look for an api call to begin MTU exchange in your library and call it after the connection opens. Also I'd like to say thanks for this issue as I now know I need to implement long reads and writes. I already started on the code for that and will push a new branch up shortly with some of that and the latest bugfixes. |
Still wondering why I didn't need it in the ESP32-Arduino BLE library. But I am good now. Thanks for the support! |
@beegee-tokyo Because this is not implemented yet and its working in old library |
HI @h2zero I know you are busy with fixing the Client stuff, but something on the Server side broke along the way.
Simple custom characteristic creation using
NIMBLE_PROPERTY::READ
makes the app crash onpService->start()
.Example code:
Serial debug output:
Decoded backtrace:
I tried as well with the BLE Uart example and it crashes at the same place. Btw. there is an error in the BLE Uart example.
should be
The text was updated successfully, but these errors were encountered: