I'm trying to automate a task to configure a bluetooth device when it's connected to my raspberry pi 3 running raspbian.
Assuming $x
is the address of the device, I need to execute the following commands after it connects:
hcitool enc $x off
hcitool sr $x slave
The initial bluetooth connection info (from running hcitool con
) looks like this:
Connections:
> ACL $x handle 11 state 1 1m MASTER AUTH ENCRYPT
And after running the above two commands, hcitool con
shows the desired state:
Connections:
> ACL $x handle 11 state 1 1m SLAVE AUTH
I was able to get a basic udev rule to execute a script, but it doesn't have the desired effect.
Here's the udev rule at /etc/udev/rules.d/99-slave.rules
SUBSYSTEM=="hidraw", RUN+="/home/pi/fix-bluetooth.bash"
And the script:
#!/bin/bash
hcitool con >> /tmp/hello_world
Then I tail -f /tmp/hello_world
and plug/unplug my bluetooth device and this is what I see:
Connections:
Connections:
Connections:
...
etc.
I've tried adding sleep
for a few seconds. I've tried adding sudo. I've tried it with multiple bluetooth devices attached. I can never get hcitool con
to output anything when executed as part of a udev rule.