In cases when your WIFI connection is troubling, you can trouble shoot and debug your connection using below commands.
To List all available WIFI networks, Run:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
This command will show something like
Now to connect to any of these available networks. Run:
networksetup -setairportnetwork en0 <SSID_OF_NETWORK> <PASSWORD>
That’s It. Happy Networking!