Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
I think the antenna of your device can be malfunctioning. Though the STA is close to the AP, it is still difficult to start communication, resulting in the error codes you saw.
To verify this cause, you can do a scan to see if the STA can capture the AP's signal soundly. To be more rigorous, you should also get the RSSI result at the AP side to see if the STA is transmitting well and the AP is capturing the STA soundly during the connection.
I think it's best to confirm this at first, based on the error code we saw, rather than investigating other less relevant causes right away.