Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

BUG - Can't change networks a second time #23

Open
doug62 opened this issue Jun 12, 2020 · 2 comments
Open

BUG - Can't change networks a second time #23

doug62 opened this issue Jun 12, 2020 · 2 comments

Comments

@doug62
Copy link

doug62 commented Jun 12, 2020

Bug: Unable to set network a second time.

Steps:

  1. Set a network - works
  2. Try to change/set another - it fails to change, retains initial setting
  3. Can set a second network if docker container is deleted - suspect that something is being persisted there.

Expect to be able to set connection several times:

@heyaphra
Copy link

heyaphra commented Aug 26, 2020

I am also experiencing this issue. The docs don't indicate whether there is an endpoint for disconnecting/reconnecting from a network. It's really important to be able to associate with different networks without completely killing the service.

UPDATE:

Just made a small pull request. It seems that initially enabling a network automatically associates the device, however, consecutive additions are only added to the config without connecting. I added a 5th step to the ConnectNetwork method that uses wpa_cli's select_network command to ensure it connects to the new network.

As an aside, it might also be useful to create a /disconnect endpoint.

@duffrecords
Copy link

I noticed a factor that can contribute to this. Over the course of testing, I've restarted the container many times and often found it would connect at first but subsequent attempts wouldn't work until I rebooted the device. It turns out the hardware device name had been incremented, so instead of phy#0 I had phy#3, thus the uap0 interface could not be created on top of it. Check if yours has changed with the iw dev command.

As a workaround, I added a parameter to the wificfg.json file that lets me specify the device name. I'm also using a shell script to update this value prior to starting the container.

diff --git a/iotwifi/commands.go b/iotwifi/commands.go
index 88fe8c7..ebd085c 100644
--- a/iotwifi/commands.go
+++ b/iotwifi/commands.go
@@ -36,7 +36,7 @@ func (c *Command) UpApInterface() {

 // AddApInterface adds the AP interface.
 func (c *Command) AddApInterface() {
-       cmd := exec.Command("iw", "phy", "phy0", "interface", "add", "uap0", "type", "__ap")
+       cmd := exec.Command("iw", "phy", c.SetupCfg.HostApdCfg.Phy, "interface", "add", "uap0", "type", "__ap")
        cmd.Start()
        cmd.Wait()
 }
diff --git a/iotwifi/types.go b/iotwifi/types.go
index b1074cb..04db1c9 100644
--- a/iotwifi/types.go
+++ b/iotwifi/types.go
@@ -20,6 +20,7 @@ type HostApdCfg struct {
        WpaPassphrase string `json:"wpa_passphrase"` // wpa_passphrase=iotwifipass
        Channel       string `json:"channel"`        //  channel=6
        Ip            string `json:"ip"`             // 192.168.27.1
+       Phy           string `json:"phy"`            // phy=phy0
 }

 // WpaSupplicantCfg configures wpa_supplicant and is used by SetupCfg

This is a kludge and I don't recommend doing this, which is why I'm not submitting it as a pull request, but it may be helpful to someone. Ideally, the code would detect the current device name but I'm not sure what would be the best way to handle the case where multiple wireless devices are present.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants