Unable to connect to wifi in headless mode

Hi all,

I have a raspberry pi 4. It is able to auto-login when it connects to a monitor and connect to wifi automatically. However, if it is not connected to a monitor then it won’t connect to the wifi. Does anyone have any idea of what is going on?
I assumed that probably it couldn’t auto-login in the headless mode for some reason thus won’t be able to connect to wifi automatically. Since if I switched CLI mode, the pi won’t be able to auto-login, the username changed to raspberry instead of ubuntu.
Thank you for any suggestions on how to fix it.

I notice that for some reasons, the raspberry in headless mode enters AP mode directly.
How do I disable this function?
Thank you very much.

Hi @alanypf,

How did you connect the Pi to wifi? If you are using the GUI, then you should make sure that the network is available to all users.

You can also run sudo pifi add SSID PASSWORD on the command line and then reboot.

When I use the GUI, the Pi would be able to connet to my router automaticlly. No further actions needed. However, in GUI mode without a monitor. The Pi would not connet to the router. It would boot into AP mode. I need to connect to the AP hotspot and then connet to my router.
I am curious about why this happened.
Is that possible to disable the AP mode?
Thank you very much.