The root cause of this issue is the handling of WiFi connections in Ubuntu. By default, when a connection is added using NetworkManager it is marked private to the user that initiated that WiFi connection and no other users on the system are allowed to use it. That’s why it does not connect pre-logon. To allow automatic connection to an SSID for all users:
sudo nmcli c modify <ssid> connection.permissions ""
Unfortunately this requires issuing that command each time a new SSID is added. Note that wired connections do not have this permission issue and are connected automatically by default.
There is another approach that is HIGHLY INSECURE, but may be acceptable on embedded devices that do not expose a local keyboard or display. This is a brute force hack to workaround the problem by automatically logging in on the console. It has the “benefit” that a development engineer that can open the box and plug in HDMI and Keyboard can directly access the linux shell (or a custom shell with the right agetty option).
# Configure systemd to use multi-user.target instead of graphical.target
# There is probably an official way to do this, but the brute force approach is:
sudo ln -s /lib/systemd/system/multi-user.target /lib/systemd/system/default.target
# Configure agetty to login automatically on the virtual console
# by editing /lib/systemd/system/getty@.service "Execstart" line as follows
ExecStart=-/sbin/agetty --autologin=ubuntu --noclear %I $TERM