Page 1 of 1
ATO Code verification
Posted: Wed May 14, 2014 4:44 pm
by Smotz
'Lo all,
Had a bit of an issue today. For some reason, the 2nd channel of my water level sensor became un-calibrated and was reading 200 (as if it was never setup). I came home from work and noticed that my entire reservoir dumped in to my tank (about 3 gallons). IT wasn't a catastrophe, but definitely concerning.
Channel (1) is my sump and (2) is my reservoir.
Can someone review this code and advise if they see any flaws?
(I just added the && ReefAngel.WaterLevel.GetLevel(2) < 150 as a safeguard to ensure that it recognized that it was calibrated properly.
Code: Select all
// Main Top Off
if ( ReefAngel.WaterLevel.GetLevel(2) >= 15 && ReefAngel.WaterLevel.GetLevel(2) < 150 && ReefAngel.Params.PH < 850 && millis() > 1000) // Ensure there is 15% of water in the Top Off reservoir and PH is less than 8.5 and the RA didn't just reboot
{
if ( ReefAngel.WaterLevel.GetLevel(1) <= 80 ) ReefAngel.Relay.On(Topoff);
if ( ReefAngel.WaterLevel.GetLevel(1) >= 100 ) ReefAngel.Relay.Off(Topoff);
}
// End Main Top Off
Re: ATO Code verification
Posted: Wed May 14, 2014 6:54 pm
by lnevo
I guess the WaterLevelATO function can't take a channel number yet? That would give you the ato timeout functionality that would protect against that situation..
What I would do is add a time condition to the if so that it reads if the waterlevel is < 80 && now()%3600<60
That way if the water level is low it will only be on for the first 60 seconds of every hour.. You could change the values to whatever works right for you.
I would then add a portal alarm if any of the water level channels go out of whack
Re: ATO Code verification
Posted: Thu May 15, 2014 5:33 am
by Smotz
I will give that a try. Thanks again.
Re: ATO Code verification
Posted: Thu May 15, 2014 5:39 am
by Smotz
lnevo wrote:I guess the WaterLevelATO function can't take a channel number yet? That would give you the ato timeout functionality that would protect against that situation..
What I would do is add a time condition to the if so that it reads if the waterlevel is < 80 && now()%3600<60
That way if the water level is low it will only be on for the first 60 seconds of every hour.. You could change the values to whatever works right for you.
I would then add a portal alarm if any of the water level channels go out of whack
wondering if there would be a more elegant way of doing this?
I don't know how to do it but is there a way for me to set a timer for how long the ATO is on and stop it at 30 seconds?
Re: ATO Code verification
Posted: Thu May 15, 2014 5:51 am
by lnevo
Thats the now()%3600<60
The 60 is the runtime and the 3600 is the repeat interval. You can change those to values to fit your needs.
The more elegant way is probably in the dev libraries where you can just say WaterLevelATO(channel, %start, %end, timeout);
Roberto can confirm that part
Re: ATO Code verification
Posted: Thu May 15, 2014 8:26 am
by rimai
brunnels has patched our libraries to gives us that option:
https://github.com/reefangel/Libraries/issues/138
If you grab the latest dev branch, you will be able to use it.
Re: ATO Code verification
Posted: Thu May 15, 2014 8:31 am
by Smotz
lnevo wrote:Thats the now()%3600<60
The 60 is the runtime and the 3600 is the repeat interval. You can change those to values to fit your needs.
The more elegant way is probably in the dev libraries where you can just say WaterLevelATO(channel, %start, %end, timeout);
Roberto can confirm that part
Gotcha. Thank you all.
Re: ATO Code verification
Posted: Sun Jun 01, 2014 8:11 am
by Smotz
lnevo wrote:Thats the now()%3600<60
The 60 is the runtime and the 3600 is the repeat interval. You can change those to values to fit your needs.
The more elegant way is probably in the dev libraries where you can just say WaterLevelATO(channel, %start, %end, timeout);
Roberto can confirm that part
I installed the Devs - to confirm:
Instead of:
Code: Select all
if ( ReefAngel.WaterLevel.GetLevel(1) <= 80 && ReefAngel.DisplayedMenu!=WATERCHANGE_MODE && millis() > 2000 && now()%3600<15) ReefAngel.Relay.On(Topoff);
if ( ReefAngel.WaterLevel.GetLevel(1) >= 100 ) ReefAngel.Relay.Off(Topoff);
I would simply use this? I don't see how it knows to use the pump...?
Code: Select all
ReefAngel.WaterLevelATO(1,80,100,15);
1 being the channel of the multi water level, 80 = start, 100 = stop, run for 15 seconds - max)
do I have to do something like this?
Code: Select all
if (ReefAngel.WaterLevel.GetLevel(1) < 80) ReefAngel.WaterLevelATO(Topoff,80,100,15);
Re: ATO Code verification
Posted: Mon Jun 02, 2014 4:05 am
by Smotz
No thoughts?
Sent from my SCH-I605 using Tapatalk
Re: ATO Code verification
Posted: Mon Jun 02, 2014 4:08 am
by lnevo
Yes but i didn't get to look at the code to verify. Roberto can hopefully confirm. There needs to be an arg for the port.
Re: ATO Code verification
Posted: Mon Jun 02, 2014 4:40 am
by Smotz
Thanks..sorry. Didn't mean to be impatient.
Re: ATO Code verification
Posted: Mon Jun 02, 2014 7:43 am
by rimai
Never used nor tested yet either, yet.
brunnels is the one that created that.
Your function is slightly wrong though.
The function is declared as this:
void ReefAngelClass::WaterLevelATO(byte Channel, byte ATORelay, int ATOTimeout, byte LowLevel, byte HighLevel)
Re: ATO Code verification
Posted: Mon Jun 02, 2014 8:13 am
by Smotz
yea, not sure it's ready for prime time
I used this (as you specified)
Code: Select all
ReefAngel.WaterLevelATO(1,Topoff,15,80,100);
and got this on the compile -
Display_Tank_test.cpp: In function 'void loop()':
Display_Tank_test:129: error: no matching function for call to 'ReefAngelClass::WaterLevelATO(int, int, int, int, int)'
C:\Users\Joe\Documents\Arduino\libraries\ReefAngel/ReefAngel.h:331: note: candidates are: void ReefAngelClass::WaterLevelATO(byte, int, byte, byte)
C:\Users\Joe\Documents\Arduino\libraries\ReefAngel/ReefAngel.h:368: note: void ReefAngelClass::WaterLevelATO(byte)
Re: ATO Code verification
Posted: Mon Jun 02, 2014 8:53 am
by rimai
Ahh..
You also need this on setup():
Code: Select all
ReefAngel.AddMultiChannelWaterLevelExpansion();
And you also need the newest feature.txt file from our github:
https://github.com/reefangel/FeaturesAndUpdateFiles
Re: ATO Code verification
Posted: Mon Jun 02, 2014 10:19 am
by Smotz
Thanks, Roberto - that compiled.
Where do you think I should place :
Code: Select all
ReefAngel.WaterLevelATO(1,Topoff,15,80,100);
Re: ATO Code verification
Posted: Mon Jun 02, 2014 10:33 am
by rimai
Place anywhere in the loop() section.
Re: ATO Code verification
Posted: Mon Jun 02, 2014 11:30 am
by lnevo
Before any other checks that you may use to disable that port
I.e. if you have something like
if (ReefAngel.GetWaterLevel(1) < 10) ReefAngel.Relay.Off(Topoff);
then put it before. If you have no other checks that would disable/enable the Topoff port then it can go anywhere.
Re: ATO Code verification
Posted: Mon Jun 02, 2014 6:12 pm
by Smotz
looks good. thanks again, guys.
Tested and working so far!