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

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement