Solved. WiFi.config conflict? vTaskDelay

I have cobbled together a small sketch for an ESP32 which works perfectly. I allows an alarm time to be set on a webpage and then a red light turns green at the desired time. I know the code needs tidying up a bit but I'll do that when I'm finished. So please, not tips on the finer points of coding just yet.

The problem is I want to use a fixed IP address and I cannot get it to work. Here is the working code with the WiFi.config lines commented out:

code removed

When I uncomment the WiFi.config lines the ESP32 sets up the correct IP address but then when I try and set the alarm time online it re-boots and doesn't re-connect to the WiFi.

I have tried putting the Wifi.config lines in several different place, but always the same problem. What am I doing wrong here?

What IP address do you receive if you allow it to be provisioned for you?

Just the next free one my router finds. Usually The script writes the IP address to the serial monitor. I want to give the alarm to my daughter for my grandkids and so a fixed address would be better because then my daughter doesn't have an Arduinio IDE or serial monitor and I am not even sure she could set an IP address to MAC address on her router.

In other words I want it to work out of the box.

I have narrowed the reason for the rebooting down to this warning

Task watchdog got triggered. The following tasks did not feed the watchdog in time

After a bit of googling I found this is a known problem that can be resolved with adding "vTaskDelay(10);" to the sketch. I therefore changed the WiFi.config into a function which included the vTaskDelay as below and called that from the main sketch.

void setIPAddress(){
   // Configures static IP address
  if (!WiFi.config(local_IP, gateway, subnet)) {
    Serial.println("STA Failed to configure");

This hasn't fixed the problem and I still get the message

Task watchdog got triggered. The following tasks did not feed the watchdog in time

Any ideas on how to fix this?

The problem was that the WiFi library needed the DNS address in WiFi.config even though it was marked as optional.