I would like to start / stop bluetooth service automatically when I turn on / off rfswitch, is that possible ?
Start and stop bluetooth service automatically as rfkill switch changes
bluetooth
Related Solutions
The first problem occurs because Pulse Audio unloads the bluetooth module after startup, so even if you put it in your startup script, it still gets unloaded a few seconds later.
Solution A
Just add a startup delay in your script, something like:
sleep 10 && pactl load-module module-bluetooth-discover
Solution B (recommended)
- Disable the bluetooth/Pulse Audio plugin.
- Right click your bluetooth icon, select Plugins, then uncheck the Pulse Audio plugin.
- Restart.
Sorry, but I don't have a solution for your remaining two issues.
Just this evening I stumbled upon the "solution" (which I would characterize as a work-around for a peculiarity (bug?) in the rfkill command).
You have to use this command:
rfkill unblock all
Just unblocking bluetooth alone doesn't work as seen above.
root@lsb-hp6570b-deb:/home/jcxz100# rfkill block all
root@lsb-hp6570b-deb:/home/jcxz100# rfkill list
0: phy0: Wireless LAN
Soft blocked: yes
Hard blocked: yes
1: hp-wifi: Wireless LAN
Soft blocked: yes
Hard blocked: no
2: hp-wwan: Wireless WAN
Soft blocked: yes
Hard blocked: no
3: hp-gps: GPS
Soft blocked: yes
Hard blocked: no
4: hp-bluetooth: Bluetooth
Soft blocked: yes
Hard blocked: no
root@lsb-hp6570b-deb:/home/jcxz100# rfkill unblock all
root@lsb-hp6570b-deb:/home/jcxz100# rfkill list
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hp-wifi: Wireless LAN
Soft blocked: no
Hard blocked: no
2: hp-wwan: Wireless WAN
Soft blocked: no
Hard blocked: no
3: hp-gps: GPS
Soft blocked: no
Hard blocked: no
4: hp-bluetooth: Bluetooth
Soft blocked: no
Hard blocked: no
5: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
It seems rfkill sees the bluetooth radio as soft-blocked when listing but not when asked to unblock... thus is does nothing. But when the "all" target is used, it just goes ahead and changes the state of every radio without judging if they are already unblocked.
Best Answer
Yes. Assuming you have
udev
, something like the following would be a decent start:And then:
See the relevant man pages for more info ... you can do a lot with udev rules (although it can be a little overwhelming to learn).