the board should be fine to use. and rssi of -40 or even -60 should be ok. If the voltage would drop for some reason it most likely would reboot. Perhaps add a led blink to your code, so you see it blink three times when it reboots. Perhaps add some different amount of blinks at different stages of the code to find out when exactly it fails.
Apparently it works fine when you power it through the usb connector. So the voltage is a likely cause.
I don’t know exactly nothing about wifi antenna’s. Did you try removing the big one and using the onboard one? (that is if you board has an on board one) (I have a seeed studio esp32c6, that has both options and I have some none seeed, esp32c3 that have onboard antenna and some that have only external)
perhaps there is an error in your code (but should also be the case when using usb power). On this page ESP32 Setting a Custom Hostname (Arduino IDE) | Random Nerd Tutorials I read that you have the order of sethostname and begin wrong.
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(hostname);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}