From 23a1a502341148b1ce6fee880df7824c4bfdd1e5 Mon Sep 17 00:00:00 2001 From: Trey Van Riper Date: Thu, 24 Mar 2022 10:47:39 -0400 Subject: [PATCH] big difference between disable and disconnect --- cmd/connectap/main.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/connectap/main.go b/cmd/connectap/main.go index 5f1207d..2625015 100644 --- a/cmd/connectap/main.go +++ b/cmd/connectap/main.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "os" - "strconv" "time" "github.com/tvanriper/go-wireless" @@ -44,23 +43,20 @@ func main() { fmt.Printf("problems getting the current status: %s\n", err) os.Exit(1) } - if len(state.ID) > 0 { + + net := wireless.NewNetwork(ssid, pks) + + if len(state.IPAddress) > 0 { // Must disconnect first. fmt.Printf("Disconnecting from %s.\n", state.SSID) - id, err := strconv.Atoi(state.ID) + _, err = wc.Disconnect(wireless.NewNetwork(state.SSID, "")) if err != nil { - fmt.Printf("unable to convert %s to a number: %s", state.ID, err) + fmt.Printf("failed to disconnect network: %s\n", err) os.Exit(1) } - err = wc.DisableNetwork(id) - if err != nil { - fmt.Printf("failed to disable network: %s\n", err) - os.Exit(1) - } - // Give it a second, to help avoid conflicting messages. + // Pause for a bit to let messages run. time.Sleep(time.Second) } - net := wireless.NewNetwork(ssid, pks) fmt.Printf("Attempting to connect to %s...\n", ssid) _, err = wc.Connect(net)