-
Notifications
You must be signed in to change notification settings - Fork 159
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
Disconnection event received immediately after Connection on Raspberry Pi 3 B+ #62
Comments
I added 250 msec delay after connection and the issue has gone. Sounds silly but works.
|
Hey @endrelovas thanks for the feedback |
Honsetly I cannot ellaborate any further as I pasted my source as well. I added 250 msec delay before every command I execute. This should not be the solution imho but it seems to work. |
I've been conducting some testing, and my code seems to work the same with and without the 250ms delay. |
To restart this thread a bit: I start to suffer as you do on a Raspi 4. Random disconnections. Honestly I start to be frustrated a bit on this issue as we are at the end of a project and the test shows your experience. Have you resolved meanwhile? |
@javiermelendezc playing a bit: no need to execute discoverServices at all. Just connect and you will get an instant disconnect. You probably have the feeling that you are getting the disconnect at that message but without calling it I end up with an immediate disconnection. Furthermore: the peripheral won't consider it as a connection neither. It seems to be a false positive connection followed by a false negative disconnection message. Quite disturbing and the codes are in hcidump -R as well (04 05 04 00 40 00 3E) meaning that 04 05 => disconnected. Looking into BluetoothHciSocket.cpp there is an if statement, exactly for this, under BluetoothHciSocket::kernelDisconnectWorkArounds.
I do not know what this does here but it seems that it closes the connection. |
This may be related: noble/node-bluetooth-hci-socket#39 |
Hey @endrelovas |
@javiermelendezc Since that I made a step forward. All I do is I wait 250 msec prior to send the next command. If connection falls I just reconnect. I made a counter up to 5 tries. Worst was 2 attempts (cycles) so far. I tried about 100 connection now. |
Seems so yes! |
Is this specific to any (others) adapters ? |
I haven't tried any external adapters. other than my Macbook Air and the Raspberry Pi 3 B+. |
I have no idea to be honest. This was the end of the communication in hcidump. I beleive the issue is shown on the 5th bottom line. 0405 = disconnected. Not sure where it became connected, perhaps 040E two lines above?
|
@endrelovas have you tried with a different version of Raspbian or another Raspberry Pi model?, I don't have any other board on hand. |
@javiermelendezc I tried on Raspi3 and Raspi4. AFAK they have different BT adapters. |
I tried on Raspi3 and Raspi4. AFAK they have different BT adapters.
I tried to make a recursive approach: keep connecting if 250 msec is not engough. It resolved some of my issues but after a while it broke apart.
Frankly I do not have the knowledge to interpret hcidump correctly. I just try to narrow down the issue to those who understand what to do. I try to find the purpose of BluetoothHciSocket::kernelDisconnectWorkArounds (@rzr perhaps you can explain?) If I understand I may try to modify the C++ code so the PI gets connected. Asking because the problem is not related to discoverServices for sure. |
Indeed, the problem is not related to discoverServices call, and as we've seen is a false "connection-disconnection" coming from the adapter. I just changed the title to reflect that.
Great work at digging into the problem @endrelovas , Thanks! |
I am having the same exact problem. However the connections are real. I'm testing the peripheral-explorer.js example and connecting to an ESP32 that blinks slowly when a connection is made and quickly when the connection is broken. I'm trying to pair the two so that the esp32 may NOTIFY the Ubuntu/Raspberry Pi 4 when a sensor value changes. Has a solution been found or have any of you considered switching to Bluepy? |
Hey @devorrah , sorry for the late response. I haven't reached a proper solution for this.
Looking forward to read what you did to get over this. |
I would like to share similar experience. I also worked around it. If this immediate-disconnect persists, the program quits and the calling script would reset the bluetooth by doing hciconfig down and up. I noticed something interesting. This problem happens on Raspian Buster but I have not seen this on Ubuntu Core 18. |
I'm currently trying to connect to one of my peripherals using @abandonware/noble,
As soon as a connection is established, i call discoverServices() and most of the time the connection falls immediately.
I use event-based transitions using Statecharts, so I'm sure there's no overlapping of commands during the connection.
It's totally related to:
noble#465
Where some people think it's because BLE and WiFi are on the same chipset on RPi 3B+ and RPi Zero. Although these boards work well on bluepy according to someone on the thread. So I think the problem it's related to hci.
Any ideas on how to solve this?
The text was updated successfully, but these errors were encountered: