[SOLVED] RTC widget show date time wrong

Hello everyone , I’m trying the new RTC widget on cloud server , I tried the example RTC , modifying it to work with the esp8266 as shield in hardware serial . The sketch seems to work correctly only that returns me the date and time 1/1/1970 0 : 0 : 0 , after ten seconds to change time in 0 : 0 : 10 , a sign that the rtc not ’ locked .
In practice it seems that the date and time are not synchronized , and this ’ the scketch I used an Arduino Mega :

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * Blynk can provide your device with time data, like an RTC.
 * Please note that the accuracy of this method is up to several seconds.
 *
 * App dashboard setup:
 *   RTC widget on V5
 *
 * WARNING :
 * For this example you'll need SimpleTimer library:
 *   https://github.com/jfturcot/SimpleTimer
 *
 * And also this Time keeping library:
 *   https://github.com/PaulStoffregen/Time
 *
 * This code is based on an example from the Time library:
 *   https://github.com/PaulStoffregen/Time/blob/master/examples/TimeSerial/TimeSerial.ino
 *
 **************************************************************/

//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <SimpleTimer.h>
#include <Time.h>
#include <WidgetRTC.h>

#define EspSerial Serial1

ESP8266 wifi(EspSerial);

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V5)

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

void setup()
{
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "Indianet", "pimapima");
Serial.println(dentrowhile
  while (Blynk.connect() == false) {
    // Wait until connected
  }

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

Serial.print("|");
  Serial.print(hour());
  Serial.print(minute());
  Serial.println(second());
  Serial.print(day());
  Serial.print(month());
  Serial.println(year());
}

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

and this the results:

|0026
111970
|0036
111970
|0046
111970
|0056
111970
|016
111970
|0116
111970
|0126
111970
|0136
111970
|0146
111970
|0156
111970
|026
111970
|0216
111970
|0226
111970
|0236
111970

Am I wrong something?

Confirms. @vshymanskyy please fix.

1 Like

Please check the latest library and RTC widget example.

Thanks when I download it? From github or your website?

both links updated… any will do

Thanks, but unfortunately, even with the latest library , discharged today from the site blynk.cc the result ’ the same …

  1. Did you try latest example?
  2. Can you enable BLYNK_DEBUG and show your log?

Screenshot below of the RTC working ok with ESP-01 and WeMos D1 Mini.
We had to make an adjustment from GMT to local time in our sketch.

1 Like

@Costas,
I’m trying to show the time using the “Value display” widget (v0) and I’m doing something wrong…
this is the piece of code:

Blynk.virtualWrite(0,hour(),":",minute());

At the app side I see this:

What am I doing wrong? It should be something really silly…:confused:

Thanks for this widget!!! This is something really useful!!

Regards

@psoro the 20 is because you are 1 hour ahead of GMT in your location, which is 21 hours.

Quite messy code but this is what we did:

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

LCD showing hours, minutes and seconds, Value Display just hours and minutes.

1 Like

you should create a string with results from RTC widget and only then push it to the Virtual Pin of Value Display.

So my messy code was necessary based on string @Pavel.

Thanks @Costas and @Pavel!

Now it looks much better!! The trick was the string as you said.

I’ll adjust the hour for my location with a bit of code, no worries.

Thanks again!!

I notice the time here is now 25:58 ! Slight correction to the following lines in my earlier sketch:

  if (gmthour == 24){
     gmthour = 0;
  }

Should be:

  if (gmthour > 23){
     gmthour = gmthour - 24;
  }
2 Likes

Ok I have forgot RTC.begin(), now work as expected thanks