WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: RPi4, Bluetooth and devices on boot  (Read 3535 times)

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
RPi4, Bluetooth and devices on boot
« on: December 27, 2020, 07:24:27 PM »
Hello,

after a bit of fighting with my rpi, I've finally managed to connect a bluetooth keyboard to the system, and to initialize the BT subsystem on boot. WOHO!

Thank you everyone for the great guides. :)

For the question in the topic: How do I wait for the internal pi's bluetooth (as in a script) to be ready before powering it on with

Code: [Select]
bluetoothctl power on
also, will a paired device connect automatically if in range? Or I have to trigger something on the Pi?

Thank you in advance!

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1263
Re: RPi4, Bluetooth and devices on boot
« Reply #1 on: December 27, 2020, 07:40:20 PM »
normally you just have to turn on the "trust" for the device.

Done in bluetoothctl

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: RPi4, Bluetooth and devices on boot
« Reply #2 on: December 27, 2020, 07:41:50 PM »
Hi The_f3l1x
Maybe this is of some use:
http://forum.tinycorelinux.net/index.php/topic,24427.msg154846.html#msg154846
Be sure to read reply #8 too.

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
Re: RPi4, Bluetooth and devices on boot
« Reply #3 on: December 27, 2020, 07:52:59 PM »
Quote from: Rich
Hi The_f3l1x
Maybe this is of some use:
http://forum.tinycorelinux.net/index.php/topic,24427.msg154846.html#msg154846
Be sure to read reply #8 too.

normally you just have to turn on the "trust" for the device.

Done in bluetoothctl

Hi Paul, hi Rich, thank you for the quick replies.

@Rich: that's the guide I followed :)

@both: The whole initialization procedure works fine and if I get into bluetoothctl after a reboot the trusted status of the device seems to "stick", although not only it never connects automatically again, I seem to need to "power on" the internal BT again :/

any ideas?

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
Re: RPi4, Bluetooth and devices on boot
« Reply #4 on: December 27, 2020, 07:57:49 PM »
Just checked again (I thought I had missed a step) and just after boot if I do

Code: [Select]
bluetoothctl
and then

Code: [Select]
show
I get

Code: [Select]
...
Powered: no
...

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: RPi4, Bluetooth and devices on boot
« Reply #5 on: December 27, 2020, 08:20:25 PM »
Hi The_f3l1x
Based on this thread:
http://forum.tinycorelinux.net/index.php/topic,23895.0.html
It looks like the  bluetoothctl  command can power it up.

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
Re: RPi4, Bluetooth and devices on boot
« Reply #6 on: December 27, 2020, 08:28:40 PM »
Hi The_f3l1x
Based on this thread:
http://forum.tinycorelinux.net/index.php/topic,23895.0.html
It looks like the  bluetoothctl  command can power it up.

Hi Rich,

yeah, I found that topic too but it's talking about turning the power on manually, not automatically. I'm trying to get everything setup on boot, and I either need another way to turn on the card, or find some trigger that I can use in a script when the device firmware is loaded before i can power it on.

In my linux noobiness i tried

Code: [Select]
wc -l `bluetoothctl list`
but there's something I must be missing something 'cause[/s]

Solution found! I think I get a 1 on

Code: [Select]
bluetoothctl list | wc -l
when the device is ready to be powered up. I'll wait for that and trigger the power on. I

'll report back if it works for anyone with the same problem :)

Confirmed!
you can tell when to power up the internal BT card using bluetoothctl and wc :)

Now the problem of the keyboard not reconnecting on boot despite being trusted still remains..
Unless I need to persist something else other than /var/lib/bluetooth
« Last Edit: December 27, 2020, 08:43:39 PM by The_f3l1x »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: RPi4, Bluetooth and devices on boot
« Reply #7 on: December 27, 2020, 09:04:17 PM »
Hi The_f3l1x
The only thing I've done with Buetooth involved an old Asus netbook. The netbooks keyboard is Bluetooth. I think this command
turned it on:
Code: [Select]
sudo hciconfig hci0 up

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1263
Re: RPi4, Bluetooth and devices on boot
« Reply #8 on: December 27, 2020, 10:27:36 PM »
I guess I did not give away all my secrets in that previous outline.

bluetoothctl can run interactively or process commandline.  You do need to wait for the controller to populate before executing power up.

Code: [Select]
bluetoothctl power on

If you had more than one controller, it might be a bit more difficult.  Then you might want to play with dbus.....  This will also power on the controller.

Code: [Select]
gdbus call -y -d "org.bluez" -o "/org/bluez/hci0" -m "org.freedesktop.DBus.Properties.Set" "org.bluez.Adapter1" "Powered" "<true>"
« Last Edit: December 27, 2020, 10:29:36 PM by Paul_123 »

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
Re: RPi4, Bluetooth and devices on boot
« Reply #9 on: December 27, 2020, 10:30:58 PM »
Hi The_f3l1x
The only thing I've done with Buetooth involved an old Asus netbook. The netbooks keyboard is Bluetooth. I think this command
turned it on:
Code: [Select]
sudo hciconfig hci0 up

That seems a different way to turn on the internal BT card. I'll keep looking around but if I can't find anything else I guess I'll either have to go wired or trigger the connection differently, like on a timer. Thank you anyway :)

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1263
Re: RPi4, Bluetooth and devices on boot
« Reply #10 on: December 27, 2020, 10:32:51 PM »
I've run into auto connection issues before with audio devices.  Does powering up the keyboard after the system is booted and the controller is started work?


If not use a script to do the connection for you....

Offline The_f3l1x

  • Newbie
  • *
  • Posts: 6
Re: RPi4, Bluetooth and devices on boot
« Reply #11 on: December 27, 2020, 10:36:03 PM »
I guess I did not give away all my secrets in that previous outline.

bluetoothctl can run interactively or process commandline.  You do need to wait for the controller to populate before executing power up.

Code: [Select]
bluetoothctl power on

If you had more than one controller, it might be a bit more difficult.  Then you might want to play with dbus.....  This will also power on the controller.

Code: [Select]
gdbus call -y -d "org.bluez" -o "/org/bluez/hci0" -m "org.freedesktop.DBus.Properties.Set" "org.bluez.Adapter1" "Powered" "<true>"

Hi Paul,

I managed to power on the device on boot, since I'm planning on only having one BT card on this Pi my system works fine :)

I'm now trying to connect to the bt keyboard once the card is powered up, but I can't seem to find a way. It's both paired and trusted, even after a reboot, but no connection, even after power cycling the keyboard itself..

Would a infinite loop waiting for the keyboard to show up work?