Rehan

Rehan

Adding new wifi without discarding existing

Hello,
I’m working on wlan with vintagenet.
I’m able to configure the interface for using multiple networks, however if i want to add new network, existing networks are discarded, is there any way to add new wifi without discarding existing ones?
This is how i configure 2 wifi networks, device is able to connect to whichever is available

VintageNet.configure("wlan0", %{
       type: VintageNetWiFi,
       vintage_net_wifi: %{
         networks: [
           %{
             key_mgmt: :wpa_psk,
             psk: <psk>,
             ssid: "TEST1"
           },
           %{
             key_mgmt: :wpa_psk,
             psk: <psk>,
             ssid: "Hotspot1"
           }
         ]
       },
       ipv4: %{method: :dhcp}
     })

Now if i try to add one more network using VintageNet.configure() existing networks are discarded. Any suggestion is welcomed
Regards,

Marked As Solved

seb3s

seb3s

Hi,
something like this should help:

 @wifi_ifname "wlan0"
 
 def get_wifi_config, do: VintageNet.get_configuration(@wifi_ifname)

 def configure_wifi(%{ssid: ssid, password: password}) do
    %{vintage_net_wifi: %{networks: networks}} = config = get_wifi_config()

    VintageNet.configure(
      @wifi_ifname,
      put_in(config, [:vintage_net_wifi, :networks], [
        %{key_mgmt: :wpa_psk, ssid: ssid, psk: password}
        | Enum.reject(networks, &(&1.ssid == ssid))
      ]),
      persist: false
    )
  end

You can of course remove persist: false based on your needs.

Cheers,
Sébastien.

Also Liked

Rehan

Rehan

Hi,

@seb3s Thank you for your help, with this i was able to add new network while keeping the existing configuration as is.

Regards

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement