Sometimes I need to set up a Raspberry Pi and configure it to connect to a WIFI network. Sometimes that network is not available at the time. I know the network name and password in advance.
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
network={
scan_ssid=1
ssid= "<wifi name>"
psk="<password>"
}