From ff1f01dc41da0731e4d540d83e257f419d56eec4 Mon Sep 17 00:00:00 2001 From: Adrian Batzill Date: Sun, 22 Sep 2024 10:59:59 +0100 Subject: [PATCH] make bluetooth init more robust --- __lib__systemd__system__stratux.service | 2 +- main/network.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/__lib__systemd__system__stratux.service b/__lib__systemd__system__stratux.service index 055ac69b8..24d24f734 100644 --- a/__lib__systemd__system__stratux.service +++ b/__lib__systemd__system__stratux.service @@ -1,6 +1,6 @@ [Unit] Description=Stratux -After=network.target +After=network.target bluetooth.target [Service] ExecStartPre=/opt/stratux/bin/stratux-pre-start.sh diff --git a/main/network.go b/main/network.go index 142cee143..050427751 100644 --- a/main/network.go +++ b/main/network.go @@ -382,9 +382,13 @@ func initBluetooth() { if len(globalSettings.BleOutputs) == 0 { return } - if err := bleAdapter.Enable(); err != nil { - addSingleSystemErrorf("BLE", "Failed to init BLE adapter: %s", err.Error()) - return + for { + if err := bleAdapter.Enable(); err != nil { + log.Printf("Failed to init BLE adapter: %s", err.Error()) + time.Sleep(5 * time.Second) + } else { + break + } } services := []bluetooth.UUID{} for _, conn := range globalSettings.BleOutputs {