Last active
May 2, 2025 21:44
Revisions
-
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ targets=( ) function try_target() { if eval $2 then echo "Target $1 (check: $2) -> check true, trying to connect"; bluetoothctl connect "$1"; -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ delay=10 # Pairs of [bluetooth MAC, test expression] targets=( "98:B6:E9:47:F0:4F" "test ! -e /dev/input/js0" "98:B6:E9:72:6C:31" "test -z \"\$(bluetoothctl info 98:B6:E9:72:6C:31 | grep 'Connected: yes')\"" ) function try_target() { -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ git clone https://gist.github.com/bc178789a441ce73b51e1e0637393aac.git bluetooth sudo chmod +x bluetooth-reconnect # Edit `bluetooth-reconnect` file according to your needs. Try if it works with ./bluetooth-reconnect sudo cp bluetooth-reconnect /usr/bin sudo cp bluetooth-reconnect.service /etc/systemd/system sudo systemctl enable bluetooth-reconnect sudo systemctl start bluetooth-reconnect # Check if it's alive -
AndBondStyle revised this gist
Apr 12, 2023 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ delay=10 # Pairs of [bluetooth MAC, test expression] targets=( "98:B6:E9:47:F0:4F" "test ! -e /dev/input/js0" "98:B6:E9:72:6C:31" "test -z \"$(bluetoothctl info 98:B6:E9:72:6C:31 | grep 'Connected: yes')\"" ) function try_target() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Inspired by [bluetooth-autoconnect](https://github.com/jrouleau/bluetooth-autoconnect), but much simplier and actually works. Based on systemd service (daemon) which does the following, repeatedly: 1. Run check command (e.g. check if device exists). If it returns zero, continue. 2. Try to run `bluetoothctl connect <MAC>`. No checks if bluetooth is on, etc. Dead simple. 3. Sleep for `delay` seconds (configurable). -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # Miminum delay between iterations, in seconds delay=10 # Pairs of [bluetooth MAC, test expression] targets=( "98:B6:E9:47:F0:4F" "test ! -e /dev/input/js0" "98:B6:E9:72:6C:31" "test ! -e /dev/whatever" -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 0 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,20 +33,3 @@ do sleep $loop_delay last_time=$(date +%s) done -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,8 @@ delay=10 # Odd index: bluetooth MAC, even index: test expression targets=( "98:B6:E9:47:F0:4F" "test ! -e /dev/input/js0" "98:B6:E9:72:6C:31" "test ! -e /dev/whatever" ) function try_target() { -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # bluetooth-reconnect Inspired by [bluetooth-autoconnect](https://github.com/jrouleau/bluetooth-autoconnect), but much simplier and actually works. Based on systemd service (daemon) which does the following, repeatedly: 1. Check activation condition. In my case, just check if `/dev/something` does not exist. 2. Try to run `bluetoothctl connect <MAC>`. No checks if bluetooth is on, etc. Dead simple. -
AndBondStyle revised this gist
Apr 12, 2023 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,15 @@ Inspired by [bluetooth-autoconnect]([url](https://github.com/jrouleau/bluetooth- ## How to install ``` git clone https://gist.github.com/bc178789a441ce73b51e1e0637393aac.git bluetooth-reconnect && cd bluetooth-reconnect sudo chmod +x bluetooth-reconnect # Edit `bluetooth-reconnect` file according to your needs. Try if it works with ./bluetooth-reconnect sudo cp bluetooth-reconnect /usr/bin sudo cp bluetooth-reconnect/bluetooth-reconnect.service /etc/systemd/system sudo systemctl enable bluetooth-reconnect sudo systemctl start bluetooth-reconnect # Check if it's alive sudo systemctl status bluetooth-reconnect ``` ## References -
AndBondStyle created this gist
Apr 12, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ #!/bin/bash # Miminum delay between iterations, in seconds delay=10 # Odd index: bluetooth MAC, even index: test expression targets=( "98:B6:E9:47:F0:4F" "test ! -f /dev/input/js0" "98:B6:E9:72:6C:31" "test ! -f /dev/whatever" ) function try_target() { if $2 then echo "Target $1 (check: $2) -> check true, trying to connect"; bluetoothctl connect "$1"; else echo "Target $1 (check: $2) -> check false, skipping" fi } last_time=$(date +%s) while true do # seq args: <start> <step> <end> for i in $(seq 1 2 ${#targets[@]}); do try_target "${targets[i-1]}" "${targets[i]}" done curr_time=$(date +%s) elapsed=$((curr_time - last_time)) loop_delay=$((elapsed>delay ? 0 : (delay-elapsed))) echo "Loop finished, sleeping for $loop_delay sec" sleep $loop_delay last_time=$(date +%s) done function try_target() { if $2 then echo "Target $1 (check: $2) -> check true, trying to connect..."; bluetoothctl connect "$1"; else echo "Target $1 (check: $2) -> check false, skipping" fi } # seq args: <start> <step> <end> for i in $(seq 1 2 ${#targets[@]}); do try_target "${targets[i-1]}" "${targets[i]}" done echo "All targets processed" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ [Unit] Description=Bluetooth reconnect service Before=bluetooth.service [Service] ExecStart=/usr/bin/bluetooth-reconnect [Install] WantedBy=bluetooth.service This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ # bluetooth-reconnect Inspired by [bluetooth-autoconnect]([url](https://github.com/jrouleau/bluetooth-autoconnect)), but much simplier and actually works. Based on systemd service (daemon) which does the following, repeatedly: 1. Check activation condition. In my case, just check if `/dev/something` does not exist. 2. Try to run `bluetoothctl connect <MAC>`. No checks if bluetooth is on, etc. Dead simple. 3. Sleep for `delay` seconds (configurable). ## How to install ``` // TODO ``` ## References - How `test` command works: https://www.computerhope.com/unix/test.htm - How to loop with equal invervals: https://unix.stackexchange.com/a/214660