From f64099b99d13ac94374e13cf46df91822e7354b9 Mon Sep 17 00:00:00 2001 From: kercre123 Date: Sun, 21 Apr 2024 23:07:57 -0500 Subject: [PATCH] Fix version on Android, extra error-handling in connectvector --- chipper/pkg/vars/vars.go | 3 ++ chipper/pkg/wirepod/setup/ble.go | 5 ++- chipper/pkg/wirepod/stt/vosk/Vosk.go | 7 +++- chipper/webroot/js/ble.js | 57 +++++++++++++++++----------- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/chipper/pkg/vars/vars.go b/chipper/pkg/vars/vars.go index bc7f0078..18c3c025 100644 --- a/chipper/pkg/vars/vars.go +++ b/chipper/pkg/vars/vars.go @@ -173,6 +173,9 @@ func Init() { Certs = join(podDir, "./certs") SessionCertPath = join(podDir, SessionCertPath) SavedChatsPath = join(podDir, SavedChatsPath) + if runtime.GOOS == "android" { + VersionFile = AndroidPath + "/static/version" + } os.Mkdir(JdocsDir, 0777) os.Mkdir(SessionCertPath, 0777) os.Mkdir(Certs, 0777) diff --git a/chipper/pkg/wirepod/setup/ble.go b/chipper/pkg/wirepod/setup/ble.go index 96624dd9..12524d36 100644 --- a/chipper/pkg/wirepod/setup/ble.go +++ b/chipper/pkg/wirepod/setup/ble.go @@ -275,7 +275,10 @@ func BluetoothSetupAPI(w http.ResponseWriter, r *http.Request) { err = ConnectVector(BleClient, id) if err != nil { fmt.Fprint(w, "error: "+err.Error()) - return + if err.Error() == "error: took more than 5 seconds" { + logger.Println("It took too long to connect to Vector. Quitting and letting systemd restart") + os.Exit(1) + } } fmt.Fprint(w, "success") return diff --git a/chipper/pkg/wirepod/stt/vosk/Vosk.go b/chipper/pkg/wirepod/stt/vosk/Vosk.go index 8d644760..4405efc1 100755 --- a/chipper/pkg/wirepod/stt/vosk/Vosk.go +++ b/chipper/pkg/wirepod/stt/vosk/Vosk.go @@ -6,6 +6,7 @@ import ( "log" "os" "path/filepath" + "runtime" "sync" "time" @@ -112,7 +113,11 @@ func runTest() { withGrm = false } rec, recind := getRec(withGrm) - pcmBytes, _ := os.ReadFile("./stttest.pcm") + sttTestPath := "./stttest.pcm" + if runtime.GOOS == "android" { + sttTestPath = vars.AndroidPath + "/static/stttest.pcm" + } + pcmBytes, _ := os.ReadFile(sttTestPath) var micData [][]byte cTime := time.Now() micData = sr.SplitVAD(pcmBytes) diff --git a/chipper/webroot/js/ble.js b/chipper/webroot/js/ble.js index 61f3af14..2cc2a590 100644 --- a/chipper/webroot/js/ble.js +++ b/chipper/webroot/js/ble.js @@ -18,6 +18,7 @@ function showBotAuth() { } function checkBLECapability() { + document.getElementById("disconnectButton").innerHTML = ""; updateAuthel("Checking if wire-pod can use BLE directly..."); fetch("/api-ble/init") .then((response) => response.text()) @@ -161,6 +162,14 @@ function ConnectRobot(id) { if (response.includes("success")) { CreatePinEntry(); return; + } else { + alert( + "There was an error connecting. WirePod will restart and this will return to the first screen of setup." + ); + updateAuthel("Waiting for WirePod to restart..."); + setTimeout(function () { + checkBLECapability(); + }, 3000); } }); } @@ -447,37 +456,41 @@ function DoAuth() { authEl.appendChild(document.createElement("br")); authEl.appendChild(m2); } else { - updateAuthel("Authentication was successful! How would you like to wake Vector up?"); + updateAuthel( + "Authentication was successful! How would you like to wake Vector up?" + ); wakeWithAnim = document.createElement("button"); wakeWithAnim.onclick = function () { - DoOnboard(true) + DoOnboard(true); }; wakeWithAnim.innerHTML = "Wake with wake-up animation (recommended)"; wakeWithoutAnim = document.createElement("button"); - wakeWithoutAnim.innerHTML = "Wake immediately, without wake-up animation"; + wakeWithoutAnim.innerHTML = + "Wake immediately, without wake-up animation"; wakeWithoutAnim.onclick = function () { - DoOnboard(false) + DoOnboard(false); }; - authEl.appendChild(wakeWithAnim) - authEl.appendChild(document.createElement("br")) - authEl.appendChild(wakeWithoutAnim) + authEl.appendChild(wakeWithAnim); + authEl.appendChild(document.createElement("br")); + authEl.appendChild(wakeWithoutAnim); } }); } function DoOnboard(wAnim) { - updateAuthel("Onboarding robot...") - fetch("/api-ble/onboard?with_anim=" + wAnim) - .then(() => { - fetch("/api-ble/disconnect"); - updateAuthel("Vector is now fully set up! Use the Bot Settings tab to further configure your bot."); - disconnectButtonDiv = document.getElementById("disconnectButton"); - disconnectButtonDiv.innerHTML = ""; - disconnectButton = document.createElement("button"); - disconnectButton.onclick = function () { - checkBLECapability(); - }; - disconnectButton.innerHTML = "Return to pair instructions"; - disconnectButtonDiv.appendChild(disconnectButton); -}) -} \ No newline at end of file + updateAuthel("Onboarding robot..."); + fetch("/api-ble/onboard?with_anim=" + wAnim).then(() => { + fetch("/api-ble/disconnect"); + updateAuthel( + "Vector is now fully set up! Use the Bot Settings tab to further configure your bot." + ); + disconnectButtonDiv = document.getElementById("disconnectButton"); + disconnectButtonDiv.innerHTML = ""; + disconnectButton = document.createElement("button"); + disconnectButton.onclick = function () { + checkBLECapability(); + }; + disconnectButton.innerHTML = "Return to pair instructions"; + disconnectButtonDiv.appendChild(disconnectButton); + }); +}