diff --git a/bluetooth.go b/bluetooth.go index dd3cc09..b935a7c 100644 --- a/bluetooth.go +++ b/bluetooth.go @@ -3,7 +3,6 @@ package main import ( "context" "errors" - "strings" "github.com/mrmarble/improv/improv" "tinygo.org/x/bluetooth" @@ -150,10 +149,9 @@ func configureWIFI(args []string, errorHandler bluetooth.Characteristic, statusH } if output != "" { infoln("Wifi command output:", output) - lines := strings.Split(output, "\n") - lastLine := lines[len(lines)-1] - if strings.HasPrefix(lastLine, "http") { - rpcResultHandler.Write(protocol.BuildImprovResponse(improv.COMMAND_WIFI_SETTINGS, []string{lastLine})) + url := findUrl(output) + if url != "" { + rpcResultHandler.Write(protocol.BuildImprovResponse(improv.COMMAND_WIFI_SETTINGS, []string{url})) } } } else { diff --git a/utils.go b/utils.go index 79199f6..df0678c 100644 --- a/utils.go +++ b/utils.go @@ -48,3 +48,12 @@ func debugln(args ...string) { func errorln(args ...string) { println("[ERROR]", strings.Join(args, " ")) } + +func findUrl(str string) string { + for _, line := range strings.Split(str, "\n") { + if strings.HasPrefix(line, "http") { + return strings.TrimSpace(line) + } + } + return "" +}