Page 1 of 2
Customizing Delayed start
Posted: Mon Jul 15, 2013 7:55 pm
by ganjero
Can I change what activates the delay start? I use it on my skimmer for feed mode but I don't want to use for water changes or controller reset (it's turns of my skimmer every time i tried a new code)
Thanks
Re: Customizing Delayed start
Posted: Tue Jul 16, 2013 4:31 pm
by ganjero
any ideas here?
Re: Customizing Delayed start
Posted: Tue Jul 16, 2013 4:34 pm
by lnevo
What do you want it based on? It can be based on anything we can test or compare
Re: Customizing Delayed start
Posted: Tue Jul 16, 2013 4:57 pm
by ganjero
The main thing I want to get rid off is that it gets trigger anytime a new code is uploaded, if this cannot be change can i program the skimmer for a delay start with a different code?
Thanks
Re: Customizing Delayed start
Posted: Tue Jul 16, 2013 5:13 pm
by lnevo
Yeah that is doable. I think I'd like it too. Give me some time and I'll have something.
Re: Customizing Delayed start
Posted: Tue Jul 16, 2013 6:24 pm
by ganjero
Great, thanks
Re: Customizing Delayed start
Posted: Thu Jul 18, 2013 5:46 pm
by ganjero
lnevo wrote:Yeah that is doable. I think I'd like it too. Give me some time and I'll have something.
Did you have time to come up with something?
Thanks
Re: Customizing Delayed start
Posted: Thu Jul 18, 2013 6:19 pm
by lnevo
Not yet..I'll try tomorrow on the train. I left my kindle at work

Re: Customizing Delayed start
Posted: Fri Jul 19, 2013 5:44 am
by lnevo
Ok this was much easier than I thought. There is a variable called RAStart that is defined when the controller boots up and initially LastStart s assigned the same variable. After mode changes LastStart is updated...but not RAStart. So, if RAStart==LastStart we just booted. The problem I had as how to differentiate between a reboot and an extended outage. Well for me if my HighATO is active that means my sump water level is normal so I added a check for that. You may need to change that based on your setup or take that part out completely.
Code: Select all
if (RAStart==LastStart && ReefAngel.HighATO.IsActive()) {
ReefAngel.Relay.On(Port2);
} else {
ReefAngel.Relay.DelayedOn(Port2);
}
So what this does is at initial boot, the port is an "always on" port. Once a feeding or waterchange mode change is exited it becomes a DelayedOn port. I have not tested it yet, but it should do the trick.
Re: Customizing Delayed start
Posted: Fri Jul 19, 2013 6:07 am
by ganjero
Thanks a lot.
I guess I will try this:
Code: Select all
if (RAStart==LastStart ) {
ReefAngel.Relay.On(Port7);
} else {
ReefAngel.Relay.DelayedOn(Port7);
}
I am not using the water sensors yet so as you said I eliminated the HighATO part, and my skimmer is on port 7 so I changed that too. Does this seem correct? I will try it tonight and give you feedback.
Thanks again.
Re: Customizing Delayed start
Posted: Fri Jul 19, 2013 7:52 am
by lnevo
Yes, that should work fine. Like I said, I haven't had a chance to test yet, so you'll save me some time if you get to try it tonight
Just keep in mind if you have any delayed power outage or downtime on your controller when it comes back up your skimmer *may* overflow if the return pump hasn't caught up.
Re: Customizing Delayed start
Posted: Sat Jul 20, 2013 9:34 am
by lnevo
It did not work for me. For some reason RAStart is getting assigned 0, but somehow LastStart which gets assigned = to RAStart has a value. No big deal... this is what i did to fix in the meantime.
Code: Select all
static unsigned long startTime=now();
if (startTime==LastStart && ReefAngel.HighATO.IsActive()) {
ReefAngel.Relay.On(relay);
} else {
ReefAngel.Relay.DelayedOn(relay);
}
It worked really nice especially with the float switch in there. if I reload code, skimmer does not stop. If I unplug RA and the water level is too high, as soon as float switch drops skimmer kicks back in. Awesome.
Re: Customizing Delayed start
Posted: Sat Jul 20, 2013 2:18 pm
by ganjero
Worked for me, thanks a lot. I guess I will have to install the float sensors to differentiate booting from power outage.
Thanks again
Re: Customizing Delayed start
Posted: Sun Jul 21, 2013 10:24 am
by ganjero
I noticed that after using this the time and date get messed up, did this happen to you?
Re: Customizing Delayed start
Posted: Sun Jul 21, 2013 10:59 am
by lnevo
No
Re: Customizing Delayed start
Posted: Fri Jul 26, 2013 6:38 pm
by ganjero
If I have this line will my port7 be delayed 60 sec or an hour?
Code: Select all
ReefAngel.Relay.DelayedOn( Port7,60 );
Thanks
Re: Customizing Delayed start
Posted: Fri Jul 26, 2013 7:09 pm
by lnevo
An hour. If you leave out the 60 you can set the time in the portal.
Re: Customizing Delayed start
Posted: Fri Jul 26, 2013 9:45 pm
by ganjero
why some things have to be set in seconds? and how do I know that ie,
Code: Select all
static time_t StartFeeding=0;
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
StartFeeding=now(); // if we entered feeding mode, register what time it was.
if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
ReefAngel.PWM.SetActinic(100);
else
ReefAngel.PWM.SetActinic(45);
Re: Customizing Delayed start
Posted: Fri Jul 26, 2013 10:05 pm
by rimai
You don't need to... It's just easier to

The code above can be coded in minutes, hours or whatevern you want.
It was a preference choice of the programmer that made the code to go with seconds.
If it were me, I would have coded it in seconds too, just because it is easier to understand.
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 6:23 am
by ganjero
So I could do tthis to delay port 7 for half hour? I guess what im trying to know is how to figure out how to tell the controller whether Im using minutes or seconds
Code: Select all
ReefAngel.Relay.DelayedOn( Port7,1800 );
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 7:23 am
by lnevo
What decides is how the function is written. DelayedOn uses minutes. So just use 30.
Aside from convenience and preference as Roberto pointed out, it is also determined by memory usage (byte vs int) and what makes sense. When writing functions now() returns seconds so thats why it's easy. But looking at delayed on it was determined that no one needed to delay in seconds only so minutes were used. This also makes it easy to store the DelayedOn default time in memory because a byte can be used instead of an int (100% savings!!)
To represent 15 minutes in seconds would be 900 and require an int for storage instead of a byte. It may not seem like much but they all add up.
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 9:31 am
by binder
Yep. When I wrote DelayedOn, the delay of seconds didn't seem appropriate because most people wanted a 1 or 2 minute (maybe even 5 minute) delay so their tanks would fill back up before the power heads started working (like in my case).
Plus, like Lee said, it's a storage issue as well as a convenience.
Now, if we were to look at the WavemakerRandom function, it makes more sense to use seconds because you may want it to run every 30 seconds before alternating or 90 seconds or something along those lines. You can't code in 1.5 for a a minute and a half, so you would be better suited for 90 seconds.
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 1:13 pm
by ganjero
Make sense, so the delayon function is in the libraries based in minutes. Thanks
Why is my skimmer coming back on after 15min instead of an hour in my code?
Code: Select all
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port7Bit | Port8Bit;
ReefAngel.FeedingModePortsE[0] = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port7Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port3Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port4Bit;
ReefAngel.LightsOnPortsE[0] = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port5Bit;
ReefAngel.OverheatShutoffPortsE[0] = 0;
// Use T2 probe as temperature and overheat functions
ReefAngel.TempProbe = T2_PROBE;
ReefAngel.OverheatProbe = T2_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 851 );
//Feeedin mode length
ReefAngel.Timer[FEEDING_TIMER].SetInterval(300);
// Feeeding and Water Change mode speed
// Ports that are always on
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port1);
ReefAngel.Relay.On( Box1_Port2 );
ReefAngel.Relay.On( Box1_Port3 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port7 );
ReefAngel.Relay.On( Box1_Port8 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardLights( Port1,14,0,19,0 );
ReefAngel.StandardLights( Port2,15,0,20,0 );
ReefAngel.StandardLights( Port3,19,55,22,0 );
ReefAngel.StandardLights( Port4,14,0,20,15 );
ReefAngel.StandardHeater( Port5,780,785 );
ReefAngel.StandardFan( Port6,780,800 );
ReefAngel.Relay.DelayedOn( Port7,60 );
ReefAngel.StandardLights( Box1_Port5,22,0,16,0 );
ReefAngel.DCPump.UseMemory = true;
////// Place your custom code below here
////disable ReefAngel.PWM.SetDaylight( ElseMode(70,30,true )); // ElseMode on sync mode, 70 +/- 30%
ReefAngel.PWM.SetDaylight( ReefCrestMode(70,30,true) ); // ReefCrest at 70% +/- 30% on sync mode
//// Jebao sump pump runs at 45% unless feeding, then a 30min runs at 100% 1hr.
static time_t StartFeeding=0;
if (ReefAngel.DisplayedMenu==FEEDING_MODE)
StartFeeding=now(); // if we entered feeding mode, register what time it was.
if (now()-StartFeeding > 1800 && now()-StartFeeding < 5400) // if feeding started between 1800 and 5400 seconds
ReefAngel.PWM.SetActinic(100);
else
ReefAngel.PWM.SetActinic(45);
///// Delay Start Turn off on Booting - Start
static unsigned long startTime=now();
if (startTime==LastStart) {
ReefAngel.Relay.On(Port7);
} else {
ReefAngel.Relay.DelayedOn(Port7);
}
///// Delay Start Turn off on Booting - End
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "ganjero" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 62, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 62, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
pingSerial();
// Relay Expansion
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox( 12, 107, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
ReefAngel.LCD.DrawGraph( 5, 5 );
}
//// Jebao Else Mode - Start
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
// Static's only initialize the first time they are called
static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
static int Delay = random( 500, 3000); // Set the initial delay
static int NewSpeed = MidPoint; // Set the initial speed
static int AntiSpeed = MidPoint; // Set the initial anti sync speed
if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
{
Delay=random(500,5000); // If so, come up with a new delay
int ChangeUp = random(Offset); // Amount to go up or down
if (random(100)<50) // 50/50 chance of speed going up or going down
{
NewSpeed = MidPoint - ChangeUp;
AntiSpeed = MidPoint + ChangeUp;
}
else
{
NewSpeed = MidPoint + ChangeUp;
AntiSpeed = MidPoint - ChangeUp;
}
LastChange=millis(); // Reset the time of the last change
}
if (WaveSync)
{
return NewSpeed;
}
else
{
return AntiSpeed;
}
}
//// Jebao Else Mode - End
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 2:19 pm
by lnevo
Looks good. As I said RAStart didn't work for me for some reason... may revisit it later...
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 6:01 pm
by rimai
You have 2 Port7 referenced in two places.
Code: Select all
ReefAngel.Relay.DelayedOn( Port7,60 );
And
Code: Select all
if (startTime==LastStart) {
ReefAngel.Relay.On(Port7);
} else {
ReefAngel.Relay.DelayedOn(Port7);
}
The second one will always override the 1st one.
Re: Customizing Delayed start
Posted: Sat Jul 27, 2013 7:13 pm
by lnevo
The last one is using InternalMemory to set the delay. Check on the portal your default delay may be 15 minutes...
Re: Customizing Delayed start
Posted: Mon Jul 29, 2013 8:38 am
by ganjero
That's it! learning more everyday

so should I delete the first reference and just adjust the delay in portal so I can keep the code that prevents triggering the delay on reboots?
Can I also fix this by deleting the first reference and just adding the time on the second reference? like this:
Code: Select all
if (startTime==LastStart) {
ReefAngel.Relay.On(Port7);
} else {
ReefAngel.Relay.DelayedOn(Port7,60);
}
Thank you
Re: Customizing Delayed start
Posted: Mon Jul 29, 2013 8:40 am
by rimai
Yes, you got it

Re: Customizing Delayed start
Posted: Mon Jul 29, 2013 9:37 am
by lnevo
If you just take out the ,60 you will have best of both worlds. Set the delay time in the portal and have it not delay on reboots.
Re: Customizing Delayed start
Posted: Mon Jul 29, 2013 10:54 am
by ganjero
You mean delete
Code: Select all
ReefAngel.Relay.DelayedOn( Port7,60);
and leave this one like this:
Code: Select all
if (startTime==LastStart) {
ReefAngel.Relay.On(Port7);
} else {
ReefAngel.Relay.DelayedOn(Port7);
}
Thanks