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;

BLYNK_ATTACH_WIDGET(rtc, V5);


void setup()
{
 Serial.begin(9600);
 setSyncInterval(1);
 Blynk.begin(auth, "network", "password");
  while (Blynk.connect() == false) {
    // Wait until connected
  }
 sensors.begin();
 sensors.setResolution(10);
 pinMode(relay, OUTPUT);
  setSyncInterval(30);
  rtc.begin();
  Blynk.syncAll();
 
 timerRT.setInterval(2000L, ReadTemp);
 timerRL.setInterval(2500L, Relay);
 
 }

bool isFirstConnect = true;
BLYNK_CONNECTED() 
{
  rtc.begin();
}

void ReadTemp() //Read temperature from sensor and activate relay
{
  sensors.requestTemperatures();
  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);
 
  if(digitalRead(relay)==LOW)
  {
    //lcd.print(0, 1, "DESLIGADO");
    led.off();
  }
  if(digitalRead(relay)==HIGH)
  {
    //lcd.print(0, 1, "LIGADO   ");
    led.on();
  }
 }

void Relay()
{
  if((userSet==1&&sensors.getTempCByIndex(0)<tempMin)||((sensors.getTempCByIndex(0)<tempMin)&&(18>hour()>15)))
  {
    digitalWrite(relay, HIGH);
    //lcd.print(0, 1, "LIGADO   ");
    led.on();
  }

   if(sensors.getTempCByIndex(0)>=maxTemp||((15>hour()||hour()>18)&&userSet==0))
  {
    digitalWrite(relay, LOW);
    //lcd.print(0, 1, "DESLIGADO");
    led.off();
  }
}

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()
{
  Blynk.run();
  timerRT.run();
  timerRL.run();
}

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?

Pete.

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
Screenshot_20200430-194152_Blynk|230x500

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.

Pete.

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.

Pete.

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?

Pete.

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.

Pete.

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