ESP32 allocating IP adress

Welcome to the forum

You have this in your sketch

 while (!Serial) {
    ;                     // Wait until serial port is ready
  }  

If the board is not connected to the PC via USB then there will not be a Serial connection and this while loop will never end