Changing Wifi connection settings via terminal

Hi,
I am using OSMC that I installed back in June 2015 on my raspberry Pi 2.
Here is the scenario.
Raspberry Pi 2 is connected to Wifi network A no ethernet cable connected.
I am connected to it via SSH terminal through my computer.
There is no visual access no hdmi connected.

How can I change Wifi Configuration of OSMC via terminal/SSH so that it now connects to a Wifi Network B ?

Please advise,

Thanks,
Ahmed

connmanctl is what you should Google.

using connmanctl when I type
connect wifi_blah_psk

it disconnects my existing remote connection ( SSH remote terminal ) but also does not connect to the network B, because that is password protected and I have no chance to type in the password.

connect does not take wifi password as argument…

The whole point of question is that I am accessing it remotely via SSH using network A and want to switch Wifi connection of OSMC to wifi network, whatever the solution is I will have to provide password and wifi information all at once…

You will need to ensure you have the agent on, run ‘agent on’, but I am not sure what to advise about disconnection. Is there no way you can do this locally, possibly via My OSMC?

Sam

sam I did do the ‘agent on’ command before it

This is an interesting problem that’s why I though I would mention it at the very outset that I do not have ethernet connection just wifi connection and the same connection has to be switched to a different wifi network.

If I could update the configuration directly in the file where it stores the WIFI information then probbaly that would do, for example following information is applicable on raspbian. You can edit following file

$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Again, some lines might already be present, just add the following.

network={
ssid=“YOUR_NETWORK_NAME”
psk=“YOUR_NETWORK_PASSWORD”
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}

But osmc does not have this .conf file anywhere in the wpa_supplicant folder…

I may well do it by physically attaching HDMI and display but, that will not solve the problem as I normally use it remotely and would prefer to solve it via SSH

Unfortunately you are operating a bit outside of the use-case for which OSMC was designed.

ActionA Well I thought was quite a basic thing to do and if it can not be done in osmc I would be surprised…

The way connman works you won’t be able to configure and connect to a second wifi network when controlling connmanctl via SSH over the first wifi network, because you will lose your first connection before completing the second connection, thus losing control of the connmanctl session.

connman doesn’t support “pre-configuring” wifi networks, to configure/save a network you must actually connect to it, and only once you have disconnected from the old network and connected to the new network will the network be saved.

Sorry but that’s just the way connman works, and yes, what you are trying to do is a bit of an unusual use case - OSMC is a mediacenter designed to be controlled with an onscreen GUI after all.

Actually this is doable. I could configure OSMC WiFi with connman via wired ethernet and have both interfaces up at the same time, then disconnect the wired interface and stay connected via wifi.

This is a great resource:

To pre-configure the wifi secret, see the section “Write config file for connecting to secure AP:”
Then when you bring up the interface with “connmanctl connect …” it will just connect and not prompt for a password. In my case, it didn’t disconnect Ethernet either,

ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:blahblah
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST DYNAMIC MTU:1500 Metric:1

wlan0 Link encap:Ethernet HWaddr 7c:dd:blahblah
inet addr:192.168.1.110 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::7edd:90ff:feb7:6996/64 Scope:Link

Only thing I haven’t managed to figure out is getting it to connect to wifi on startup. But the github connmanctl was super helpful.

Once you connect – it should remain connected.

Sam

My problem is the following, and I would like to know if it is possible to do it using OSMC.
The thing is completely related to this topic, so I thought it would be better not to open a new thread but continue this one (maybe, with the new versions that have been released of OSMC now it is possible to achieve this).

I would like to give my raspberry with OSMC installed to a friend, who is not tech savvy. He has passed me the SSID and password of his network so I would like to give it to him pre-configured. I would prefer to give him the system pre-installed with some plugins (he doesn’t know how to install them) so it can’t be the first installation.

I have thought that I could change temporarilly my home’s SSID and password and maybe it could work but I would like to know if there is a better way.

I know how to do it in a raspbian or other distros not based on connman, but not how to do it in OSMC.

In the link posted by htpcero, the section “Write config file for connecting to secure AP:” could be the solution to my question but the problem is, for the line “[service_wifi__managed_psk]” I do not know the hash, I have not access to the Wifi and only know the SSID and password.

Is there any way to do it?

Thanks a lot

Use the preseeder / don’t boot.

Searched for a little bit of information about the preseeder. Found this:

I supposed (no reason in particular) that that file was used only in the first boot for installing the o.s, not in every boot when all was installed and working.

Thank you! That’s exactly what I need. I will test it next week.

Be aware that in a few months the preseeder format may change. If that happens I can advise

Hi,

In order to test the solution, I changed the SSID of my network to a new one and also the password. Then I connected some devices to that SSID to check it worked correctly.

I modified the preseed.cfg file to the following:

d-i target/storage string sd
d-i network/interface string wlan
d-i network/auto boolean true
d-i network/ip string 192.168.1.201
d-i network/mask string 255.255.255.0
d-i network/dns1 string 8.8.8.8
d-i network/dns2 string 8.8.4.4
d-i network/gw string 192.168.1.1
d-i network/ssid string SSID_Without_Spaces
d-i network/wlan_keytype string 1
d-i network/wlan_key string passphrase

And booted the pi to try it, but it didn’t connect. The gateway is correct and the IP is not used by other devices in the network.

  1. Anything I am probably doing wrong? Do I have to forced it someway to read the preseed.cfg file?
  2. Is there a way of using “SSID With Spaces” in the preseed.cfg file?
    I know there were problems with those spaces, I do not know if they have been solved.

Thanks

When I reverted the changes (changed again the SSID in the router to the original one and wrote the original preseed.cfg configuration) which was:
d-i target/storage string sd
d-i network/interface string wlan
d-i network/auto boolean true
d-i network/ssid string SSID2_Without_Spaces
d-i network/wlan_keytype string 1
d-i network/wlan_key string passphrase2

It worked. In order to test if I had done something wrong or if it just isn’t reading the preseed.cfg and taking the configuration that works (which is stored somewhere), I wrote a false SSID and a wrong password in the preseed.cfg and put the original SSID and original password in the router. The connection worked.

So the only think that occurs to me is that it isn’t reading the preseed with the changes. Could that be possible?

Preseed is only going to work on first boot!

1 Like

Ok, perfect.

It’s just that in my original comment I said “I would prefer to give him the system pre-installed with some plugins […] so it can’t be the first installation” so I guessed that what was answered worked not only for the first boot.

If it is impossible to give to a friend a system pre-installed with some plugins … ok, it’s just a pity.

Thanks really a lot!!!

You can clone the card and show him how to connect to a network using My OSMC.