Hi all,
I have a problem with RTC.
The first time I try to get time I get back year-> 1970
Thx,
Andreas
Here is my code:
#define BLYNK_PRINT Serial
#include "SimpleTimer.h"
#include <Ethernet.h>
#include <BlynkSimpleEsp8266.h>
#include <DallasTemperature.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
const char* auth = "0fd--------a-d4";
const char* ssid = "xxx";
const char* password = "xxxx"; //del
WidgetLED GarageLed(V6);
WidgetRTC rtc;
WidgetTerminal BlynkTerminal(V2);
boolean AlarmState = false;
boolean NightMode;
int AlarmTimerId;
int PIRState = false;
unsigned long LastAlarmMillis;
SimpleTimer AlarmTimerOff;
SimpleTimer Timer1;
bool isFirstConnect = true;
BLYNK_ATTACH_WIDGET(rtc, V5);
//==================================================================================
//==================================================================================
BLYNK_CONNECTED()
{
if (isFirstConnect)
{
Blynk.syncAll();
isFirstConnect = false;
}
}
//==================================================================================
//==================================================================================
void clockDisplay()
{
Serial.println (TimeS());
}
//==================================================================================
//==================================================================================
String lpad(String txt, byte width, String pattern) {
String tmp = txt;
for (byte i=tmp.length(); i<width; i++)
tmp = pattern + tmp;
return tmp;
}
//==================================================================================
//==================================================================================
String TimeS()
{
String currentTime = lpad(String(hour()), 2, "0") + ":" + lpad(String(minute()), 2, "0") + ":" + lpad(String(second()), 2, "0");
String currentDate = String(day()) + "/" + month() + "/" + year();
return (currentDate + " " + currentTime);
}
//==================================================================================
//==================================================================================
void setup()
{
Timer1.setInterval(3000, clockDisplay);
Serial.begin(115200);
Blynk.begin(auth, ssid, password);
while (Blynk.connect() == false) {}
Serial.println("Connected To Blynk");
rtc.begin();
}
//==================================================================================
//==================================================================================
void loop()
{
Blynk.run();
Timer1.run();
}
And the output I get:
[3247] Connected to WiFi
[3247] IP: 192.169.200.162
[3247] Blynk v0.3.7 on ESP8266
[5001] Connecting to blynk-cloud.com:8442
[5182] Ready (ping: 1ms).
Connected To Blynk
1/1/1970 00:00:05
[5375] Time sync: OK
13/6/2016 09:30:21
13/6/2016 09:30:24
13/6/2016 09:30:27
13/6/2016 09:30:30
13/6/2016 09:30:33
13/6/2016 09:30:36