Skip to content

Adam-Software/bt_connect.service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

  1. README.md

markdown

Bluetooth Auto-Connect Service

Automatically connects to a specified Bluetooth device on system startup using bluetoothctl.

πŸ“¦ Prerequisites

  • Linux with bluetoothctl (typically included in bluez package)
  • Active Bluetooth adapter
  • Pre-paired target device

πŸ›  Installation

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

πŸ” Basic Checks

  1. Verify Bluetooth is active:
    rfkill list bluetooth
    sudo rfkill unblock bluetooth

Check device pairing status:

bluetoothctl
paired-devices

🚨 Common Issues

  1. 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
  1. 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
  1. 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
  1. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages