1

I have created a C++ wrapper on top of nmcli to connect 2 WiFi modules to WPA2 networks in Ubuntu 18. However, it adds a number postfix to the SSID. Example: My Network becomes My Network 1 and then this number keeps growing.

As I need to specify the ifname, the current command is nmcli -w 90 device wifi connect BSSID password AMAZING_PASSWORD ifname wlan0. I have also tried using nmcli connection up <name> ifname <my_interface>, but that requires me to actually connect both WiFi modules to the network previously, but that does not seem right. Are there any solutions that would avoid that number postfix or an easier way to implement the connection up without needing to previously connect both modules to the network?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
ignacio
  • 1,181
  • 2
  • 15
  • 28

1 Answers1

1

You can set the connection name when connecting using:

#wlan0
nmcli -w 90 device wifi connect BSSID password AMAZING_PASSWORD ifname wlan0 name NAME_OF_CON_VIA_WLAN0
# wlan1
nmcli -w 90 device wifi connect BSSID password AMAZING_PASSWORD ifname wlan1 name NAME_OF_CON_VIA_WLAN1

You can see your list of connections using nmcli c. By default when connecting to a wifi network the SSID is also the connection name but you can change it

ofirule
  • 4,233
  • 2
  • 26
  • 40
  • Fair enough. But then, I would need to connect both modules to the network. I mean, this approach requires me to develop code also to check whether the system has already been connected to his network before or not. I was searching for a solution in which I could connect only one WiFi module and use that information to connect the other one when necessary. – ignacio Sep 02 '20 at 11:57
  • I don't quite understand, but you can delete the connection like so: `nmcli connection delete NAME_OF_CON` , and then you can add or delete connection according to your logic – ofirule Sep 02 '20 at 12:53
  • Do you mean that I should always delete a connection after I disconnect from it? – ignacio Sep 02 '20 at 13:33
  • I don't know all the pros and cons of create/delete connection vs up/down of an existing connection. But deleting a connection is a valid and good solution for many use-cases – ofirule Sep 02 '20 at 13:48