Closed aienabled closed 3 years ago
Hey,
Thanks for the suggestion, I'll make it clear that it currently only works for Linux/Mac in the README.
I might also have a play with getting it running on Windows, so I will leave this issue open for now. I will need to swap in a different Bluetooth library, maybe I can get one running that works on all platforms.
I've made a branch bleak
(In progress PR #6) that switches the BLE library from gatt-python
to bleak
which should work on Linux, Windows, Mac.
My experience with it so far is it seems to work quite well on Windows, but seems flakey on Linux. It seems to often leave the connection in a bad state so it can't reconnect. I'm not used to asyncio
though so it's possible I'm not using it correctly.
I will continue playing around with it but you can try the bleak
branch on Windows now, feedback welcome.
Thank you very much, @rhyst!
I've tried bleak
branch and can confirm that it works fine under Windows 10 (1909).
Some notes:
python
instead of python3
.So now it works fine and I can drive the desk to the desired height. I've created a separate ticket regarding the drive precision problem https://github.com/rhyst/idasen-controller/issues/7 .
Regards!
UPD. If anyone curious, here is my AutoHotkey script to drive the desk to stand and sit mode by pressing Ctrl+Alt+Shift+Up or Down arrow respectively: (you can change arrows to PgUp PgDn but in my case, these shortcuts are already taken for other actions)
;Idasen Desk - Stand
^!+Up::Run "C:\Users\...\Desk - Stand.lnk"
;Idasen Desk - Sit
^!+Down::Run "C:\Users\...\Desk - Sit.lnk"
(I've created shortcut files on the desktop but it's not necessary and could be simple python
calls)
Hi @rhyst
I created a scan feature which works with --scan ADAPTER_NAME
parameter. I used qatt module for this.
If you like this feature let me know and I'll rewrite it with bleak
@aienabled Thanks! I'll add a set up / troubleshooting page I think to record useful tips and add. Possibly a "recipes" dir as well for things like your autohotkey setup and my albert config.
@rpdswtk Very happy to accept a PR. And if you have feedback on if the bleak branch works on Linux for you that would be very helpful and useful to decide whether I want to switch everything to bleak or maintain two different scripts. Bleak seems a bit slower to connect and I'm not 100% confident in the disconnect :grimacing:
Started testing using Ubuntu 20.04 with no connection issue, but feels definitely slower.
I am a Windows user using WSL2 and not really familiar with python... I try to use it with bleak branch. I have to manually install bruez because when I run python3 main.py it gives me error cannot find bluetoothctl. Also there is a typo on README.md. blueoothctl > bluetoothctl.
I still cannot get it working. when I want to get Device MAC addresses with bluetoothctl it shows
Waiting to connect to bluetoothd...dbus[4599]: arguments to dbus_connection_get_object_path_data() were incorrect, assertion "connection != NULL" failed in file ../../../dbus/dbus-connection.c line 5905.
This is normally a bug in some application using the D-Bus library.
D-Bus not built with -rdynamic so unable to print a backtrace
[1] 4599 abort bluetoothctl
if I run python3 main.py --monitor I get
Connecting
Traceback (most recent call last):
File "main.py", line 220, in run
await client.connect()
File "/home/roy/.local/lib/python3.8/site-packages/bleak/backends/bluezdbus/client.py", line 92, in connect
device = await BleakScannerBlueZDBus.find_device_by_address(
File "/home/roy/.local/lib/python3.8/site-packages/bleak/backends/bluezdbus/scanner.py", line 248, in find_device_by_address
return await scanner._find_device_by_address(
File "/home/roy/.local/lib/python3.8/site-packages/bleak/backends/scanner.py", line 99, in _find_device_by_address
await self.start()
File "/home/roy/.local/lib/python3.8/site-packages/bleak/backends/bluezdbus/scanner.py", line 93, in start
self._bus = await client.connect(self._reactor, "system").asFuture(loop)
twisted.internet.error.ConnectError: An error occurred while connecting: Failed to connect to any bus address. Last error: An error occurred while connecting: 2: No such file or directory..
Disconnected
Plesae help..
Hey @zeroarst, have you tried using the repo in Windows without WSL? The fact that you are having issues in bluetoothctl
suggests this is beyond the scope of this script to fix, I have no idea if Bluez works at all in WSL.
I've pushed a small change that works around a bug where bleak does not use the specified adapter when scanning/connecting. This allows me to use a different Bluetooth adapter which seems to work more consistently.
It also allows you to specify a scan_timeout
which I have found works when set to 1
and makes it feel much quicker. If it keeps working for me I think I'll merge it soon.
@aienabled
May I ask you what did you get it working on Windows, through the Windows Command line?
I tried to use git bash seem better but still getting errors.... I am not familiar with python it seems the exception is from colon symbol...variable cannot be declared with type..? my python version
When I run python main.py
And I looked at the source code of bleak...
Really want to get this working on Windows.
Merged the bleak branch with master.
Hello, as far as I've researched python3-dbus is not available for Windows as it's intended only for Linux and Mac. I wish to know if there is a workaround. If not, perhaps it would be best to mention this in the README file.
Regards!