Ethernet Shield using Alarms for Garduino

I'm having some troubles using the time info taken from the UDP server.
I'm setting a timer to water the plants two times a day.
I'm trying to call a function (water) at a specific time but it is not working.
Any help?

   void Night() {
     int nowHour;
     nowHour=hour();
     int nowMinutes;
     nowMinutes=minute();
     int nowSeconds;
     nowSeconds=second();

     if (nowHour==21&&nowMinutes==59&&nowSeconds==40){
        Water();
        }
   }

What values do you get for nowHour, nowMinutes and nowSeconds if you print them ?

What calls the Night() function ?

Please post your whole program.

The Night function is called by

Alarm.alarmRepeat(21,26,30, Night);

set at void setup ().

I’m assuming that hour () prints the present hour since digitalClockDisplay function bellow displays the time stamp.

void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" “);
Serial.print(day());
Serial.print(” “);
Serial.print(month());
Serial.print(” ");
Serial.print(year());
Serial.println();

Alarm.alarmRepeat(21,26,30, Night);This calls the Night() function at 21:26:30 each day. Why then does the Night() function check to see whether the time is something different ?

     if (nowHour==21&&nowMinutes==59&&nowSeconds==40){
        Water();
        }

Actually i've tried both ways separatelly.
The alarm function for some reason does not trigger the function so i've tried the other option but it did not work.
I'll try to clean The code and post it Like you suggested.

If you know what time it is, you don't need the Alarm class. You can call Water() from loop() at the appropriate time.

If you want to call Water() from Night(), you can do that, too. Just be sure to call Night() often enough from loop().

The alarm function for some reason does not trigger the function

Does not trigger what function? How do you know it doesn't?

Could you give an example how to call a determined function at a certain time at loop?

Could you give an example how to call a determined function at a certain time at loop?

int waterHour = 5;
int waternMin = 0;
int waterSec = 0;
bool watered = false;

void loop()
{
   if(hour() == waterHour && minute() == waterMinute && second() == WaterSecond && !watered)
   {
       Water();
       watered = true;
   }
   else
       watered = false;
}

Excuse my lack of knowledge but you first created a new int called watered. Then inserted the watered boolean as false.
Why is it necessary?

Code:
int waterHour = 5;
int waternMin = 0;
int waterSec = 0;
bool watered = false;

void loop()
{
   if(hour() == waterHour && minute() == waterMinute && second() == WaterSecond && !watered)
   {
       Water();
       watered = true;
   }
   else
       watered = false;
}

but you first created a new int called watered.

Where?

Then inserted the watered boolean as false.

The variable I created was a boolean called watered, with an initial value of false.

Sorry, it was a boolean.
But why is it necessary? The If by itself isn't enough?

Thanks,

It is a safeguard to ensure that the water() function only gets called once when the time to water matches the current time. Probably not a problem when the timing is to the second but imagine what might happen if the timing was being done only to the minute, particularly if the water() function is non blocking, which it should be.

Thanks a lot!
I'll work on the code this weekend and i'll give it a try.

Thanks UKHelibob and PaulS!

i've tried this alteration last weekend and our house didn't get flooded.

:slight_smile:

Regards,