-
Notifications
You must be signed in to change notification settings - Fork 295
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
Spontaneous disconnection after a few seconds #1198
Comments
Can you please try the branch from #1143? |
I tried that and got the same result. I downlaoded the code from that branch from here, pasted the folder on the same folder as my script, uninstalled bleak (but not bleak-winrt, which still is 1.2.0) and ran the script again, to the same result. I also noticed I was running an example from master, instead of develop, so it was kind of outdated. Now I pulled the example code from develop, but still got the same result. |
If you got the exact same logs, then you did not run the correct code. The pull request branch should no longer have "restarting get services due to services changed event" in the logs. |
Well yes, by the same result I meant that it crashes with the same message at the same moment. Here are the logs
Edit: I also tried communicating with a device that has Just Works security enabled and it works, these are the logs:
|
I debugged a little bit with Wireshark and Pycharm. Perhaps you already knew this, but I found that when this line is reached: From the Wireshark log, the disconnect starts from the Host as an HCI_CMD to the controller. So it looks like the windows host code is deciding to disconnect, but I'm not sure why. |
Can you share the wireshark logs? |
Sure, cap1.zip. I tried one more thing: I changed the firmware on the nRF to support pairing and bonding again, and it started working with 0.19.5. So that seems to be the difference that breaks it. We have worked without pairing before, using the dotnet backend in windows, I believe, so this should be possible, as far as I know. We need this device to work without pairing, so enabling pairing is just a workaround for now. |
Hi again! Have you had a chance to look at this? Were the logs helpful? Is there any more input I can provide? Like logs or tests, etc.? Or perhaps a workaround to try? Thanks! |
Does this still happen with the current |
So now it's working with the develop branch, with the "bleak-winrt-fix-leaking-services" branch I had pulled on 2023/01/11 and with the 0.19.5 installed with pip. I was just running the "enable_notifications.py" example, nothing fancy. The firmware on the nordic chip is the same as before, a few custom characteristics without pairing or security. Might have been a Windows issue? I'll update again if I can reproduce it. |
Meeting the same problem, and I have no idea about this. I think it's caused by Windows issue too. If you have any progress about this, please tell me. |
It's possible, I've encountered several issues that go away after a reset or a driver update. I have an Intel AX201, and the bluetooth driver version is 22.190.0.2. Perhaps try updating? My other suspicion is regarding the Windows resgistry. Many times "Remove Device" from the control panel is not enough and some traces are left in the registry or somewhere else and some information persists. It could be possible that, since Windows had been paired before to the same MAC address, it still believed that it needed pairing/security and it encountered a discrepancy with the device capabilities (which didn't suppor security anymore), so it aborted the connection. Cleaning the registry manually, resetting the PC and even trying on a different PC that hasn't ever been paired with the device could be helpful. |
So far, most people who have reported problems on Windows and included Bluetooth radio info have mentioned they have an Intel Bluetooth chip. |
Unfortunately, I tested the same code on another device with a Realtek BT Adapter, and that seems runs into the same situation. |
You haven't shared any code. Are we sure that the code isn't just telling the device to disconnect in your case (e.g. using the BleakClient context manager with nothing to keep it waiting)? |
import asyncio
import platform
import sys
import logging
from bleak import BleakClient
from bleak.uuids import uuid16_dict
from bleak.backends.winrt.client import logger as bleak_log
ADDRESS = (
"70:66:55:26:8B:0C"
if platform.system() != "Darwin"
else "B9EA5233-37EF-4DD6-87A8-2A875E821C46"
)
uuid = "00002a1c-0000-1000-8000-00805f9b34fb"
def temper_callback(sender: int, data: bytearray):
temperture = int.from_bytes(data[1:5], sys.byteorder)
print(f"{sender}: {temperture}")
def disconnected_callback():
print("device disconnected!")
async def main(address):
bleak_log.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('---BLEAK:%(levelname)s %(message)s'))
bleak_log.addHandler(ch)
bleak_log.disabled = False
async with BleakClient(address, winrt=dict(use_cached_services=True)) as client:
print(f"Connected: {client.is_connected}")
client.set_disconnected_callback(disconnected_callback)
await client.start_notify(uuid, temper_callback)
await asyncio.sleep(1000)
await client.stop_notify(uuid)
if __name__ == "__main__":
asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS)) In my case, I just start a indication that callback every time a temperature data is generated. As you can see, I use a All logs are also attached below.
|
You could try logging Bluetooth packets to see what triggers the disconnect, it could be either the remote device or Windows. |
Description
I'm trying to connect to a BLE peripheral implemented on an nRF device. I'm able to connect, but then the connection drops after about 4 seconds, every single time.
The nRF peripheral supports BLE 5, 2M PHY and is configured without security, i.e. characteristics are open, no pairing or bonding is required or supported.
What I Did
I started running old communication scripts that used to run on bleak 0.12, and at first it seemed to work, but only when the whole thing lasted less than a few seconds. Longer scripts started failing because of the disconnection.
After that, I tried running the example scripts from the repo and got the same problem in all of them. For example, the
enable_notifications.py
script is very similar to what our communication scripts do, so I ran that one, and it crashes because it loses connection before getting to thestop_notify
call.Connecting from nRF Connect on my phone works without issue.
As an added note here, which may or may not be relevant, Bleak 0.12 used to work fine with our device while it supported pairing. When I removed the security, it stopped working (it never connects). So I started moving to newer versions, but none of them seemed to work, until 0.19.5. This one does connect, but has this spontaneous disconnection issue.
Logs
Here's the output of running the
enable_notifications.py
script, with the custom MAC address and characteristic UUID.Here's the output of the nRF firmware. The disconnection reason, 0x13, only means that the PC ended the connection, but it adds no further information.
Thank your for your time!
The text was updated successfully, but these errors were encountered: