Blynk keeps disconnecting when running this sketch

Hi, i am using Arduino Mega 2560 with ESP8266 on a local server. Tried running the code below and my Blynk will disconnect. Is it because of flooding? BTW i tried running the functions separately and it works fine but when i compile them into a single code they do not work. Can someone please help me

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Blynk.h>
#include "DHT.h"
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
#define DHTPIN 11
#define DHTTYPE DHT11   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
ESP8266 wifi(&EspSerial);
BlynkTimer timer;

int PWM = 3;
boolean running_two = false;
int takeover2 = 0;


char auth[] = "***";
char ssid[] = "**";
char pass[] = "**";

//dht and fan
WidgetLED led3(V3);

BLYNK_WRITE(V3)
{
  int value = param.asInt();
  digitalWrite(12,value);

  if (value == LOW){
    led3.off();
    Serial.println("AC OFF");
  } else {
    led3.on();
    Serial.println("AC ON");
  }
}

void tempsensor(){
running_two = takeover2; 

  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  Blynk.virtualWrite(V4, t);
  Blynk.virtualWrite(V5, h);

  if (t > 35 && running_two == false){
  digitalWrite(PWM, HIGH);
  
  delay(10);
}
else if (t < 35 && running_two == false) {
  digitalWrite(PWM, LOW); 
 
}
  }

BLYNK_WRITE(V6) // Button Widget is writing to pin V1
{
  int fanSpeed = param.asInt();
  
   if (fanSpeed == 0) {
     analogWrite(PWM, 0);
    Serial.println("FAN OFF");
   } else if (fanSpeed == 1) {
    analogWrite(PWM, 190);
    Serial.println("LOW");
  }else if (fanSpeed == 2) {
    analogWrite(PWM, 255);
    Serial.println("HIGH"); 
  } 
}

BLYNK_WRITE(V7) {
  takeover2 = param.asInt();

  if (takeover2 == HIGH){
  running_two == true; 
  Serial.println("takeover fan");
   }
  else if (takeover2 == LOW) {
  running_two == false;
  Serial.println("back to DHT11");
  return running_two;
   }
 }

//ldr
const int ledPin = 13;   //the number of the LED pin
const int ldrPin = A0;  //the number of the LDR pin

int val = 0;
int takeover = 0;
int relay1State = 0;
boolean running = false; //


BLYNK_WRITE(V2) {
  relay1State = param.asInt();
  digitalWrite(ledPin, relay1State);
}

BLYNK_WRITE(V1) {
  takeover = param.asInt();

  if (takeover == HIGH){
  running == true; 
  Serial.println("taken over");
   }
  else if (takeover == LOW) {
  running == false;
  Serial.println("back to LDR sensor");
  return running;
   }
 }
 
void checkLDR() {
  int relay1Status = digitalRead(ledPin);
  int ldrStatus = analogRead(ldrPin);   //read the status of the LDR value
  running = takeover;
 
  //check if the LDR status is <= 300
  //if it is, the LED is HIGH
  
 if (ldrStatus <=300 && running == false) {
    digitalWrite(ledPin, HIGH);               //turn LED on
    Serial.println("Light Bulb is ON");
    Blynk.virtualWrite(V1, relay1Status);
    
   } 
  else if (ldrStatus >=300 && running == false  ){
    digitalWrite(ledPin, LOW);               //turn LED off
    Serial.println("Light Bulb is OFF");
    // Update Button Widget
      Blynk.virtualWrite(V1, relay1Status);
 }
 
} 

//Setup
void setup() { // the setup function runs once when you press reset or power the board

// Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass, "***", 8080);
  //lights
  pinMode(ledPin, OUTPUT);  //initialize the LED pin as an output
  pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input
  digitalWrite(ledPin, relay1State);
  timer.setInterval(4000L, checkLDR);
  
  pinMode(12,OUTPUT);
  dht.begin();

  pinMode(PWM,OUTPUT);
  // Setup a function to be called every second
  timer.setInterval(2000L, tempsensor);


}





void loop()
{
  Blynk.run();
  timer.run();
}

A post was merged into an existing topic: DHT11 sensor cannot send data to BLYNK app