ds3231 rtc

so, i’m using the following rtc library https://github.com/rodan/ds3231 what i’m trying to achieve is for a relay to turn on at 5am and off at 9pm.
i get the following error. thanks in advance for the help!!!

growcode2.3:53: error: 'hour' was not declared in this scope

   if (hour() > 5 && (!Encendido)) {

            
 Not used: C:\Program Files (x86)\Arduino\libraries\DHT-sensor-library-master
exit status 1
'hour' was not declared in this scope

part of code where problem is

void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  if (hour() > 5 && (!Encendido)) {
    Serial.print("hola");
    Encendido = true;
    }
    else if (hour() > 21 && (Encendido)) {
      Encendido = false;
    }
    timer_update(&ft2000, &t2000, timeout_t2000);
  }

full code:

#include <Arduino.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include "DHT.h"
#include "timer.h"
#include "TimerOne.h"
#include <Wire.h>
#include <RtcDS3231.h>


#define Rele 5
#define DHTTYPE DHT22
#define BLYNK_PRINT Serial
#define W5100_CS  10
#define SDCARD_CS 4
#define DHTPIN 2


int t2000, ft2000;
int sensorPin = 0;
int sensorValue = 0;
int ht = 0;
int tref = 0;
boolean Encendido = false;
char auth[] = "";
DHT dht(DHTPIN, DHTTYPE);
RtcDS3231<TwoWire> Rtc(Wire);

void setup() {
  Serial.begin(9600);
  //--------RTC SETUP ------------
  Rtc.Begin();
  RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
  RtcDateTime now = Rtc.GetDateTime();
  if (now < compiled)
  {
    Rtc.SetDateTime(compiled);
  }
  Rtc.Enable32kHzPin(false);
  Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
  //--------BLYNK SETUP-----------
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  Blynk.begin(auth);
}


void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  if (hour() > 5 && (!Encendido)) {
    Serial.print("hola");
    Encendido = true;
    }
    else if (hour() > 21 && (Encendido)) {
      Encendido = false;
    }
    timer_update(&ft2000, &t2000, timeout_t2000);
  }

  void timeout_t2000() {
    float t = dht.readTemperature();
    float h = dht.readHumidity();
    Blynk.virtualWrite(V1, t);
    Blynk.virtualWrite(V2, h);
    if (isnan(h) || isnan(t)) {
      return;
    }
    sensorValue = analogRead(sensorPin);
    ht = 1023 - sensorValue;
    Blynk.virtualWrite(V3, ht );
    timer_reset(&ft2000, &t2000, 2000);
  }
#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
    char datestring[20];

    snprintf_P(datestring, 
            countof(datestring),
            PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
            dt.Month(),
            dt.Day(),
            dt.Year(),
            dt.Hour(),
            dt.Minute(),
            dt.Second() );
    Serial.print(datestring);
}

hour() would be a call to a function named "hour", which you have not defined.

Take a closer look at the library documentation on how to access the time.

i have read de .h and .cpp files haven't found what i'm looking for, maybe because i don't know what to look for? if you could give me some pointers it would be much apretiated.

You print the hour in the code you most recently posted.

Use the same method to access the hour, in other program statements.

so, like this?

:frowning:

void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  if (dt.hour() > 5 && (!Encendido)) {
    Serial.print("hola");
    Encendido = true;
    }
    else if (dt.hour() > 21 && (Encendido)) {
      Encendido = false;
    }
    timer_update(&ft2000, &t2000, timeout_t2000);
  }

Close!
Spelling and capitalization is extremely important.

thanks, i'm beating my head against the desk tho. :wink:

void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  if (dt.Hour(), > 5 && (!Encendido)) {
    Serial.print("hola");
    Encendido = true;
    }
    else if (dt.Hour()() > 21 && (Encendido)) {
      Encendido = false;
    }
    timer_update(&ft2000, &t2000, timeout_t2000);
  }

Not used: C:\Program Files (x86)\Arduino\libraries\DHT-sensor-library-master
exit status 1
'dt' was not declared in this scope
:confused:

You need to start with code that actually compiles and runs.

I'm not familiar with any of those libraries.

the only thing that doesn't compile is the

if (dt.Hour(), > 5 && (!Encendido)) {
Serial.print("hola");
Encendido = true;
}
else if (dt.Hour()() > 21 && (Encendido)) {
Encendido = false;
}

what i need to know is how do i call the hour so i can compare it to a set value.

garyocampo:

  if (dt.Hour(), > 5 && (!Encendido)) {

and

    else if (dt.Hour()() > 21 && (Encendido)) {

Look at those lines. Look very carefully at the punctuation.

So it looks like your problem is that you've named your datetime object where you store the time data "now" not "dt" in the portion of the code that's giving you errors, so in order to look at the hour, you would call now.hour () not dt.hour (). If you replace the dt.hour ()'s with now.hour ()'s in the portion of the code that isn't compiling (and fix the syntax error) I think it would work.

ok fixed sintax error (slams head to desk). but i still get an error.

void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  if (now.hour() > 5 && (!Encendido)) {
    Serial.print("hola");
    Encendido = true;
    }
    else if (now.hour() > 21 && (Encendido)) {
      Encendido = false;
    }
    timer_update(&ft2000, &t2000, timeout_t2000);
  }
 Not used: C:\Program Files (x86)\Arduino\libraries\DHT-sensor-library-master
exit status 1
'class RtcDateTime' has no member named 'hour'

Hmm. Maybe double check your capitalization, the H in hour might need to be capitalized if that's how the function is named in the library.

thanks everyone for the help!!!!!
the code now reads as follows

void loop() {
  Blynk.run();
  RtcDateTime now = Rtc.GetDateTime();
  //encendido y apagado del led
  if (now.Hour() > 5) {
    Serial.println("hola");
    digitalWrite(rele, HIGH);
  }
  else if (now.Hour() > 21) {
    Serial.println("chau");
    digitalWrite(rele, LOW);
  }
  timer_update(&ft2000, &t2000, timeout_t2000);
}