Skip to content

Commit

Permalink
big difference between disable and disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
tvanriper committed Mar 24, 2022
1 parent 9d05942 commit 23a1a50
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions cmd/connectap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"strconv"
"time"

"github.com/tvanriper/go-wireless"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 23a1a50

Please sign in to comment.