Start util wpa_cli and execute commands:
> add_network
0
> set_network 0 ssid "MyNetworkSSID"
OK
> set_network 0 psk "MyNetworkPassword"
OK
> enable_network 0
OK
> save_config
OK
> quit
You can add multiple networks in a similar way. They will have different IDs, and the device will connect to any of them automatically.