DateTime now

Hello, i have a problem with DateTime now=rtc.now(). Im using ds1307 as a rtc. The thing is that i cant get blynk working when i have datetime definition in my code. If i commented it out everything works normally. Is problém in DateTime , or i should set up something in Blynk?

Hello. Please show all code and error you see.

Well its basically blynk esp8266 standalone example.
void setup {
espserial.begin(9600);
Blynk.begin(…);
}
void loop {
DateTime now=rtc.now();
Blynk.run();
}
i didnt get any error in serial monitor, but it looks Like it freezes after i get first ping. App says that my duino is not in network.

That is because you run a thing in the loop. It’s not recommended. There is an example in the Blynk library called PushData and it uses the SimpleTimer library to execute timed functions (e.g. every 5 seconds). This has to be applied to get things out of the loop().

So basically i need to call DateTime every, say 1000ms?
So with timer lib i Will just use: t.every(1000, gettime);

Yeap. Here is Blynk RTC example - https://github.com/blynkkk/blynk-library/blob/master/examples/Widgets/RTC/RTC.ino

I have more things in loop, so i was wondering, if i can do it like this:

/*********************************************************************************/

//#include <BlynkWrongInclude.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "SoftwareSerial.h"
#include <SPI.h>
#include <LEDFader.h>
#include <Curve.h>
#include <DHT.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Timer.h>
#include <Event.h>
#include <SPI.h>
#include "RTClib.h"
#include <Wire.h>

#include <SD.h>
#include <SPI.h>

#define auth "..."
#define ssid "..."
#define pass "..."
#define EspSerial Serial
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 2    
#define DHTTYPE DHT11				// DHT 11
DateTime now;
byte SunriseStart = 7;				//When sunrise mode starts(hour)
byte  DayStart = 8;					//When day mode starts(hour)
byte  SunsetStart = 16;				//When sunset mode starts(hour)
byte  NightStart = 21;				//When night mode starts(hour)
byte  OFFstart = 23;				//When to shut down all acc(hour)
int fadetime=50;		//Fade time(from 0 to max)(ms)

#define Rp 5		//Red channelPWM pin
#define Gp 6		//Green channel PWM pin
#define Bp 9		// Blue channel PWM pin
#define Wp 10		//White channel PWM pin
#define BWp 11		//Powerled blue PWM pin
					/********************************************************************************/
DHT dht(DHTPIN, 11);

LEDFader BW = LEDFader(BWp);
LEDFader W = LEDFader(Wp);
LEDFader R = LEDFader(Rp);
LEDFader G = LEDFader(Gp);
LEDFader B = LEDFader(Bp);
RTC_DS1307 rtc;
Timer t;


void setup() {
	//fadetime = fade * 60 * 1000;
	pinMode(Wp, OUTPUT);
	pinMode(Bp, OUTPUT);
	pinMode(Rp, OUTPUT);
	pinMode(BWp, OUTPUT);
	pinMode(Gp, OUTPUT);
	pinMode(13, OUTPUT);
	//Serial.begin(9600);
	//setPwmFrequency(9, 8);
	//setPwmFrequency(11, 8);
	//analogWrite(BWp, 20);*/
	//Serial.begin(9600);
	EspSerial.begin(ESP8266_BAUD);
	delay(10);
	Blynk.begin(auth, wifi, ssid, pass);
	delay(10);
	dht.begin();
	
	delay(10);
	
	DateTime now = rtc.now();
	if (now.hour() >= SunriseStart && now.hour() < DayStart) {
		W.fade(100, fadetime / 15);
		BW.set_value(0);
		R.fade(255, 6000 / 15);
		G.fade(255, fadetime / 15);
		B.set_value(0);
	}
	if (now.hour() >= DayStart && now.hour() < SunsetStart) {
		W.fade(255, fadetime / 15);
		BW.fade(220, fadetime / 15);
		R.fade(255, 6000 / 15);
		G.fade(100, fadetime / 15);
		B.set_value(0);
	}
	if (now.hour() >= SunsetStart && now.hour() < NightStart) {
		BW.fade(255, fadetime / 15);
		W.fade(200, fadetime / 15);
		G.fade(0, fadetime / 15);
		R.fade(255, 6000 / 15);
		B.set_value(0);
	}
	if (now.hour() >= NightStart && now.hour() < OFFstart) {
		R.fade(100, fadetime / 15);
		G.fade(136, fadetime / 15);
		B.fade(255, fadetime / 15);
		BW.fade(100, fadetime / 15);
		W.fade(50, fadetime / 15);
	}
	if (now.hour() >= OFFstart || now.hour() < SunriseStart) {
		W.set_value(0);
		BW.set_value(0);
		R.set_value(0);
		G.set_value(0);
		B.set_value(0);
	}
	
}
void loop() {
	Blynk.run();
	aqua();
}
void RTC() {
	DateTime now = rtc.now();
}
void aqua() {
	/**********************************************
	******************Misc. things****************
	**********************************************/
	t.every(1000, RTC);
	BW.update();
	W.update();
	R.update();
	G.update();
	B.update();
	t.update();
	
	
	/****************************************************
	*****************LAN Communication****************
	*****************************************************/
//String read = Serial.readStringUntil('=');
	/*if (Serial.available()>0) {
		
		if (Serial.read() == 48) {
			if (Serial.peek() == 's') {
				Serial.println("READY");
				SunriseStart = Serial.parseInt();
				SunriseEnd = Serial.parseInt();
				DayStart = Serial.parseInt();
				DayEnd = Serial.parseInt();
				SunsetStart = Serial.parseInt();
				SunsetEnd = Serial.parseInt();
				NightStart = Serial.parseInt();
				NightEnd = Serial.parseInt();
				OFFstart = Serial.parseInt();
				OFFend = Serial.parseInt();
				fade = Serial.parseInt();
				fadetime = fade * 60 * 1000;
				Serial.flush();
			}
			else {
				//Serial.println(F("true"));
				Serial.println(SunriseStart);
				Serial.print(FS);
				Serial.println(SunriseEnd);
				Serial.print(FS);
				Serial.println(DayStart);
				Serial.print(FS);
				Serial.println(DayEnd);
				Serial.print(FS);
				Serial.println(SunsetStart);
				Serial.print(FS);
				Serial.println(SunsetEnd);
				Serial.print(FS);
				Serial.println(NightStart);
				Serial.print(FS);
				Serial.println(NightEnd);
				Serial.print(FS);
				Serial.println(OFFstart);
				Serial.print(FS);
				Serial.println(OFFend);
				Serial.print(FS);
				Serial.println(fadetime / 60000);
				Serial.print(FS);
				Serial.flush();
			}
		}
			}
		
	
	/*if (rtc.isrunning()) {
		DateTime now = rtc.now();
	}*/
	/****************************************************
	  *****************Light section**********************
	  ****************************************************/
	if (now.hour() >= SunriseStart && now.hour() < DayStart) {
		if (R.is_fading() == false) {
			if (R.get_value() == 0) {
				R.fade(255, 6000 / 15);
			}
		}

		if (G.is_fading() == false) {
			if (G.get_value() == 0) {
				G.fade(255, fadetime / 15);
			}
		}

		if (W.is_fading() == false) {
			if (W.get_value() == 0) {
				W.fade(100, fadetime / 15);
			}
		}
	}																	//Sunrise, yellow RGB strip
		
		if (now.hour() >= DayStart && now.hour() < SunsetStart) {            //Day, orange RGB strip, blue and white powerleds are fully on
			
			if (W.is_fading() == false) {
				if (W.get_value() == 100) {
					W.fade(255, fadetime / 15);
				}
			}
			if (BW.is_fading() == false) {
				if (BW.get_value() == 0) {
					BW.fade(220, fadetime / 15);
				}
			}

			if (G.is_fading() == false) {
				if (G.get_value() == 255) {
					G.fade(100, fadetime / 15);
				}
			}

		}
		if (now.hour() >= SunsetStart && now.hour() < NightStart) {        //SUNSET, red led strip

			if (BW.is_fading() == false) {
				if (BW.get_value() == 220) {
					BW.fade(255, fadetime / 15);
				}
			}

			if (W.is_fading() == false) {
				if (W.get_value() == 255) {
					W.fade(200, fadetime / 15);
				}
			}
			//R.fadeIn(6000 / 15, 255);
			
			if (G.is_fading() == false) {
				if (G.get_value() == 100) {
					G.fade(0, fadetime / 15);
				}
			}
		}


		if (now.hour() >= NightStart && now.hour() < OFFstart) {        //NIGHT, moonlight on, everything else turned off
			if (R.is_fading() == false) {
				if (R.get_value() == 255) {
					R.fade(100, fadetime / 15);
				}
			}
			if (G.is_fading() == false) {
				if (G.get_value() == 0) {
					G.fade(136, fadetime / 15);
				}
			}
			if (B.is_fading() == false) {
				if (B.get_value() == 0) {
					B.fade(255, fadetime / 15);
				}
			}
			if (W.is_fading() == false) {
				if (W.get_value() == 200) {
					W.fade(50, fadetime / 15);
				}
			}
			if (BW.is_fading() == false) {
				if (BW.get_value() == 255) {
					BW.fade(100, fadetime / 15);
				}
			}
		}
		if (now.hour() >= OFFstart || now.hour() < SunriseStart) {          //SHUTDOWN
			if (R.is_fading() == false) {
				if (R.get_value() == 100) {
					R.fade(0, fadetime / 15);
				}
			}
			if (G.is_fading() == false) {
				if (G.get_value() == 136) {
					G.fade(0, fadetime / 15);
				}
			}
			if (B.is_fading() == false) {
				if (B.get_value() == 255) {
					B.fade(0, fadetime / 15);
				}
			}
			if (BW.is_fading() == false) {
				if (BW.get_value() == 100) {
					BW.fade(0, fadetime / 15);
				}
			}
			if (W.is_fading() == false) {
				if (W.get_value() == 50) {
					W.fade(0, fadetime / 15);
				}
			}
	}
}

In a word NO, learn how to use SimpleTimer.

I know that i should call aqua() with timer, but thats not possible here, because i need to fade leds smoothly

Finally i get this to function state. I used HC-06 for communication between Blynk and my custom arduino board. And i also hosted my own Blynk server on AWS.
There is a git for arduino code, it will stay up to date with my system.
GIT link
The problem really wasnt in things in loop. You can run things in loop, unless they are nonblocking or aren’t sending values to Blynk App. The problem was in my RTC module, it didnt communicate with arduino, so DateTime was waiting for rtc.now() and therefore blocking loop. Now it all works great, i’m glad that blynk is here.