-
Notifications
You must be signed in to change notification settings - Fork 210
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
Possible HCI.Poll() bug with _recvIndex and _recvBuffer #73
Comments
Hi @mattleesmi , |
Hello @polldo Yes, I am using a BLE and IoT, and it does seem similar to #102. I have stepped away from the work using the boards for a few months now but I hope to return to it soon so I can look this further as well as the #70 issue I have been encountering. I will report back when I can! Thank you for the input. |
Hello, Sorry for the very late update, I was running more tests on this and I am still getting crashes with the latest version with the same issues where _recvIndex is going above 258 and crashing at 533. I am testing a catch if statement under the while loop like this
It seems that somehow the else statement of void HCIClass::poll is being skipped somehow. Thanks, |
Hi @mattleesmi |
Hey @polldo So far I have only had this problem on the IoT's, as far as I can see my little tweak is working at the moment. Is that patch of IoT's too? If so how do I integrate it? Thanks |
No, it's a nano33ble specific patch. The BLE should be continuously updated, by executing void loop() {
BLE.poll();
....
} |
With my current code setup it is running about 140 polls per second (have been tracking it), is that too little? edit: I took a look again as I had switch it off for a bit, it still most gets around 140 or more although sometimes it dips to quite low numbers |
Small update: I was trying things out again and I found myself in a very noisy Bluetooth room that was causing very frequent crashes even with quite a lot of polls per second. I did a bit more digging in HCI.cpp and I found that one of the main causes what the poll was picking up ACL packets that were too big (this may be linked to the other stuff that has been mentioned with regards to the buffer not being read enough) So from what I have managed to understand is that this piece of code: So I put a separate if statement that looks like this:
With this, I would get results like: ACL too big: 21920. As you can see I tried to catch this and reset the index. This seems to work but there are still crashes. Anecdotally these crashes seem to happen when the code tries to handle the packet but I am not sure. A similar thing did occur with RX events but it was less frequent, although sometimes I did get large RX events like this:
Now I might be wrong but that feels like several events mashed up into one as most of the time they are between 45-150 characters and there is a hard limit of 246 (or thereabouts) in the reading capacity of the BLE #70 Is it possible that the if statements at the moment are not flexible enough to deal with data that is coming in "wrong"? I have uploaded the full HCI.poll that I have been playing with but I am sure that the issue is deeper than this. If this is of interest I can try to use the extra catches and see what it looks like when it still crashes. |
Hello,
I came across an occasional crash while using BLE/HCI.poll(). The crash occurs when _recvIndex goes above the size of _recvBuffer. The crash in my tests occurs when _recvIndex = 533.
I explained how I came across it in this Arduino forum post: https://forum.arduino.cc/index.php?topic=680797.0 but the long and the short of it is that it seems to happen after receiving an HCI_ACLDATA_PKT (possibly without being connected to anything) which leads to _recvIndex++ over and over without being caught and reset by the if statements and reset (not sure why). The basic fix I currently have running in HCI.cpp within the while (HCITransport.available()) loop is:
if (_recvIndex > 257) { _recvIndex = 0; if (_debug) { _debug->println(); _debug->println("***Overflow Catch***"); _debug->println(); } }
Not groundbreaking but seems to be stopping the crash.
The "overflow catch" is still occurring in my tests, however it may be something else. Please let me know if more information would help or if I am missing something obvious.
Thanks,
Matt
The text was updated successfully, but these errors were encountered: