WidgetRTC starting 1 1 1970

Hi, I am having problems with the RTC I am using the std. sketch from Blyk examples.
Is there anyone that can help me??

#include <Time.h>
#include <TimeLib.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WidgetRTC.h>

char auth[] = "9342e0e92bxxxxx8befc8a664b";
char ssid[] = "Roennebaervejxx";
char pass[] = "rahbekxx";

BlynkTimer timer;
WidgetRTC rtc;

void clockDisplay()
{
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  Blynk.virtualWrite(V1, currentTime);
  Blynk.virtualWrite(V2, currentDate);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  rtc.begin();
  timer.setInterval(1000L, clockDisplay);
}

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

Don’t post unformatted sketches to the forum.

Do you have the RTC widget in your project?

Move rtc.begin() to:

BLYNK_CONNECTED() {
   rtc.begin();
}

If this fails try RTC Advanced example.

I’m using the method given in advanced RTC example and that works well for me. If you include widgetrtc.h, it will not compile.

As @Costas said, move rtc.begin to BLYNK_CONNECTED() as only after the Blynk connection can the RTC sync with the server. If the widget is not instanced in you UI, the RTC will never sync.

1 Like

Thanks both for your fast response. I have struggled with this RTC for some days now, I tried both RTC and advanced without succes. I am an amateur sorry for not understanding but if using the std example from Blynk where do I put the BLYNK_CONNECTED? Tried several places but get an: ‘rtc’ was not declared in this scope.

It’s a free standing function so pretty much anywhere. If you want a particular place let’s say between setup() and loop().

Hi Costas, sorry I tried the BLYNK_CONNECTED without result. It passes the compiler without failures, but still shows counting from “0” time and 1970. I also tried the advanced type here it also compiles fine but do not print any time. Just connecting like this:
[4228] Connected to WiFi
[4228] IP: 192.168.0.43
[4228]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.5.0 on NodeMCU

[4298] Connecting to blynk-cloud.com:8442
[4429] Ready (ping: 0ms)

I have Blynk sketch with 3 sensores running without problems.

@rahbek you still haven’t answered this question… it is a required widget (and set for your timezone) if you want to use Blynk’s RTC

Also, why do you need Time.h? Having multiple Time libraries could also add to your issue.

Hi both,
I misunderstood the RTC widget to be included. I also found that I do not need double time liberaries. Everything is working now. THANKS for your understanding and help.

1 Like