Ubuntu Core is especially designed for appliances: you can very easily create a customized image by defining your own model assertion and including the specific snaps you need for your target application. At the same time, the system is security-first and you can finish configuration on it only by connecting via a system console. However, this can be inconvenient some times, as accessing the console is not immediate in many devices: sometimes you need special connectors/cables or even doing some soldering. If that is the case, you would be better off by having an easier way of performing the configuration.
Canonical has had a solution for this for a while, the wifi-connect snap. This snap helps you to configure connectivity for the device by creating a wifi Access Point to where you can connect from a mobile phone and then select the wifi network where the device should connect to. This is very useful in a scenario where a technician installs a device, and then configures basic connectivity so the device can reach the Ubuntu store and receive updates.
The wifi-connect snap is not published in the store: instead, the sources are public so anybody can take them as reference and adapt to their needs.
How does it work?
Wifi-connect allows you to configure wifi connectivity in an ingenuous way: it creates an Access Point to which you can connect from a mobile phone. When you do so, the phone will present you a captive portal that, after asking for a password, will show you a list of surrounding wifi SSIDs (wifi network identifiers). You can select and introduce the password for any of those SSIDs, and after that the AP you connected to shuts down and the device tries to connect to the selected SSID. If it fails in the attempt, it will create the AP again so you can still access the portal and re-try.
Wifi-connect has two modes: in the management mode, it lets you configure the wifi network the device connects to, as described in the previous paragraph. Once a successful connection happens, you enter operational mode. This mode exposes a portal that allows you to disconnect from any wifi the device is connected to. If you do this, you go back to management mode. Of course, to access the operational portal you need access to the network the device has connected to.
How to set it up?
You can build the snap from sources and then include it in your image. You also need to include the network-manager snap, which is needed to control the wifi interface (previously, wifi-connect also had the wifi-ap snap as a dependency, but after some recent changes that is not the case anymore). Note that you will need network-manager snap from the 1.10 track or from a more modern track. When testing, you can install NM with
snap install --channel=1.10 network-manager
There are some interface connections that you need to perform, either manually or by configuring them via gadget connections. The commands you need to run if doing this manually are
snap connect wifi-connect:firewall-control snap connect wifi-connect:network-manager network-manager
You will also need to configure some of the wifi-connect settings. First, to set the exposed AP name and password:
snap set wifi-connect wifi.ssid=<my_AP> snap set wifi-connect wifi.security-passphrase=<my_AP_password>
To configure the portal password:
snap set wifi-connect portal.password=<my_portal_password>
To enable the operational portal (it is disabled by default):
snap set wifi-connect portal.operational=true
And to set the wifi interface to use:
snap set wifi-connect wifi.interface=<wifi_interface>
There are also options to set the subnet, country code, channel, and band for the AP. Another interesting option is “config-wifi-once”, that disables the management portal once the device has connected successfully once to a wifi network:
snap set wifi-connect config-wifi-once=<true|false>
You can configure these settings from your image gadget too (defaults section). Finally, the project contains a very extensive documentation that explains the snap in more detail. Hopefully now you have everything you need to get started with wifi-connect!