Skip to content

Instantly share code, notes, and snippets.

@maoueh
Last active March 31, 2022 12:30
  • Star 40 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save maoueh/8260199 to your computer and use it in GitHub Desktop.
OpenELEC (4.0.1) WIFI connection details using `connman`

Even though there is a nice XBMC add-on to configure your WIFI settings, sometimes, you may still want to setup the WIFI connection for many reasons or just for fur.

OpenELEC use connman for managing connection to the various available network.

Setuping connman to connect to your protected WIFI network is an easy requiring you only to create a config file and enter some commands in a shell.

This guide was run using OpenELEC 4.0.1 which use internally connman 1.21. It will guide through all necessary steps to configure a connection to your WIFI network. Once setup, OpenELEC will automatically re-connect on boot as long as you keep the configuration in your storage.

Here we go!

  1. Ensures connman daemon is running:

    ps faux | grep connmand

    If you see something like below, then you are good to go:

    OpenELEC:~ # ps faux | grep connmand
     862 root       0:00 /usr/sbin/connmand -nr
     1033 root      0:00 grep connmand
    

    If you only see:

    OpenELEC:~ # ps faux | grep connmand
     1033 root      0:00 grep connmand
    

Then you will probably need to startup connmand manually. Note that this will not be persistent, i.e. it will not autostart next time you boot your machine.

To start connmand manually, do:

   `/usr/bin/connmand -nr`
  1. Ensures there is a network adapter for your WIFI card (or USB dongle or whatever):

    ifconfig

    You should see an adapter starting with wlan in the list. Here the result of the command in my hardware:

    eth0      Link encap:Ethernet  HWaddr B8:27:EB:0F:01:A0
              inet addr:192.168.0.115  Bcast:192.168.0.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:2307 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1268 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:320940 (313.4 KiB)  TX bytes:159217 (155.4 KiB)
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
    wlan0     Link encap:Ethernet  HWaddr 00:13:EF:20:01:8A
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
  2. Enable connman wifi technology:

    connmanctl enable wifi

    Maybe connman will complain that wifi is already enabled, if it's the case, no problem, just move to next step.

    If connman cannot enable wifi, it probably means there is something fishy with your adapter (wrong linux driver maybe).

  3. Scan for WIFI network nearby:

    connmanctl scan wifi

    This will scan nearby network available.

  4. List found WIFI network:

    connmanctl services

    This will list all known services. A services for connman is an available device for which is possible to connect to. This is not limited to WIFI and includes ehternet, bluetooth (if enabled) and more. Here the list I received when doing this command on my hardware:

    *AR Wired             ethernet_b827eb0f01a0_cable
     BELL825              wifi_0013ef20018a_42454c4c383235_managed_psk
     VIDEOTRON2188        wifi_0013ef20018a_564944454f54524f4e32313838_managed_psk
     bungie               wifi_0013ef20018a_62756e676965_managed_psk
     Moth                 wifi_0013ef20018a_4d6f7468_managed_psk
     Maison               wifi_0013ef20018a_4d6169736f6e_managed_psk
     GOAHEAD              wifi_0013ef20018a_474f4148454144_managed_psk
     VIDEOTRON6117        wifi_0013ef20018a_564944454f54524f4e36313137_managed_psk
     VIDEOTRON4100        wifi_0013ef20018a_564944454f54524f4e34313030_managed_psk
     Nicolas              wifi_0013ef20018a_4e69636f6c6173_managed_psk
    

    As you can see, there is a bunch of them. All the one starting with wifi_ are WIFI network available to connect to. The suffix _psk means it's a protected network.

    If my case, the network I want to connect to is Moth, so its service id assigned by connman is wifi_0013ef20018a_4d6f7468_managed_psk.

  5. Create the configuration file to access the network.

    The connman configuration files on OpenELEC are not at the usual location of /var/lib/connman. In the OpenELEC distribution, you must put your configuration file in /storage/.cache/connman.

    So, navigate to this directory and create a file with the pattern <name>.config. The <name> should be replaced with any name you think is useful to remember the network. In my case, I chose moth as the <name> since it relates closely to the WIFI SSID name.

    When the file is created, enter the following content in it using your favorite editor (nano is the default one in OpenELEC):

    [global]
    Name = Moth
    Description = Moth Wifi service config file
    
    [service_wifi_moth]
    Type = wifi
    Name = Moth
    Passphrase = <passphrase>
    

    This is the minimal configuration required (in fact, the [global] section is not really necessary but useful to have).

    For the [global] section, enter an identifier for the file in the Name field and a description of the network in the Description field.

    Other section must always start with a service_. What follows after is simply again another identifier which identity the network. In my case, I used the pattern wifi_<ssid_name>.

    Then, in this section, the Type if the type of technology for the service which is wifi in our case. The Name represents the SSID network name with is Moth in my case. And finally, Passphrase is the password for the network, replace <passphrase> with your own secret passphrase.

    If you have an SSID name with special characters (like spaces or anything else), removed the Name line and put a line SSID = <SSID_name_in_hex> instead. The value <SSID_name_in_hex> should be replaced by the hex value of your SSID name which can obtained online with a service like . For example, for the network Moth, the configuration file would look like this when using the SSID field:

    [global]
    Name = Moth
    Description = Moth Wifi service config file
    
    [service_wifi_moth]
    Type = wifi
    SSID = 4d6f7468
    Passphrase = <passphrase>
    

    There is more more configuration available but only those will suffice for you guide. Refer to the config file format for more information on the configuration file format (links to version 1.21 of connman).

  6. Check that connman correctly sees your new settings.

    For this, simply run:

    connmanctl scan wifi
    connmanctl services
    

    In the refreshed services list, there now should be a A* just before the network you configured, this indicates that connman knows how to connect to this service:

    *AR Wired                ethernet_b827eb0f01a0_cable
    *A  Moth                 wifi_0013ef20018a_4d6f7468_managed_psk
        BELL825              wifi_0013ef20018a_42454c4c383235_managed_psk
        bungie               wifi_0013ef20018a_62756e676965_managed_psk
        Nicolas              wifi_0013ef20018a_4e69636f6c6173_managed_psk
        Maison               wifi_0013ef20018a_4d6169736f6e_managed_psk
        GOAHEAD              wifi_0013ef20018a_474f4148454144_managed_psk
        VIDEOTRON2188        wifi_0013ef20018a_564944454f54524f4e32313838_managed_psk
        VIDEOTRON6117        wifi_0013ef20018a_564944454f54524f4e36313137_managed_psk
        VIDEOTRON4100        wifi_0013ef20018a_564944454f54524f4e34313030_managed_psk
    

    If the network does not have the *A before it, try restarting the connman daemon to force it to reload configuration files. First, obtain the connmand pid by running:

    ps faux | grep connmand

    And then checking the first number if the result line.

    kill <connmand_pid>

    It should restart automatically but if it's not the case:

    /usr/bin/connmand -nr

    When it have restarted, run another wifi scan and check if the services has the *A flag.

  7. Connect to the network

    connmanctl connect wifi_0013ef20018a_4d6f7468_managed_psk

    Where wifi_0013ef20018a_4d6f7468_managed_psk is the servie id reported by connman for your network.

    If everything went well, should then be connected to your protected WIFI network.

Voilà and enjoy Matt

@TheMooDude
Copy link

Great info, much appreciated. I may be a right fool here but can someone please clarify the process to add two or more wlan configs. I would like to have a box that'll connect in a number of places and would like to have it store a list of known networks.

@timinski
Copy link

@TheMooDude:
If you get the answer to your multi SSID wifi question above, please post it here. Would like to acheive the same with my RPi2B. Thanks in advance.

@pigoz
Copy link

pigoz commented Aug 21, 2016

Great article. Thanks for taking the time to write it! 👍

@tiitpaananen
Copy link

Thanks, this was helpful. In case of plex original raspberry image... doing ssh... root/plex > that password is nowhere documented and ssh is only way to get in as plex does NOT allow to open another console with ctrl+alt+F2 key combination

@AnthraxBass
Copy link

Thanks for a great guide! Can you please take a look at the issue that I'm having? I don't know where to set this ap_scan thing (openELEC 6.0)

  • Oct 23 19:36:23 OpenELEC wpa_supplicant[2713]: Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures
  • Oct 23 19:36:23 OpenELEC wpa_supplicant[2713]: Using interface wlan0 with hwaddr xx:xx:xx:xx:xx:xx and ssid "xxxxxxxxxxxxx"
  • Oct 23 19:36:23 OpenELEC kernel: Disconnect STA : ff:ff:ff:ff:ff:ff scb_val.val 3

@smosse
Copy link

smosse commented Dec 31, 2016

thx !

@bruce356
Copy link

Thanks so much this is really fantastic, wifi option for Plex Media Player on Pi3. Runs very smooth at 10Mbs.
Regards

@hex007
Copy link

hex007 commented Mar 21, 2018

What if there is no input device connected to the setup. You can only access the sdcard to enter the details. How would you then add network settings? In raspbian it is as easy as copying my wpa_suplicant.conf file to sdcard. Is there a way to add a new connection when the system is not booted up ??

@bezzpezz
Copy link

Hey Guys, I could not get connman to connect via wifi using the above method. The wifi just failed to register no matter what I did (No * next to the wifi name when executing the connmanctl services command - after completing all the steps beforehand of course).
The fix for me can be found here https://discourse.osmc.tv/t/could-not-connect-to-wi-fi/5654/16
It's just a matter of running connmanctl by itself, finding the wifi you want to connect to and then connecting.
Connmanctl takes care of everything, It creates a few config files similar to above (if you dig deeper they reside in a folder named after your connection in /storage/.cache/connman).

@Proj3ctS
Copy link

Proj3ctS commented Jul 6, 2019

Thanks @maoueh for this guide. Helped me a lot with setting up a WiFi connection via Proximus Smart WiFi on my rPi2 running LibreElec.

My config file:
`[global]
Name = proximus_smart_wifi
Description = Proximus Smart Wifi service config file

[service_wifi_proximus_smart]
Type = wifi
IPv4 = dhcp
IPv6 = auto
Name = Proximus Smart Wi-Fi
EAP = ttls
Identity = @proximuswifi.be
Phase2 = MSCHAPV2
Passphrase = `

@gravelfreeman
Copy link

Hi and thanks for making this build. Really handy since Rasplex is now dead. I had a hard time figuring out how to get wifi working so though I'd may write a simple way to do it.

Install "Linux File Systems by Paragon Software" to access your linux partition SD card. Or get a Linux Ubuntu live disc. Unhide hidden files. Then navigate to SDCARD/.cache/connman and create a file named "wifi.config". Write this inside and fill according to your credentials:

[global]
Name = Wifi
Description = Wifi service config file

[service_wifi_<name given above>]
Type = wifi
Name = <your wifi name (ssid)>
Passphrase = <your wifi password>

Safely eject with Paragon and voilà!

@balouken
Copy link

balouken commented May 1, 2020

Thanks @maoueh for this guide. Helped me a lot with setting up a WiFi connection via Proximus Smart WiFi on my rPi2 running LibreElec.

My config file:
`[global]
Name = proximus_smart_wifi
Description = Proximus Smart Wifi service config file

[service_wifi_proximus_smart]
Type = wifi
IPv4 = dhcp
IPv6 = auto
Name = Proximus Smart Wi-Fi
EAP = ttls
Identity = @proximuswifi.be
Phase2 = MSCHAPV2
Passphrase = `

Do this still work? Because it does not work for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment