RTC showing time elapsed since start and not current time

I have this project that has been running for a long time now and suddenly stoped working. When I was checking if there was any hardward malfunction I notice that the problem is the value I’m getting from RTC.
I tried to make it sync many times but no luck. It keep returning me the amout of time since I turned it on and not the current time…
I’m using a NodeMCU ESP8266 wth a DS18B20. I’ll be really happy if anybody can give me a hand here

#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO 
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h> 
#include <DallasTemperature.h>
#include <WidgetRTC.h>
#include <TimeLib.h>

SimpleTimer timerRT;
SimpleTimer timerRL;

WidgetLCD lcd(V1);
WidgetRTC rtc;
WidgetLED led(V9);

#define Pin D3//  pin DATA ds18b20
#define relay D4

char auth[] = "auth";

OneWire ourWire(Pin); 
DallasTemperature sensors(&ourWire); 

int userSet;
int maxTemp;
int timerCheck;
int tempMin;
char currentTime;


void setup()
 Blynk.begin(auth, "network", "password");
  while (Blynk.connect() == false) {
    // Wait until connected
 pinMode(relay, OUTPUT);
 timerRT.setInterval(2000L, ReadTemp);
 timerRL.setInterval(2500L, Relay);

bool isFirstConnect = true;

void ReadTemp() //Read temperature from sensor and activate relay
  lcd.print(0, 0, "Temp:");
  lcd.print(5, 0, String(sensors.getTempCByIndex(0),1));
  lcd.print(10, 0,"MAX:"); 
  lcd.print(14, 0, maxTemp);
  lcd.print(10, 1, "MIN:");
  lcd.print(14, 1, tempMin);
  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  lcd.print(0, 1, currentTime);
    //lcd.print(0, 1, "DESLIGADO");
    //lcd.print(0, 1, "LIGADO   ");

void Relay()
    digitalWrite(relay, HIGH);
    //lcd.print(0, 1, "LIGADO   ");

    digitalWrite(relay, LOW);
    //lcd.print(0, 1, "DESLIGADO");

BLYNK_WRITE(V7) //Check user selection (On/Off)
    userSet = param.asInt();

BLYNK_WRITE(V8) //Check user max temperature setting
    maxTemp = param.asInt();
    tempMin = maxTemp - 2;

void loop()

Is the NodeMCU connecting successfully with Blynk and showing the ping result?
If it is then maybe try deleting the RTC widget from the app and add it back in again?


Yeah, I’m actually receiving information from it and can activate stuff with the button but not with the RTC.
I turned it on around 50min ago.
I tried removing the RTC and adding back but no luck. Even when I try changing the time zone nothing happens

This line of code looked a bit odd, as the RTC widget doesn’t have a pin attached to it. A Quick search showed this:

I’m guessing that deleting the RTC widget will be necessary, and maybe changing your code slightly as discussed in the topic linked above.


Well, after removing the RTC I realized the time count was still going on…
Guess I’ll try updating my Blynk lib and see if it will solve the problem

It will do, that’s how the code is written.
You’d need to reboot your device or wait for an RTTC sync to happen.


I think there is, as you can’t attach the RTC to a virtual pin now.

Maybe you updated your Blynk app and it’s no longer compatible with the RTC widget structure that you had?


1 Like

Just updated everything and now having some trouble with the #include <BlynkSimpleEsp8266.h>
Getting some error
\Arduino\libraries\Blynk\src/WidgetRTC.h:37:5: error: 'Blynk' was not declared in this scope Blynk.sendInternal("rtc", "sync")
No luck trying to fix it. Can’t even find the line that’s giving me error

This line is causing the error for me, but not the same one you’re getting:

With that commented-out the code compiles for me. If it doesn’t compile for you then I think that you probably have a problem with the way you’ve installed the Blynk library update.

You have these two lines in your void setup:

I think you should probalt remove the first one.

BTW, you don’t need two separate timers to achieve what you want. One single timer instance (usually declared as timer) can have up to 16 timers attached to it.


1 Like

So, I found out that I was having some confict with functions under the same name on Blynk and SimpleTimer libraries.
Changed all names on SimpleTimer and edited code a bit since they don’t use some parameters I was using to call function and now everything seems to running fine.
Just have to upload to board again and see if RTC works.
UPDATE: After changing SimpleTimer library names everything is fine

1 Like