- README.md
markdown
Automatically connects to a specified Bluetooth device on system startup using bluetoothctl
.
- Linux with
bluetoothctl
(typically included inbluez
package) - Active Bluetooth adapter
- Pre-paired target device
git clone https://github.com/yourusername/bluetooth-auto-connect.git
cd bluetooth-auto-connect
chmod +x scripts/bt_connect.sh
sudo cp scripts/bt_connect.sh /usr/local/bin/
sudo cp systemd/bluetooth-auto-connect.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now bluetooth-auto-connect.service
β Configuration Edit MAC address in:
nano scripts/bt_connect.sh # Change DEVICE_MAC value
π Documentation Troubleshooting Guide
Systemd Service Reference
π€ Contributing Fork the repository
Create your feature branch
Commit changes
Push to the branch
Open a pull request
π License MIT License
2. TROUBLESHOOTING.md
# Troubleshooting Guide
- Verify Bluetooth is active:
rfkill list bluetooth sudo rfkill unblock bluetooth
Check device pairing status:
bluetoothctl
paired-devices
π¨ Common Issues
- Connection Timeout Symptoms: Service starts but device doesn't connect Solutions:
Increase wait time in service file:
ExecStartPre=/bin/sleep 30 # Increased from 20
Manual connection test:
echo -e "connect XX:XX:XX:XX:XX:XX\nquit" | bluetoothctl
- Service Failure Symptoms: Service crashes repeatedly Debug steps:
journalctl -u bluetooth-auto-connect.service -f -n 50
sudo systemctl reset-failed bluetooth-auto-connect.service
- Permission Issues Fix:
sudo chown root:root /usr/local/bin/bt_connect.sh
sudo chmod 755 /usr/local/bin/bt_connect.sh
3. scripts/bt_connect.sh
#!/bin/bash
# Bluetooth auto-connect script
DEVICE_MAC="XX:XX:XX:XX:XX:XX" # Replace with your device's MAC address
echo -e "connect $DEVICE_MAC\nquit" | bluetoothctl
- systemd/bluetooth-auto-connect.service
[Unit]
Description=Bluetooth Auto-Connect Service
After=bluetooth.target network.target
Requires=bluetooth.service
[Service]
Type=simple
ExecStartPre=/bin/sleep 20
ExecStart=/usr/local/bin/bt_connect.sh
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target