Page 4 of 5

Re: Dosing Pump not running on Schedule

Posted: Mon Jun 17, 2013 10:13 am
by kirkwood
lnevo wrote:I know what is wrong!!!!!

I mixed up the usage of the Port7Bit.

The arg to bitRead should be the position from [0-7] so for Port7 use 6 instead of Port7Bit!
So you are saying I should change "Port7Bit" to "Port6Bit" throughout the code?

Another question - what is the lag between one of the pumps running and the time registering in the custom fields?

Also would the custom fields reset if my power went out? I had a brief power outage early this morning and my ATO fields reset and my ALK and CAL fields both are behind schedule. The power outage was only for a minute so I know i didn't miss any doses. It occurred at about 530am and i think all the fields reset at that point.

Re: Dosing Pump not running on Schedule

Posted: Mon Jun 17, 2013 10:18 am
by lnevo
No, change Port7Bit to "6"

I was using it incorrectly. If power goes out you lose your timer. But the portal would still remember if you look at the graphs, you would have to add the amount before and after power outage. Put your controller on a UPS :) If you have a 2nd relay bar you could even alert when you lose one and take action on the controller (shutdown lights or something).

It takes 5 minutes to refresh the portal. so that would be longest delay.

Re: Dosing Pump not running on Schedule

Posted: Mon Jun 17, 2013 7:58 pm
by kirkwood
Good news, the ATO reset is working!

Im starting to see why you initially coded it as a maskOff function because the logic would be that you would encounter an empty ATO reservoir with the ATO pump running and then you would turn the mask off, refill the reservoir, and the ATO custom field counter would be reset to zero.

Re: Dosing Pump not running on Schedule

Posted: Mon Jun 17, 2013 8:00 pm
by lnevo
Exactly. But with it running or not, you would override it off until your neighbor came to refill it. Then you'd release the override and it would reset the counter,

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 18, 2013 10:29 am
by kirkwood
Here is the custom graph for the minutes counter on my Calcium dpump. I am dosing 68 minutes per day and the data looks great. I had a couple power outages last week and uploaded new code a few times so the counter did reset itself a few times, but so far so good. The webcharting for the seconds counters doesn't really produce good data because it doesn't compile fast enough to show the seconds counting up to 60 and resetting back to 0 repeatedly. But the minutes is all that really matters to me anyway.

http://forum.reefangel.com/status/chart ... &filter=c2

So I am wondering if the seconds custom fields are required in any way to track the number of minutes? Basically is the data for fields 0,2 and 1,3 generated independently? I was thinking that instead of having seconds in fields 1 and 3 I would rather have it report the # of minutes from fields 0, 2 at 11:30pm every day. Because at 11:30pm the dpumps would have run already for their entire alotted dosage, then the next day when I went to the portal I would be able to see what the previous days total dosage was without having to go pull up the custom webcharting. Additionally, I assume it would be easy to populate those numbers on my RA display to show what the total ALK and CAL dosage was from the previous day. Then if the number is ever off I would know to run a diagnostic check to see if maybe the power went out the night before or if insufficient dosage was made and then I would know to supplement the next days dose.

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 18, 2013 11:14 am
by lnevo
Yeah, we could very easily do that. Currently at 11:59pm we clear all 4 timers. We could just make it clear the 0,2 and save the last value into 1 and 3 and not update the seconds anymore. I'll give you some code later today.

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 18, 2013 2:11 pm
by kirkwood
Awesome! Yeah I think that data will be more useful. I can't tell you how much I appreciate all the coding.

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 18, 2013 2:13 pm
by lnevo
No problem. I will eventually be submitting some of the code we worked on to the libraries. This involves a new DosingPump class with calibration ability and dosing by volume.

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 18, 2013 3:13 pm
by lnevo
Ok, try this. It will back up the portal timer in minutes at 11:59 and then reset just the dosing pumps. The reset code is back to mask off, I'd you want to switch back and I hopefully fixed all the compile errors you had. Hope I didn't add any...

Code: Select all


const byte numPumps=3;
byte pump[numPumps] = { Port3, Port4, Port7 };
byte portalMinutes[numPumps] = { 0, 2, 4 };
byte portalSeconds[numPumps] = { 1, 3, 5 };

static time_t pumpTimer[numPumps];
static boolean pumpStatus[numPumps];
static boolean atoDisabled;
  
for (int i=0;i< numPumps;i++) {
  if (ReefAngel.Relay.Status(pump[i])) {
    if (!pumpStatus[i]) {
      pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
      pumpStatus[i]=true;
    }
  } else {
    if (pumpStatus[i]) {
      pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
      pumpStatus[i]=false;

      // Normalize and assign to CustomVar for reporting on the portal
      ReefAngel.CustomVar[portalMinutes[i]]=pumpTimer[i]/60; // Number of Minutes
//      ReefAngel.CustomVar[portalSeconds[i]]=pumpTimer[i]%60; // Number of Seconds
    }
  }
}


if (now()%SECS_PER_DAY==SECS_PER_DAY-1) {
    // Backup timers to portal variable
    ReefAngel.CustomVar[portalSeconds[0]] = pumpTimer[0]/60;
    ReefAngel.CustomVar[portalSeconds[1]] = pumpTimer[1]/60;
    ReefAngel.CustomVar[portalSeconds[2]] = pumpTimer[2]/60;
    pumpTimer[0]=0; // Clear timer for Port3
    pumpTimer[1]=0; // Clear timer for Port4
}

if (bitRead(ReefAngel.Relay.RelayMaskOff, 6)==0) { // ATO relay is manually disabled
  atoDisabled=true;
} 
if (atoDisabled && (bitRead(ReefAngel.Relay.RelayMaskOff, 6)==1)) { // ATO override has been cleared
  pumpTimer[2]=0; // Clear timer for Port7
  atoDisabled=false;
}

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 8:27 am
by kirkwood
I loaded the code in last night. I will let you know what happens tonight when the clock strikes midnight.

I am trying to educate myself on coding as you have been walking me through this whole process. Usually I can make sense of what the code is instructing the RA to do, however I couldn't figure out what part of the code is telling fields 1 and 3 to register the minutes ran from fields 0 and 2 at 11:59pm each day.

Thanks!

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 10:12 am
by lnevo
byte portalSeconds[numPumps] = { 1, 3, 5 };

...

if (now()%SECS_PER_DAY==SECS_PER_DAY-1) {
// Backup timers to portal variable
ReefAngel.CustomVar[portalSeconds[0]] = pumpTimer[0]/60;
ReefAngel.CustomVar[portalSeconds[1]] = pumpTimer[1]/60;
ReefAngel.CustomVar[portalSeconds[2]] = pumpTimer[2]/60;
pumpTimer[0]=0; // Clear timer for Port3
pumpTimer[1]=0; // Clear timer for Port4
}

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 2:09 pm
by kirkwood
Something isn't right. Fields 0 and 2 reset themselves at 2pm this afternoon. Fields 1 and 3 are both displaying 0.

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 3:52 pm
by lnevo
1 and 3 will not show data till after midnight. 12:05 the latest

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 7:00 pm
by kirkwood
Right. I had some data in fields 0 and 1 last night when it should have pulled but still had zeros today. I will wait to see what happens tonight after midnight and update you tomorrow.

Re: Dosing Pump not running on Schedule

Posted: Wed Jun 19, 2013 7:17 pm
by lnevo
Did you copy my whole code i posted above? I commented out the line that updates the seconds fields so it should only get updated at midnight. If you tried to merge its an easy miss...

Make sure the line in the main loop that updates the seconds on the portal is commented...

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 3:58 am
by kirkwood
I will check the code tonight. Fields 1 and 3 didn't pull last night.

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 10:33 am
by kirkwood
kirkwood wrote:I will check the code tonight. Fields 1 and 3 didn't pull last night.
I loaded the code exactly as it was written in your post on 6/18 at 6:13pm. The only change I made was that I kept the ATO reset function as "maskON". So something is preventing the data to pull correctly at 11:59pm.

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 10:38 am
by lnevo
Can you post the whole code again so I can review it as it is. Sorry for the trouble, but I don't see how it's not gettign set...

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 12:18 pm
by kirkwood
will do. i will post full code this evening

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 6:23 pm
by kirkwood
Here is my full code

#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 <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 = Port5Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port6Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );


// Ports that are always on
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port8 );

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
ReefAngel.MHLights( Port1,16,0,23,0,5 );
ReefAngel.MHLights( Port2,17,0,21,30,10 );
ReefAngel.DosingPumpRepeat( Port3,0,120,292 );
ReefAngel.DosingPumpRepeat( Port4,60,120,340 );
ReefAngel.StandardHeater( Port6,775,805 );
ReefAngel.StandardATO( Port7,900 );
////// Place your custom code below here

//Start Feeding Mode at 17:00 and 21:00
if ( (now()%86400==61200) || (now()%86400==75600) ) {
ReefAngel.FeedingModeStart();
}

const byte numPumps=3;
byte pump[numPumps] = { Port3, Port4, Port7 };
byte portalMinutes[numPumps] = { 0, 2, 4 };
byte portalSeconds[numPumps] = { 1, 3, 5 };

static time_t pumpTimer[numPumps];
static boolean pumpStatus[numPumps];
static boolean atoDisabled;

for (int i=0;i< numPumps;i++) {
if (ReefAngel.Relay.Status(pump)) {
if (!pumpStatus) {
pumpTimer=now()-pumpTimer; // Pump was off, timer is now a time
pumpStatus=true;
}
} else {
if (pumpStatus) {
pumpTimer=now()-pumpTimer; // Pump was on, timer is now a timer
pumpStatus=false;

// Normalize and assign to CustomVar for reporting on the portal
ReefAngel.CustomVar[portalMinutes]=pumpTimer[i]/60; // Number of Minutes
// ReefAngel.CustomVar[portalSeconds[i]]=pumpTimer[i]%60; // Number of Seconds
}
}
}


if (now()%SECS_PER_DAY==SECS_PER_DAY-1) {
// Backup timers to portal variable
ReefAngel.CustomVar[portalSeconds[0]] = pumpTimer[0]/60;
ReefAngel.CustomVar[portalSeconds[1]] = pumpTimer[1]/60;
ReefAngel.CustomVar[portalSeconds[2]] = pumpTimer[2]/60;
pumpTimer[0]=0; // Clear timer for Port3
pumpTimer[1]=0; // Clear timer for Port4
}
if (bitRead(ReefAngel.Relay.RelayMaskOn, 6)==1) { // ATO relay was forced on
atoDisabled=true; // don't want to change the variable names yet.. but you may want to to make it clearer..
}
if (atoDisabled && (bitRead(ReefAngel.Relay.RelayMaskOn, 6)==0)) { // ATO override has been cleared
pumpTimer[2]=0; // Clear timer for ATOPort
atoDisabled=false;
}

////// Place your custom code above here

// This should always be the last line
ReefAngel.Portal( "kirkwood" );
ReefAngel.ShowInterface();
}

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 7:14 pm
by lnevo
Nevermind I know what the problem was. We need to make sure that the clearing and backing up only happens once. Right now it's happening a few times for the second before midnight which is not what we want because it's lost after the first run. Anyway, here's a fix.

Code: Select all

static boolean clearTimer;
if (now()%SECS_PER_DAY!=SECS_PER_DAY-1) clearTimer=true;
if ((now()%SECS_PER_DAY==SECS_PER_DAY-1) && clearTimer==true) {
// Backup timers to portal variable
ReefAngel.CustomVar[portalSeconds[0]] = pumpTimer[0]/60;
ReefAngel.CustomVar[portalSeconds[1]] = pumpTimer[1]/60;
ReefAngel.CustomVar[portalSeconds[2]] = pumpTimer[2]/60;
pumpTimer[0]=0; // Clear timer for Port3
pumpTimer[1]=0; // Clear timer for Port4
clearTimer=false;
}

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 7:20 pm
by kirkwood
Got an error on this line of code:

if (now()%SECS_PER_DAY==SECS_PER_DAY-1 && clearTimer=true) {

1value required as left operand of assignment

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 7:29 pm
by lnevo
Sorry put () around the first test :)

if ( (now()%SECS_PER_DAY==SECS_PER_DAY-1) && clearTimer=true) {

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 7:45 pm
by kirkwood
lnevo wrote:Sorry put () around the first test :)

if ( (now()%SECS_PER_DAY==SECS_PER_DAY-1) && clearTimer=true) {
It still gives the same error.

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 8:12 pm
by rimai
It need to be like this:
if ( (now()%SECS_PER_DAY==SECS_PER_DAY-1) && clearTimer==true) {

Re: Dosing Pump not running on Schedule

Posted: Thu Jun 20, 2013 8:15 pm
by lnevo
Thanks :)

Re: Dosing Pump not running on Schedule

Posted: Fri Jun 21, 2013 7:46 pm
by kirkwood
I loaded the new code this afternoon so I will report back tomorrow

Re: Dosing Pump not running on Schedule

Posted: Sat Jun 22, 2013 5:42 pm
by kirkwood
kirkwood wrote:I loaded the new code this afternoon so I will report back tomorrow
Success!

Re: Dosing Pump not running on Schedule

Posted: Sat Jun 22, 2013 5:51 pm
by lnevo
Whew :)

Re: Dosing Pump not running on Schedule

Posted: Tue Jun 25, 2013 6:43 am
by kirkwood
Everything has been working well but this morning I noticed something that didn't make sense. Custom Fields 4 and 5 are my ATO minutes and ATO seconds, respectively. This morning field 4 was 62 and field 5 was 62. That makes me wonder if field 5 is programmed to pull the field 4 value at 11:59pm each night like my ALK and CAL. It doesn't really matter to me either way because the ATO seconds value is of little consequence.

I had a final idea on tracking dosing values - right now we are tracking in field 0&2 the dosing minutes for the day that resets at the end of each day, field 1&3 that updates each night at 11:59pm with the value of fields 0&2. And then maybe we do fields that will keep a running total of minutes that carrys over from day to day so that I can track when my dosing reservoir is close to empty. Basically after field 1 updates with the total dose for the day, another field would add that number to its existing total and that would continue each day until I reset it in the same way I would reset the ATO via the masking function.

So basically in the end I would do Fields 0,3 for daily running tally of minutes, fields 1,4 that pulls field 0,3 value at 11:59pm each day, fields 2,5 that adds the value of field 1,4 to the existing value of field 2,5 each day, and field 6 would be my ATO minutes. Fields 2,5,6 would all need to be able to be reset via the masking functionality we've been using for the ATO.

I don't need this right now, as my code is working nicely right now and i'm about to put it to the test by heading out of town for a bit, so I don't want to load any new code that I will need to tinker with...