Closed tomsturges closed 3 years ago
Raspberry Pis are weird, mine won't let me do bluetooth things as a non-root user so maybe that has something to do with it. If you install idasen controller as root:
sudo pip3 install idasen-controller
And then run the script as root:
sudo idasen-controller
Does that change anything?
Thanks, but no. I did as you suggested (and re-connected in bluetoothctl
as it had disconnected overnight) but it still cannot find the desk.
Ah so it seems that the mac_address must be uppercase. I have made the script uppercase it when reading from the config. Please update and let me know if that starts working (I think there is no need for sudo as your bluetoothctl works without it):
pip3 install --upgrade idasen-controller
I notice that update capitalising the MAC address now, but unfortunately I still have the same error (I checked with sudo too).
Is the mac address capitalised in the error?
(This now works on my RPi 3B running Raspbian)
Yes it is. I am on a RPi 4, I think also Raspbian (It is "Raspberry Pi OS with desktop and recommended software"). I will double check I really have the correct MAC address, maybe I made a mistake, or it has changed, I dunno.
Does running idasen-controller --scan
return anything?
Also what python version are you running on the pi?
pi@raspberrypi:~ $ python --version
Python 2.7.16
pi@raspberrypi:~ $ python3 --version
Python 3.7.3
idasen-controller --scan
returns a list of 10 devices, but none of them are the MAC address that bluetoothctl
tells me I am connected to (and has the Alias "Standing Desk")
Very confusing! Whats the output of hcitool dev
? Wondering if you somehow have two bluetooth adapters or something.
pi@raspberrypi:~ $ hcitool dev
Devices:
hci0 DC:A6:32:D3:FE:2D
Btw I could not connect to my desk with the Linak android app, so I disconnected my RPi using remove
inside bluetoothctl
and now I can connect again. So I'm pretty sure that's the correct MAC address.
Ahah! Now that I disconnected via bluetoothctl
, the desk is now found with idasen-controller --scan
. However I'm still having trouble connecting. I'll play a little bit and report back.
I've got everything basically the same as you:
➜ ~ python3 --version
Python 3.7.3
[bluetooth]# info E8:5B:5B:24:22:E4
Device E8:5B:5B:24:22:E4 (random)
Name: Desk 8932
Alias: Desk 8932
Paired: yes
Trusted: no
Blocked: no
Connected: no
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (99fa0001-338a-1024-8a49-009c0215f78a)
UUID: Vendor specific (99fa0010-338a-1024-8a49-009c0215f78a)
UUID: Vendor specific (99fa0020-338a-1024-8a49-009c0215f78a)
UUID: Vendor specific (99fa0030-338a-1024-8a49-009c0215f78a)
➜ ~ hcitool dev
Devices:
hci0 B8:27:EB:77:8C:03
➜ ~ idasen-controller --scan
Found 5 devices using hci0
E8:5B:5B:24:22:E4: Desk 8932
...
Except mine connects:
➜ ~ idasen-controller
Connected E8:5B:5B:24:22:E4
Height: 688mm
Disconnected
You could try adjusting the scan/connect timeouts and see if that helps? (I have noticed another bug that setting scan timeout from command line will not work so do that one in the config file).
Ok thanks I'll report back in a couple hours, need to head out.
Ok it works now! The (or one of the) problems was this...
I paired in bluetoothctl
using pair <MAC ADDRESS>
. It seems this would pair me, but also connect me, to the desk. So then idasen-controller
was unable to connect. So to fix I used disconnect <MAC ADDRESS>
in bluetoothctl
so that I am paired but not connected.
Perhaps you could update the README as it says "the desk should be connected and paired to the computer", whereas (at least with the RPi) it looks like it needs to be paired but NOT connected. Just a suggestion.
Thanks a lot for you help!
Glad its working. Interestingly on my pi it does not seem to matter if its connected in bluetoothctl or not but I will add it as a troubleshooting suggestion as you suggest.
Thanks for this Python code. It's the first one, which allowed me to control my desk.
I'd like to integrate this now into Homeassistant. However, before I start with this adventure, I'd need to resolve the following:
I only was able to use your code after I paired the desk in my Raspian on a PI3B. WIhtout pairing, I don't get it working at all. However, I don't now, how I could automate pairing in Python......
Any idea, how I could get your code work without prior pairing? Or alternatively, do you have a proposal, how pairing could be done with Python code?
Many thanks!
A couple of ways you could:
bluetoothctl
command from python using the os
or subprocess
modules.
Hi again!
So my Raspberry Pi is paired to my desk but when I type
idasen-controller
I get the errorCould not find desk e0:83:79:xx:xx:xx
(I added it to the config.yaml). I confirmed that I am paired by typingbluetoothctl
at the command line to open the Bluetooth Controller and then typedinfo e0:83:79:xx:xx:xx
which tells me:(I scrambled some info above with 'xxx'; I'm not sure what is safe to include online)