[SOLVED] ESP8266 Wrong date time year on RTC

I use ESP8266 connect with my blynk application ,but went open serial monitor it show wrong every thing, I use last library 0.3.4 I use code RTC

It means you haven’t obtained the time from the server. 1970 is the start of time as far as many computers are concerned.

Either your sketch doesn’t have all the corrects details for the Blynk RTC to work or the Blynk server failed to give you the time, for reasons unknown to me.

@nuedjidee pls post full sketch as Text with using </>

This is almost impossible :slight_smile:

I try long time it same result

i Use This Code

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <Ethernet.h>
//#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c97e47add7024b6c95ed2dd938859b08";

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V5);

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth,"WORK_2G", "arduinothai2015");

  while (Blynk.connect() == false) {
    // Wait until connected
  }

  // Begin synchronizing time
  rtc.begin();

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

// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details
  BLYNK_LOG("Current time: %02d:%02d:%02d %02d %02d %d",
            hour(), minute(), second(),
            day(), month(), year());
}

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

You need attach RTC widget to virtual pin in your app. Without it you cannot get time from server.

This my app . Use pin v…?

This is your problem. Free V5 and assign it to RTC widget.

@Dmitriy surely there is a limit to the number of simultaneous requests to your server?

@Costas yes. 100 req/sec per user. Usually if you don’t do

void loop() {
   BLynk.virtualWrite();
}

you never reach it :slight_smile:

No I was referring to different users accessing your system at the same time.

RTC widget is very flakey for me.

No limitations in that case. But it can make larger load on your board if you have widgets with Reading Frequency.

Now Year it true but Time it wrong my locate will +7 HR

How to Config ?

That is because the widget provides UTC / GMT. You need to adjust to your local time.

int gmthour = hour() + 2; if (gmthour == 24){ gmthour = 0; } String displayhour = String(gmthour, DEC); int hourdigits = displayhour.length(); if(hourdigits == 1){ displayhour = "0" + displayhour; } String displayminute = String(minute(), DEC); int minutedigits = displayminute.length(); if(minutedigits == 1){ displayminute = "0" + displayminute; } String displaysecond = String(second(), DEC); int seconddigits = displaysecond.length(); if(seconddigits == 1){ displaysecond = "0" + displaysecond; } String displaycurrenttime = displayhour + ":" + displayminute; String currenttime = "Time is " + displayhour + ":" + displayminute + ":" + displaysecond; Serial.println(currenttime); lcd.print(0, 1, currenttime); Blynk.virtualWrite(V11, displaycurrenttime);

I use this code for my location ,now it true but the day it wrong 1 day

That looks very like some of my code, or perhaps I borrowed it from someone.

Up until last weekend we were GMT +2 in our location but following DST we are now GMT +3.

If you are 7 hours ahead of GMT then you need to change +2 to +7 (plus / minus any DST you have in your country). Not sure why you would be out by a day without checking through the code.

Couple of useful sites we use for DST and Unixtime together with DST adjustment from BST are shown below. Not tested and GMFoffset is actually the number of hours to get to BST (not GMT as the variable name suggests).

// for DST and Unixtime see http://www.timeanddate.com/time/zone/uk/london and http://www.csgnetwork.com/time2unixdscalc.html
if((secsSince1900 > 1477360800) && (secsSince1900 < 1490490000)){ // winter 2016 / 17
  GMToffset = GMToffset - 1;  
}
if((secsSince1900 > 1509242400) && (secsSince1900 < 1521939600)){  // winter 2017 / 18
  GMToffset = GMToffset - 1;  
}
  if((secsSince1900 > 1540692000) && (secsSince1900 < 1553994000)){  // winter 2018 / 19
  GMToffset = GMToffset - 1;  
}

`// Digital clock display of the time
void clockDisplay()
{
ATime = now() + 60 * 60 * timeZone; // adjust time

BLYNK_LOG(“Current time: %02d:%02d:%02d %02d %02d %d”,
hour(ATime), minute(ATime), second(ATime),
day(ATime), month(ATime), year(ATime));

terminal.print(“Current time: “);
terminal.print(hour(ATime));
terminal.print(”:”);
terminal.print(minute(ATime));
terminal.print(":");
terminal.println(second(ATime));
terminal.flush();

}`

Easy to understand and works fine :slight_smile:

Or we can add timezone option for RTC :slight_smile:

1 Like

@Gdemon @Costas @nuedjidee wanted to say that I was able to successfully test RTC widget with TimeZone setting on UI. So in next release you don’t have to deal with crappy timezones in your code :wink:

3 Likes

you have example code for change date & year in other location ?