UNO R4 Wifi not connecting to wifi with one code, but connecting with other

Hello. I am moving from an UNO R3 to an UNO R4 wifi for my project specifically for OTA updates and RTC. I ran the default Thing sketch code to connect to my wifi which works great and connects quickly.
image

I have now moved my unfinished project code into that given default sketch. The code runs without error, however it is not connecting to the wifi anymore:
image

I am not sure what the issue is. Is my code running before the board has a chance to try to reconnect? Thanks for any help.
Here is my code:

#include <DHT.h>
#include <DHT_U.h>
#include "Arduino_SecureElement.h"
#include "Arduino_LED_Matrix.h"
#define sens_pin 2
#define heat_io 3
#define light_io 4
#define fan_io 5

#define DHTTYPE DHT22

DHT dht(sens_pin, DHTTYPE);

struct Plant {
  float temperature;
  float humidity;
  float light_height;
};

Plant TomatoStages[] = {
  {28, 50, 13},
  {26, 55, 18},
  {24, 60, 23},
  {22, 65, 28}
};

#include "thingProperties.h"
ArduinoLEDMatrix matrix;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
  dht.begin();
  pinMode(heat_io, OUTPUT);
  pinMode(light_io, OUTPUT);
  pinMode(fan_io, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}


void Romas(Plant plant) {
      int time = 0;
  while (true) {
    float temp = dht.readTemperature();
    float hum = dht.readHumidity();
    Serial.print("\nTemperature: ");
    Serial.print(temp);
    Serial.print(" Humidity: ");
    Serial.print(hum);

    int lightstart = 5000; // 6 hours, when light starts 21600000
    int lightduration = 43200000; // 12 hours temporarily
    int fullday = 86400000; // 24 hours
    int fantimer = 0;
    //digitalWrite(fan_io, HIGH);
    Serial.print("\n");
    Serial.print(time);
    // digitalWrite(light_io, HIGH);
    // if (time == lightstart) {
    //   digitalWrite(light_io, HIGH);
    // }
    // else if (time == lightduration + lightstart) {
    //   digitalWrite(light_io, LOW);
    // }
    if (temp <= 22) {
      digitalWrite(heat_io, HIGH);
    }
    else if (temp >= 25) {
      digitalWrite(heat_io, LOW);
      digitalWrite (fan_io, HIGH);
    }
    if (temp < 30) {
      digitalWrite (fan_io, LOW);
    }


    // if (fantimer == 3.6E6) { // fan will turn on every hour
    //   fantimer = 0;
    //   digitalWrite(fan_io, HIGH);
    // } 
    // else if (time == 300000) {
    //   digitalWrite(fan_io, LOW);
    // }
    // if (hum > 75) {
    //   digitalWrite(fan_io, HIGH);
    // }
    // else if (hum < 73) {
    //   digitalWrite(fan_io, LOW);
    // }

    delay(1000);
    time = time + 1000;
    fantimer = fantimer + 1000;
    if (time == 5000) {
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}



void loop() {
  ArduinoCloud.update();
  Plant myPlant = PepperStages[0];
  Romas(myPlant);
}

NOTE: Please forgive my code, it is crudely made.
NOTE: I am basing my diagnosis of the board connecting by if it says "connected to "bread" in the serial monitor. And if the device info on arduino cloud says online or offline.

NAN value of DHT sensors means faulty cables, wrong connection or a bad sensor. Please check what happened in your case. Test it with a simple code, without wifi.

I understand, the board is not connected to any DHT sensor as I am still trying to get it connected to the cloud. the NAN values are expected.