[SOLVED] RTC is not showing current time, shows year 1970 every time i power it up


    #define BLYNK_PRINT Serial

    //#include <Ethernet.h>
    //#include <BlynkSimpleEthernet.h>
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <SimpleTimer.h>
    #include <TimeLib.h>
    #include <WidgetRTC.h>


    char auth[] = "9xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    char ssid[] = "xxxxxxxxxxx";
    char pass[] = "xxxxxxxxxxxx";

    SimpleTimer timer;

    WidgetRTC rtc;

    // Digital clock display of the time
    void clockDisplay()
    {
      // You can call hour(), minute(), ... at any time
      // Please see Time library examples for details

      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();

      // Send time to the App
      Blynk.virtualWrite(V9, currentTime);
      // Send date to the App
      Blynk.virtualWrite(V10, currentDate);
    }

    void setup()
    {
      // Debug console
      Serial.begin(9600);


    Blynk.begin(auth, ssid, pass);
      // Begin synchronizing time
      while(Blynk.connect() == false){}

      rtc.begin();

      // Other Time library functions can be used, like:
      //   timeStatus(), setSyncInterval(interval)...
      // Read more: http://www.pjrc.com/teensy/td_libs_Time.html

      // Display digital clock every 10 seconds
      timer.setInterval(10000L, clockDisplay);
    }

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

Did you search this site for “1970”?

Yes, Ive been trying what worked for others but no luck so far.

The widget has been changed and you cant assign a virtual value now witch was a common mistake.

This is my serial output
[14262] Connected to WiFi
[14263] IP: 192.168.1.7
[14263]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.3 on Arduino

[14334] Connecting to blynk-cloud.com:8442
[14684] Ready (ping: 1ms).
[19685] Connecting to blynk-cloud.com:8442
[20876] Ready (ping: 1ms).
Current time: 0:0:31 1 1 1970
Current time: 0:0:41 1 1 1970

Current time: 4:11:50 1 1 1970
Current time: 4:12:0 1 1 1970
Current time: 4:12:10 1 1 1970
Current time: 4:12:20 1 1 1970
Current time: 4:12:30 1 1 1970
Current time: 4:12:40 1 1 1970
Current time: 4:12:50 1 1 1970
Current time: 4:13:0 1 1 1970
Current time: 4:13:10 1 1 1970
Current time: 4:13:20 1 1 1970
Current time: 4:13:30 1 1 1970

When you do a search switch relevance to most recent, the fix is there.

@VANGDE

Are you running Local Server… I believe RTC gets it’s time from the server… perhaps you installed Local Server in a DeLorean? :stuck_out_tongue:

But in all seriousness… make sure your server time is correct.

Opps… now I check :blush: … hope I didn’t ruin the surprise.

Double opps… I think I will go home now…

Hm, my intention is that my esp8266 to connect through wifi to my router and from there to blynk server in order to get the current time based on the timezone ive selected in my blynk app.

The sckech is esentially the blynk example but with wifi instead of ethernet.

I cant see yet what im missing.

time?[quote=“Gunner, post:6, topic:11261”]
[14334] Connecting to blynk-cloud.com:8442[14684] Ready (ping: 1ms).
[/quote]

I know that it is too short but who is sending the 1970 time?

@vangde your ESP is giving you 1970, as per the libraries. That is always the ESP “time” on reboot until it collects the correct time from Blynk.

Ok, so you say it never connects to blynk server?
What could be the cause of it, since the code is essentially from blynk.
Missing or bad libraries?

No it connects to the Blynk server but it isn’t picking up the time from the server.
I have used Blynk a lot over the last 12 months or so and when I was testing out the recent widget change I couldn’t believe it wouldn’t give me the correct time.
After a few hours, literally, I realised I had forgotten to add the widget to the project. So I had the code in the sketch but there was no call from the app for the time.

1 Like

You might want to try the 0.4.4 library that has the new RTC widget.

1 Like

Costas, you are a hero!!

It needed the 0.4.4 library in order to work with the new RTC widget

As per the Announcement and the second most recent “1970” post (ignoring yours).

I think you might also need to change the app to ESP as Serial Monitor shows you have selected Arduino. Not sure if the old 0.4.3 was incorrectly showing Arduino for ESP’s but it should certainly show ESP now with 0.4.4.

My device is a WeMos D1 Mini actually but it doesnt seems to cause any problems that i have declared wrong device to the app.

It will for sure as the pins are all different. Do you have Arduino or Generic ESP selected and if Generic does Serial Monitor show ESP8266 now?

I guess you are right but i wasnt using any actual digital pins, It said arduino since i hanent changed my device yet.

Better to change sooner rather than later, unless you are never going to use physical pins, because when you make the change it “resets” the widgets. If you have 4 full tabs of widgets it is a pain going through and updating them all.

Yes i realized that recently. I have 2 tabs of widgets that i will have to redo but the most important part was the code that wasnt working. And thanks to you now it is!

1 Like

Sorry guys, but the problem not solved.
I’ve tried standard example RTC with w5500 shield.
With the cloud server works good. But with local server don’t works

Last library and the same result:

[0] Getting IP...
[2269] IP:192.168.0.9
[2270] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.8 on Arduino Mega

[5001] Connecting to 192.168.0.34
[5211] Ready (ping: 7ms).
Current time: 0:0:15 1 1 1970
Current time: 0:0:25 1 1 1970
Current time: 0:0:35 1 1 1970
Current time: 0:0:45 1 1 1970
Current time: 0:0:55 1 1 1970

server’s side time:

pi@raspberrypi:~ $ date
Fri 13 Oct 20:58:40 MSK 2017