-
Notifications
You must be signed in to change notification settings - Fork 44
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
Only first BT packet received when message is cut because of packet size limit #21
Comments
Ok, I could dig a little bit more into the issue. I set the BLE service in debugger mode and could see the logs from the Seems that BLE cuts messages into parts due to packet size limitations and for some reason, most of the times I'm receiving only one of those parts (see below). Why is that happening? Is it a code issue or rather a hardware limitation that the phone is sending the two packets too close in time and one is being lost? |
Might have something to do with the configuration of the Gatt server Scan response as mentioned here: https://stackoverflow.com/questions/46847750/raspberry-pi3-ble-as-central-device-receiving-just-one-packet-per-connection-int |
Ok, new update: Bluetooth is correctly receiving all the packets, I could check it by using the utility btmon. Everytime I send a problem, the full array of holds is received, but I guess some of them are lost in the dbus process and the application only sees some of them. I'm starting to investigate the dbus with dbus-monitor. I would appreciate any help. Thank you. |
I've tried multithreading for the problems processing to check if it was a performance issue. `class ProblemWorker(threading.Thread):
class MoonApplication(dbus.service.Object):
` Same behavior... |
Short analysis of BT packet timing. I sent the same problem several times, one that I know that occupies 2 packets and measured time difference between the first and second packet (by using btmon). Then, the right columns show if each packet was received. Note that I did not receive so many correct problems in a row, I cut some of the failing attempts to have more positive samples in the image. Main conclusions:
|
Did you try to play with the connection timings, i.e.: Approach 1 (maybe not working?):
Approach 2 (maybe working):
|
I already tried both without success (well maybe for the first one I did not use those exact params, will give it a try). Anyway, I would say that the Bluetooth connection interval has nothing to do, as I am correctly receiving all the packets (I can see them with btmon). I suspect that the data loss happens from the BLE to the UART. At this point, I think that it is a UART buffering problem. I'm not familiar with how the internal implementation is dealing with UART RX buffer when a new data arrives without the previous one having been processed. |
As he mentioned, i used the "echo 6 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval" Method, because i have the same issue as you. |
I'm using Android. I just tried the "echo 6 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval" and nothing changed. Then I noticed that this is overwritten upon connection, so I included it in the code to be done everytime and now: Surprise! It actually improved a little bit. But as @Friesi said, still many packets lost. I still don't fully understand why with btmon I see all the packets. |
As reading this now, i think i have never tried to set it to 1 because i read that the minimum time is 7,5ms (so 6). But maybe it is working? Did you try this? |
It was worth it to give it a try. But unfortunately, I get |
Problem with bluetooth is more complex. |
That's really disappointing. Any chances that we can work on the BLE app implementation to try to improve this situation? I'm not very familiar with it yet, but would be glad to try to collaborate. @8cH9azbsFifZ @marcelbesoeu @e-sr |
It looks like the Moonboard app itself is quite problematic -> https://www.reddit.com/r/climbharder/comments/eryae9/android_moonboard_app_problems/ I would love to see the moonboard team making the app open source... |
All packets are trasmitted from phone to RPI Bluetooth what we can see on BTMON, but only first packet is received on DBUS. Maybe there is another way to monitor BT transmission (catch and parse BTMON console output ???) |
I like the idea. Will give it a try this afternoon! |
Maybe the BT problem is old "ble/gatt_base" code? I found project: https://punchthrough.com/creating-a-ble-peripheral-with-bluez/ . Final code looks much simplier. |
I went through the code in that project and it contains the same elements as the gatt_base folder. The only difference is that they put all the classes in a single file in there. |
UPDATE! I implemented a parser for the btmon output and could make it work, now I receive 100% of packets! It was a bit tricky because the stdout was being buffered and I had to force it to unbuffer by implementing a custom class for streaming the data. Huge thanks to @marcelbesoeu for the suggestion :D You can find it in my fork of the moonboard app. If the feedback is good, I will issue a Pull Request to the original repo. |
Merged the commit into my fork - first test looks fine with my setup. |
I have an issue when sending problems to the Raspberry. I have to click the button at the app many times until it gets displayed to the leds. I started troubleshooting and added a print in the BLE service to see the raw received messages.
The problem is that most of the received messages are indeed None, see the screenshot below:
Over 20 attemps for 1 problem...
I'm using Raspberry Pi Zero and internal Bluetooth with clean installation and Moonboard app in Android device.
Please let me know if you need more info. Any clues on what could be happening?
Thank you in advance!
The text was updated successfully, but these errors were encountered: