Page 1 of 1

Re: Countdown timer for relay

Posted: Sun Oct 11, 2015 3:46 pm
by lnevo
What is the port supposed to do. Just cause the code you posted is gonna run that port for 2 minutes every 6 hours.

Try and put the following before the if statement.

ReefAngel.Relay.Off(Box2_Port6);

Is that the port your using anyway? You have to change the code to use the correct port. I don't see any Box1 or other Box2 ports...

Re: Countdown timer for relay

Posted: Sun Oct 11, 2015 4:07 pm
by paperdesk
Facepalm ;) I thought that having two boxes meant I had a box 1 and a box 2. After reading your comment I realized that box 1 is actually my second box. After that came together it was simple to change the time values and remove the "else" line and it's working perfectly. Thanks!

Re: Countdown timer for relay

Posted: Sun Oct 11, 2015 9:11 pm
by lnevo
Awesome. Can you post your final code that you used.

Re: Countdown timer for relay

Posted: Mon Oct 12, 2015 7:54 am
by paperdesk
I ran into some issues last night, but think it's working now. I'll post the code once I'm sure it's stable and correct, just doing a little testing today.

Re: Countdown timer for relay

Posted: Wed Oct 14, 2015 8:09 am
by paperdesk
Here's what I ended up with. It runs for one hour and repeats every two days. , I have to wait two days to be sure it actually repeats, but I think it will:

Code: Select all

  int repeat=2880; // in minutes
  int runtime=3600; // in seconds
  static time_t t;
  
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Box1_Port6)) {
    ReefAngel.Relay.Auto(Box1_Port6);
    t=now();
  }  

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Box1_Port6);
  } else {
    ReefAngel.DosingPumpRepeat(Box1_Port6,0,repeat,runtime);    
  }  

Re: Countdown timer for relay

Posted: Wed Oct 14, 2015 8:13 am
by lnevo
Cool and triggering manually is working? What are you automating here?

Re: Countdown timer for relay

Posted: Thu Oct 15, 2015 8:39 am
by paperdesk
Yep, when I toggle the relay from the app it opens the relay for the set amount of time (60 minutes currently) and shuts off again. It then runs automatically every two days for 60 minutes.

I'm using this code to control a solenoid on my RODI system. It refills my fresh water container on a regular basis and other containers on demand.

My fresh water container has a shut off float in it, but I overflowed other water containers too many times, so it's nice to have something that will shut off automatically.

I wonder if this function could be built into the app that would allow one to start a countdown timer for any relay, after which the relay would return to its normal function. Seems like something a lot of people would use, and would be a lot simpler than changing to code frequently.

Re: Countdown timer for relay

Posted: Thu Oct 15, 2015 12:53 pm
by lnevo
I have a class in the libraries called TimedPort that does this. I would recommend looking at the water level sensor module and then just using the WaterLevelATO function to control the solenoid.