txwifi
txwifi copied to clipboard
BUG - Can't change networks a second time
Bug: Unable to set network a second time.
Steps:
- Set a network - works
- Try to change/set another - it fails to change, retains initial setting
- 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:
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.
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.