I could do like that but it wouldn't be much funlnevo wrote:You can try using an if statements to make sure and at least get your ATO working. It will be sans timeout...
if (ReefAngel.WaterLevel.GetLevel() < X) ReefAngel.Relay.On(ATO_Port);
if (Reefangel.WaterLevel.GetLevel() > Y) ReefAngel.Relay.Off(ATO_Port);
Change X and Y and the ATO Port.
Instant Water Level ATO timeout
Re: Instant Water Level ATO timeout
Re: Instant Water Level ATO timeout
I added some serial print to trace the different variables. The topping seem to work occasionally but most of the time not.
That was the output of a successful timeout. The interesting part is in the following run after clearing the ATO:
Look at the last WLATO.Timer. Recognize the new value? Any ideas how it's set?
WaterLevelATO with the Serial.print that I used:
Code: Select all
WL: 73 WLATO.Timer: 262144 millis(): 282117 diff: 19973 IsTopping: 1 msTimeout: 20000
WL: 73 WLATO.Timer: 262144 millis(): 282140 diff: 19996 IsTopping: 1 msTimeout: 20000
WL: 73 WLATO.Timer: 262144 millis(): 282147 diff: 20003 IsTopping: 1 msTimeout: 20000
(millis() - WLATO.Timer) > msTimeout && WLATO.IsTopping() <-- This indicates the timeout
Code: Select all
WL: 74 WLATO.Timer: 316609 millis(): 316609 diff: 0 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316632 diff: 23 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316639 diff: 30 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316653 diff: 44 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316667 diff: 58 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316682 diff: 73 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316696 diff: 87 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316710 diff: 101 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316733 diff: 124 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316740 diff: 131 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316754 diff: 145 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 316609 millis(): 316769 diff: 160 IsTopping: 1 msTimeout: 20000
WL: 74 WLATO.Timer: 262144 millis(): 316883 diff: 54739 IsTopping: 1 msTimeout: 20000
(millis() - WLATO.Timer) > msTimeout && WLATO.IsTopping() <-- This indicates the timeout
WaterLevelATO with the Serial.print that I used:
Code: Select all
void ReefAngelClass::WaterLevelATO(byte Channel, byte ATORelay, int ATOTimeout, byte LowLevel, byte HighLevel)
{
// Input: Relay port and timeout value (max number of seconds that ATO pump is allowed to run)
// Input: Low and High Water Level to start and stop ATO pump
unsigned long msTimeout = ATOTimeout * 1000;
byte waterlevel = WaterLevel.GetLevel(Channel);
/*
Is the low level is reached (meaning we need to top off) and are we not currently topping off
Then we set the timer to be now and start the topping pump
*/
if (waterlevel < LowLevel && (!WLATO.IsTopping()))
{
Serial.println("waterlevel < LowLevel && (!WLATO.IsTopping())");
WLATO.Timer = millis();
WLATO.StartTopping();
Relay.On(ATORelay);
}
// If the high level is reached, this is a safeguard to prevent over running of the top off pump
if (waterlevel >= HighLevel)
{
WLATO.StopTopping(); // stop the low ato timer
Relay.Off(ATORelay);
}
unsigned long milli = millis();
Serial.print("WL: ");
Serial.print(waterlevel);
Serial.print(" WLATO.Timer: ");
Serial.print(WLATO.Timer);
Serial.print(" millis(): ");
Serial.print(milli);
Serial.print(" diff: ");
Serial.print(milli - WLATO.Timer);
Serial.print(" IsTopping: ");
Serial.print(WLATO.IsTopping());
Serial.print(" msTimeout: ");
Serial.print(msTimeout);
Serial.println();
/*
If the current time minus the start time of the ATO pump is greater than the specified timeout value
AND the ATO pump is currently running:
We turn on the status LED and shut off the ATO pump
This prevents the ATO pump from continuously running.
*/
if ((millis() - WLATO.Timer) > msTimeout && WLATO.IsTopping())
{
Serial.println("(millis() - WLATO.Timer) > msTimeout && WLATO.IsTopping()");
Relay.Off(ATORelay);
LED.On();
bitSet(AlertFlags, ATOTimeOutFlag);
#ifdef ENABLE_EXCEED_FLAGS
if (InternalMemory.read(ATO_Exceed_Flag)==0)
InternalMemory.write(ATO_Exceed_Flag, 1);
#endif // ENABLE_EXCEED_FLAGS
#ifdef ENABLE_ATO_LOGGING
// bump the counter if a timeout occurs
AtoEventCount++;
if ( AtoEventCount >= MAX_ATO_LOG_EVENTS ) { AtoEventCount = 0; }
#endif // ENABLE_ATO_LOGGING
}
}