From 8894fbe5b2774930e192d19156630dfecc4a2f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B6per?= Date: Wed, 11 Sep 2019 13:59:00 +0200 Subject: [PATCH] Update wpacfg.go --- iotwifi/wpacfg.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/iotwifi/wpacfg.go b/iotwifi/wpacfg.go index b3a82cd..1598d53 100644 --- a/iotwifi/wpacfg.go +++ b/iotwifi/wpacfg.go @@ -65,7 +65,6 @@ func (wpa *WpaCfg) StartAP() { SetupCfg: wpa.WpaCfg, } - // note: we use wlan1 as ap instead command.RemoveApInterface() command.AddApInterface() command.UpApInterface() @@ -130,7 +129,8 @@ rsn_pairwise=CCMP` // ConfiguredNetworks returns a list of configured wifi networks. func (wpa *WpaCfg) ConfiguredNetworks() string { - netOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan").Output() + netOut, err := exec.Command("wpa_cli", "-i", " + ", "scan").Output() if err != nil { wpa.Log.Fatal(err) } @@ -143,7 +143,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { connection := WpaConnection{} // 1. Add a network - addNetOut, err := exec.Command("wpa_cli", "-i", "wlan0", "add_network").Output() + addNetOut, err := exec.Command("wpa_cli", "-i", "wlan1", "add_network").Output() if err != nil { wpa.Log.Fatal(err) return connection, err @@ -152,7 +152,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { wpa.Log.Info("WPA add network got: %s", net) // 2. Set the ssid for the new network - addSsidOut, err := exec.Command("wpa_cli", "-i", "wlan0", "set_network", net, "ssid", "\""+creds.Ssid+"\"").Output() + addSsidOut, err := exec.Command("wpa_cli", "-i", "wlan1", "set_network", net, "ssid", "\""+creds.Ssid+"\"").Output() if err != nil { wpa.Log.Fatal(err) return connection, err @@ -161,7 +161,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { wpa.Log.Info("WPA add ssid got: %s", ssidStatus) // 3. Set the psk for the new network - addPskOut, err := exec.Command("wpa_cli", "-i", "wlan0", "set_network", net, "psk", "\""+creds.Psk+"\"").Output() + addPskOut, err := exec.Command("wpa_cli", "-i", "wlan1", "set_network", net, "psk", "\""+creds.Psk+"\"").Output() if err != nil { wpa.Log.Fatal(err.Error()) return connection, err @@ -170,7 +170,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { wpa.Log.Info("WPA psk got: %s", pskStatus) // 4. Enable the new network - enableOut, err := exec.Command("wpa_cli", "-i", "wlan0", "enable_network", net).Output() + enableOut, err := exec.Command("wpa_cli", "-i", "wlan1", "enable_network", net).Output() if err != nil { wpa.Log.Fatal(err.Error()) return connection, err @@ -185,7 +185,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { for i := 0; i < 5; i++ { wpa.Log.Info("WPA Checking wifi state") - stateOut, err := exec.Command("wpa_cli", "-i", "wlan0", "status").Output() + stateOut, err := exec.Command("wpa_cli", "-i", "wlan1", "status").Output() if err != nil { wpa.Log.Fatal("Got error checking state: %s", err.Error()) return connection, err @@ -198,7 +198,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { // see https://developer.android.com/reference/android/net/wifi/SupplicantState.html if state == "COMPLETED" { // save the config - saveOut, err := exec.Command("wpa_cli", "-i", "wlan0", "save_config").Output() + saveOut, err := exec.Command("wpa_cli", "-i", "wlan1", "save_config").Output() if err != nil { wpa.Log.Fatal(err.Error()) return connection, err @@ -225,7 +225,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) { func (wpa *WpaCfg) Status() (map[string]string, error) { cfgMap := make(map[string]string, 0) - stateOut, err := exec.Command("wpa_cli", "-i", "wlan0", "status").Output() + stateOut, err := exec.Command("wpa_cli", "-i", "wlan1", "status").Output() if err != nil { wpa.Log.Fatal("Got error checking state: %s", err.Error()) return cfgMap, err @@ -256,7 +256,7 @@ func cfgMapper(data []byte) map[string]string { func (wpa *WpaCfg) ScanNetworks() (map[string]WpaNetwork, error) { wpaNetworks := make(map[string]WpaNetwork, 0) - scanOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan").Output() + scanOut, err := exec.Command("wpa_cli", "-i", "wlan1", "scan").Output() if err != nil { wpa.Log.Fatal(err) return wpaNetworks, err @@ -267,7 +267,7 @@ func (wpa *WpaCfg) ScanNetworks() (map[string]WpaNetwork, error) { time.Sleep(1 * time.Second) if scanOutClean == "OK" { - networkListOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan_results").Output() + networkListOut, err := exec.Command("wpa_cli", "-i", "wlan1", "scan_results").Output() if err != nil { wpa.Log.Fatal(err) return wpaNetworks, err