Dosing at Night

Do you have a question on how to do something.
Ask in here.
Post Reply
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Dosing at Night

Post by chase »

Was messing around with some of the code I found around the forums but I'm still having trouble figuring out how to implement the timeframe. I would like to dose between the hours of 2200-0500 every hour for 2 secs.
I've got the code Roberto posted for someone else working, just not during the range of time I would like.
Here's the code so far:

Code: Select all

      if (ReefAngel.DisplayedMenu==255 && minute()==0 && second()<4)  //Alk Doser - Only works if Main screen is showing
        ReefAngel.Relay.On(AlkDoser);  //Turn Alk Doser on
      else
        ReefAngel.Relay.Off(AlkDoser);  //Turn Alk Doser off
      if (ReefAngel.DisplayedMenu==255 && minute()==5 && second()<4)  //CA Doser - Only works if Main screen is showing
        ReefAngel.Relay.On(CaDoser);  //Turn CA Doser on
      else
        ReefAngel.Relay.Off(CaDoser);  //Turn CA Doser off
Here's the link to the forum I found it in: http://forum.reefangel.com/viewtopic.ph ... pump#p3005
Thanks for your help!
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Dosing at Night

Post by binder »

chase wrote:Was messing around with some of the code I found around the forums but I'm still having trouble figuring out how to implement the timeframe. I would like to dose between the hours of 2200-0500 every hour for 2 secs.
Here's some code that should work for you. It will dose at the top of the hour, every hour in your time frame, for 2 seconds. It is hard coded, so if you want to be able to change the values via the wifi interface just let me know and we can do something like in the other thread you referenced.

Code: Select all

if ( ReefAngel.DisplayedMenu == DEFAULT_MENU ) 
{
	/* 
	Hours between 22 and 5
	minute must be 0 (top of the hour)
	seconds less than 2 (up to 2 seconds)
	*/
	if ( ((hour() >= 22) || (hour() <= 5)) &&
		 (minute() == 0) && 
		 (second() < 2) )
	{
		ReefAngel.Relay.On(Port1);
	}
	else 
	{
		ReefAngel.Relay.Off(Port1);
	}
}
You will want to change the Port1 to whatever the port it is you want to turn on/off. If you want to dose multiple pumps and stagger the dose time or minute, just copy the inner if statement and adjust accordingly (ie, change the minute or second).

curt
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Dosing at Night

Post by chase »

Awesome, thanks curt. Gonna test it out over the few days with a couple bottles of RO.

Oh, I forgot to mention it in the original post but I like having the 2nd doser come on 5 minutes later. So would that look like this (would modify the port as well)?

Code: Select all

if ( ReefAngel.DisplayedMenu == DEFAULT_MENU )
{
   /*
   Hours between 22 and 5
   minute must be 0 (top of the hour)
   seconds less than 2 (up to 2 seconds)
   */
   if ( ((hour() >= 22) || (hour() <= 5)) &&
       (minute() == 5) &&
       (second() < 2) )
   {
      ReefAngel.Relay.On(Port1);
   }
   else
   {
      ReefAngel.Relay.Off(Port1);
   }
}
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Dosing at Night

Post by rimai »

You got it.
Just make sure to change the Port1 to another Port instead of 1.
Roberto.
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Dosing at Night

Post by chase »

I've been messing with the code for a while and for some reason it seems to dose more than the specified times. I have it set up to dose over night. In the morning before I leave for work in the I make sure to check the level in the test vials and then empty them. When I get home I find water in them, and they seem to dose throughout the evening as well. I'm assuming the controller is setup on an internal 24hr clock (instead of am/pm) so that would rule out dosing at 3am and 3pm, etc. Here's my code:

Code: Select all

#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>

#define Daylight            1
#define AutoTopOff          2
#define Heater              3
#define Return              4
#define WavemakerL          5
#define WavemakerR          6
#define LEDs                7
#define Refugium            8
#define Heater2             11
#define CaDoser             15
#define AlkDoser            16

void setup()
{
   randomSeed(analogRead(0)); //wm stuff 
    ReefAngel.Init();  //Initialize controller   
    ReefAngel.FeedingModePorts = B00001000;
//    ReefAngel.WaterChangePorts = B00000000;
//    ReefAngel.OverheatShutoffPorts = B00000101;
//    ReefAngel.LightsOnPorts = B00000001;
    // Ports that are always on
    ReefAngel.Relay.On(Return);
   //wm stuff
    ReefAngel.Timer[1].SetInterval(random(15,35));
    ReefAngel.Timer[1].Start(); 
    ReefAngel.Relay.On(WavemakerL);
}

void loop()
{
    ReefAngel.ShowInterface();
//Temp 1 settings
       // Turn on Heater2 when the temp < 76.8 degrees
          if ( ReefAngel.Params.Temp1 <= 768 ) ReefAngel.Relay.On(Heater2);
          // Turn off Heater2 when the temp > 77.0 degrees
          if ( ReefAngel.Params.Temp1 >= 770 ) ReefAngel.Relay.Off(Heater2);
//    ReefAngel.StandardFan(Chiller,775,783); Removed for ATO function
    ReefAngel.StandardHeater(Heater,768,771); 
    ReefAngel.StandardLights(Daylight,9,0,21,00);  //Daylight schedule 9:00am - 8:30pm
    ReefAngel.StandardLights(Refugium,21,0,9,0);  //Refugium schedule 9:00pm - 9:00am
    ReefAngel.StandardLights(LEDs,8,30,22,30);  //LED schedule 8:30am - 10:30am
    ATOFailSafe(AutoTopOff); //ATO Stuff  
//Wavemaker
    if ( ReefAngel.Timer[1].IsTriggered() )
      {
        ReefAngel.Timer[1].SetInterval(random(15,30));
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Toggle(WavemakerL); //port 5
        ReefAngel.Relay.Toggle(WavemakerR); //port 6
       }
//Dose Ca
                   if ( ReefAngel.DisplayedMenu == DEFAULT_MENU ) //Alk Doser - Only works if Main screen is showing
              {
               /*
               Hours between 12am and 3am
               minute must be 0 (top of the hour)
               seconds less than 2 (up to 2 seconds)
               */
               if ( ((hour() >= 12) || (hour() <= 3)) && (minute() == 0) && //dose time
                   (second() < 2) ) //dose duration
               {
                  ReefAngel.Relay.On(CaDoser);
               }
               else
               {
                  ReefAngel.Relay.Off(CaDoser);
               }
            }
  
//Dose Alk
                   if ( ReefAngel.DisplayedMenu == DEFAULT_MENU ) //Ca Doser - Only works if Main screen is showing
              {
               /*
               Hours between 12:05am and 3:05am
               minute must be 0 (top of the hour)
               seconds less than 2 (up to 2 seconds)
               */ 
               if ( ((hour() >= 12) || (hour() <= 3)) && (minute() == 5) && //dose time
                   (second() < 2) ) //dose duration
               {
                  ReefAngel.Relay.On(AlkDoser);
               }
               else
               {
                  ReefAngel.Relay.Off(AlkDoser);
               }
            }  
}

void ATOFailSafe(byte ATO) //changed port to fATO
{
   // Check for the low switch
   /*
   If the Low switch is active, meaning the float is opposite the end with the two wires,
        we are empty so we should turn on the pump.  Otherwise, we are full, so turn off the port.
   */
   if ( ReefAngel.LowATO.IsActive() )
   {
      ReefAngel.LowATO.StartTopping();
      ReefAngel.Relay.On(ATO);
   }
   else
   {
      ReefAngel.LowATO.StopTopping();
      ReefAngel.Relay.Off(ATO);
   }

   if ( ReefAngel.LowATO.IsTopping() && ! ReefAngel.HighATO.IsActive() )
   {
      // We have a problem
      /*
      The pump is running and topping but the low switch isn't shutting off the port.
      We must shutoff the port ourself.
      */
      ReefAngel.Relay.Off(ATO);
      // Trigger some sort of alert, maybe an email or text message

      /*
      We did not indicate that the port is not topping anymore, we could do that manually
      OR we could not do it and replace the switch and have the controller do it for us.
      It's completely up to the user.
      At this point, it shouldn't matter because there is a problem with the switch and that
      needs to be addressed.
      */
  }
}
Thanks for the help!
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Dosing at Night

Post by rimai »

You are correct. It's in military hours.
So, change this:

Code: Select all

if ( ((hour() >= 12) || (hour() <= 3)) && (minute() == 0) && //dose time
To this:

Code: Select all

if ( ((hour() >= 0) || (hour() <= 3)) && (minute() == 0) && //dose time
Try it out and let me know if this worked.
Roberto.
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Dosing at Night

Post by chase »

rimai wrote:You are correct. It's in military hours.
So, change this:

Code: Select all

if ( ((hour() >= 12) || (hour() <= 3)) && (minute() == 0) && //dose time
To this:

Code: Select all

if ( ((hour() >= 0) || (hour() <= 3)) && (minute() == 0) && //dose time
Try it out and let me know if this worked.
Okay, I see where I had the time messed up but it's still dosing outside of midnight and 0300. The code looks right thought so no idea what's going on...
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Dosing at Night

Post by rimai »

Ahh... You want between 0 and 3.
The logic is wrong then.
You are checking if hour is greater than midnight or less than 3.
|| -> means or
&& -> means and
So your code has to be:

Code: Select all

if ( ((hour() >= 0) && (hour() <= 3)) && (minute() == 0) && //dose time
Try that and see if it works.
Roberto.
chase
Posts: 101
Joined: Fri Sep 16, 2011 8:26 am

Re: Dosing at Night

Post by chase »

Awesome, sure did. Haven't noticed any 'mystery' dosing in my test containers..thanks again the for the help!
Image
Post Reply