I was able to automatically connect to my phone (which was previously paired and trusted through bluetoothctl) using the following shell script and then creating a service that starts it automatically:
rfkill unblock bluetooth sleep 2 bluetoothctl << EOF connect XX:XX:XX:XX:XX:XX EOF sleep 2
I called the script setconnectBT.sh and made it executable with the command:
chmmod +x setconnectBT.sh
Then I created a service called setconblu.service in /lib/systemd/system/ which looked like this:
#!/bin/sh [Unit] Description=sets bluetooth and connects the board to a paired device [Service] ExecStart=/home/root/setconnectBT.sh Type=idle [Install] WantedBy=basic.target
Then you can enable it with:
systemctl enable setconblu.service
After you reboot your board, it should connect to your phone automatically.
hey .. thank for your help.
But this code is specific for the device address mentioned in the script.
How to configure it so that it automatically detects the available devices and can communicate with the connected device.
I tried this same code.
but it is not working for me.
can you guide me in detail step by step..?
thanks for your help.
But i think in my case the issue is with hciconfig hci0 up & hciconfig hci0 piscan coomand.
I am unable to connect bluetooth with these commannds manually also.
Can you tell me how to configure bluetooth with the help of hciconfig commands.
hey, my code is working now.
Thanks for your help
Great to hear Malay. If you ever encounter any other issue, don't hesitate to come back to the community.