Open dreamstyler opened 4 years ago
Hi @dreamstyler .
Thanks for reporting.
Rather than resetting the BLE stack, I would try to detect the cause of your 'crash at some random point'.
Could you post the sketch you are using and attach the debug information printed into the serial monitor? (To print the debug information you should insert this statement BLE.debug(Serial);
after the begin of the serial monitor in your sketch).
However, thanks also for this report https://github.com/arduino-libraries/ArduinoBLE/issues/129 . I will address it in the coming days!
Thanks for your reply,
I will check later to give some sample code.
Please find below a log dump
NOTE: It would be good to have a way to check what MTU was negotiated with the other BLE device as this informs one on how much data can be transferred. (this is stored on peers but there is no where to check what that is)
There are a few cases where this below happens, but id does seem to keep working HCI EVENT RX <- 04130004 13 5 1 0 0 1 0
At there points is when coms stops working and a reboot is required. Its as if the Ardrino BLE module freezes and does not accept new requests from other BLE device. Did try query the BLE mac address of the Arduino at this point and it return 0's. Reboot is where I trigger a reboot.
Added a sample project, the actual project is much larger. I use FreeRTOS so I had to "unpluck some functions" to add vTaskSuspendAll, xTaskResumeAll, vTaskDelay Also commented out some code, like reading data from SD card, but this should give you an idea of what I have done thus far.
P.S. I am using a "arduino iot 33 nano"
The ATT class is missing an end() function to clean up ATT variables. This end function then needs to be called inside BLELocalDevice::end().
Proposed function:
I set up my BLE as a peripheral and use it to stream data to an android device. The mobile requests data using an index (writes to a characteristic) and then my IoT33 nano has a data characteristic which it updates. The mobile app listens for change notifications on the data characteristic, and once it read it requests the next index. I am using a MTU of 242. This works ok but the Arduino seems to crash at some random points. From 10000 data requests it can crash at any point.
To address this I restart the BLE module by calling end() and then being(). I noticed that sometimes the MTU from the peers in ATT were not being cleared. After further investigation, I noticed there is some house keeping missing in ATT end() to clean all the _peers.
Not sure if this is an issue, but disconnect() should probably clean up all _peers even if HCI.disconnect(_peers[i].connectionHandle) does not return 0;