Can I add WiFi config to SD card pre-install? (headless setup)

  • Hi there,


    I recently bought a RPI Zero W.


    I've installed OE/LE on many arm boxes before. They have always had full-sized USB ports, so I've always done the initial config using a USB keyboard.


    The RPI Zero W has only micro USB, so I can't (easily) set it up with a keyboard. I know I can enable the ssh daemon by editing cmdline.txt before inserting the SD card into the Pi. In theory I could then complete the setup remotely. Unfortunately, the Zero W also does not have ethernet, so I can't get it one the network without WiFi connection details.


    Is there any way I can pre-configure the WiFi on the SD card before inserting it into the Pi so that it is enabled as soon as the Pi boots for the first time? I know Raspbian and other distros allow you to place wpa_supplicant.conf into /boot on the SD, but last I checked LE doesn't use wpa_supplicant.


    Alternately, does anyone have any other suggestions? I was also hoping I might be able to use a remove via CEC - and the adapter does pop up as discovered - but I can't seem to use it navigate the setup screens. From memory, the same remote has worked on other LE boxes post-setup.


    Thanks!

  • It's not possible to preconfigure networking and we have no plans to change anything to make it possible. CEC should work, as long as the micro to normal HDMI convertor doesn't do something to interfere. Plan C is to invest in a cheap micro USB to normal USB adapter.

  • Thanks. Really appreciate you taking the time to respond and all the work you do on LE.


    For now I've solved the problem by putting LE to the side and installing Kodi on Raspbian instead. Raspian allowed me to pre-configure the WiFi, which meant I could enable the webservice and then use the iOS remote app to navigate the Kodi setup process.


    For what it's worth, I still couldn't get CEC to work. The same TV/AVR/remote works perfectly with other LE boxes, so I suspect you are correct and something weird is going on with the mini-HDMI cable (this is the only mini-HDMI device I own).


    I would have spent longer fixing the cable in order to use LE, but really the was just an experiment to see how well Kodi would run on the Zero W (the answer? Surprisingly well). This box is ultimately going to become a Home Assistant server.

  • As @chewitt mentioned, for the sake of ~£1 get an adaptor. It makes life easier and is always there, especially if for what ever reason the wifi doesn't connect.

  • Yes, it's possible. Mount the SD card on your computer and create (as root):

    Code
    nano /where_sd_card_is_mounted/storage/.cache/connman/mywifi.config

    Add the following (change "mywifi" after "Name" to your SSID and "passphrase" to your passphrase), save the file and boot your pi:


    Code
    [service_wifi_mywifi]
    Type = wifi
    Name = mywifi
    Passphrase = passphrase
  • I'd like to add the following comment: Azeam's instructions above pertain most directly to a non-Windows computer (Linux, Unix, Mac, etc.) The above file needs to be added to the boot partition of the Libreelec SD card. You can use a Windows machine as well, but you need to know where to put the file. It's not labeled on my Windows machine as Azeam shows it. The boot partition is a VFAT partition and (at least on my SD card) is small - around 500 MBytes.) Because it's a VFAT partition, it can be seen, written and read by either pretty much any computer or OS - Windows, Linux, Mac, etc. If you're using Windows as a computer to edit the SD card, Notepad++ is a safe word processor to read and write Unix/Linux style text files (which end lines with only a line feed, unlike Windows which uses a line feed/carriage return pair). If you have a multi-booted Raspberry Pi as do I, you need to look around a little to find the right partition. Also, if you mount the SD card on your Windows machine, the machine will find a number of separate virtual drives on the card, some of which it will say aren't formatted and many or all of which may be only labeled as "Disk X..." If they're not formatted, DON'T LET WINDOWS FORMAT THEM. THEY ARE LINUX EXT4-FORMATED PARTITIONS.


    My Windows machine doesn't find the partition LibreElec boot partition labeled as "storage" or "boot" but rather simply as "Disk I." In order to identify the correct Libreelec boot partition, you'll want to find a USB drive that you can open. Look for a file called os_config.json and open it using Notepad or Notepad++. If the description says Libreelec, you're in the right place. You can then follow Azeam's instructions, above.


    One other thing: if you want to get to your Raspberry Pi via SSH, you'll need a file on the boot directory called "SSH". It can be empty. SSH will need to have been already configured

  • I am currently trying to setup a fresh LE headless on a Pi Zero W. The Wifi setup (as described above) worked like a charm but I am not able to get ssh working. Therefore, I placed the "ssh" file in the root directory of the boot-partition (smaller fat partition). However, I cannot connect via ssh ("Connection refused") nor is the ssh-file delete as stated in the manual page. Is there any hint on how to get ssh running without any screen, etc?

    Thanks a lot for all your effort and help!

    All the best,

    Philsen

  • You can add "ssh" to kernel boot params to force SSH service start. On a Raspberry Pi boot params are in cmdline.txt .. we have never (not even back in OE days) supported forced start from a file called 'ssh' in the boot partition.

  • Dear Chewitt,


    thanks for the clarification. I thougth it works that way as indicated in the comment above (and as mentioned for rasbian which is obviously a different).

    I will have a try later the evening!

    Thanks a lot!

  • Yes, it's possible. Mount the SD card on your computer and create (as root):

    Code
    nano /where_sd_card_is_mounted/storage/.cache/connman/mywifi.config

    Add the following (change "mywifi" after "Name" to your SSID and "passphrase" to your passphrase), save the file and boot your pi:


    Code
    [service_wifi_mywifi]
    Type = wifi
    Name = mywifi
    Passphrase = passphrase

    Hi chewitt


    The Libreelec connection flow has always been great apart from when installing a new instance without HDMI CEC, input peripheral or ethernet. I've had it happen a few times where something has failed and I've had to dig my emergency 50m ethernet cable out! Why can't we manually define the credentials in the LE settings? Surely it's as simple as generating this text file?


    Then if we enable WiFi tethering pre-install, once the WiFi credentials were known it could be entered via the GUI and a remote app like Yatse or XBMC Remote. Once the file is there and hotspot tether is disabled it will autoconnect.


    If it's something LE team are not interested in maybe someone with some basic python skills (not me or I would) could make a simple addon to create this file.

  • In our opinion this is not a problem that needs to be fixed. In addition, the LE10 change to GBM/V4L2 mean that RPi0/1 are no longer on our list of official target hardware which further weakens the argument for adding complexity to support their use-case.

  • The OP was referring to RPi0/1 however this is true for all RPi IMO. From a consumer hardware perspective, connecting a new device wirelessly is industry standard and something which would make LE a lot more accessible. Thanks for confirming it's not something on the road map however. I'll see if I can find someone to help code an add-on to do it.