Can you adding debugging commands and customize SMS alerts?

Do you have a question on how to do something.
Ask in here.
Post Reply
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Can you adding debugging commands and customize SMS alerts?

Post by mudcat1 »

I have a few questions that I hope someone can help me with. I am attempting to get 3 dosing pumps working and I am using code that I have found in various posts from the forum. I cannot determine if the pumps are running as expected because I am not at home to observe them. I have been checking the Relay status section of the web portal but I don't see any activity for the pumps during the times they should be running. I do however see activity for other devices (ex. power head, heater, ATO and lights). So I would like to insert some debugging commands to send SMS messages or email messages so I can determine if my "if" statements are working as expected. Or is there a debugger that I can use to set breakpoints to test the code?

Here is the Sketch that I am currently using...

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

    // Ports that are always on
    ReefAngel.Relay.On( Port5 ); // Hydor powerhead 
}

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

// Setup SMS alerts
 void WifiSendAlert(byte id, boolean IsAlert)
{
  static byte alert_status;

  if (IsAlert)
  {
    if ((alert_status & 1<<(id-1))==0)
    {
      alert_status|=1<<(id-1);
      Serial.print("GET /status/alert.asp?e=3141234567@vtext.com&id=");
      Serial.println(alert_status,DEC);
      Serial.println("\n\n");
    }
  }
  else
  {
    if (id==0)
    {
      alert_status=0;
      delay(900);
    }
    else
    {
      alert_status&=~(1<<(id-1)); 
    }
  }
}

// Tunze short pulse functions
     byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
  byte tspeed=0;
  PulseMinSpeed=constrain(PulseMinSpeed,0,100);
  PulseMaxSpeed=constrain(PulseMaxSpeed,0,100);
  tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
  if (PulseSync)
    return tspeed;
  else
    return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}

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

void loop()
{
        
//*** Dosing Pumps *** added 12-27-12
//    ReefAngel.DosingPumpRepeat( Port2,0,60,240 );
//    ReefAngel.DosingPumpRepeat( Port3,0,60,240 );
//    ReefAngel.DosingPumpRepeat( Port4,0,60,240 );

//*** Heater *** added 12-27-12
    ReefAngel.StandardHeater( Port7,755,765 );

//*** Refugium Light *** added 12-27-12
    ReefAngel.StandardLights( Port8,20,0,8,0 );
    
////// Place your custom code below here

/* List device attached to each port on the Relay Box.
   Port 1 - ATO
   Port 2 - Dosing Pump KH
   Port 3 - Dosing Pump CA
   Port 4 - Dosing Pump MG
   Port 5 - Hydor Koralia (future) Tunze 6105 Powerhead
   Port 6 - Unused (future) Tunze 6105 Powerhead
   Port 7 - Heater
   Port 8 - Sump LED Light
*/
// Night mode for Tunze powerheads starts at 10:00 pm and stops at 8:00 am. 
    if ( (hour() >=22) || (hour() <=8) ){
      ReefAngel.PWM.SetActinic( TunzeShortPulse(30,30,10,true) );
      ReefAngel.PWM.SetDaylight( TunzeShortPulse(30,50,5,false) ); }
    else {
    // Day mode for Tunze powerheads
      ReefAngel.PWM.SetActinic( TunzeShortPulse(30,50,2,true) ); 
      ReefAngel.PWM.SetDaylight( TunzeShortPulse(30,90,2,false) ); }

// THIS SECTION OF CODE IS NOT WORKING AS EXPECTED

// Dose Alk one time per hour for 1 minute between 8:00 pm and 5:00 am. 
if ( hour() >=20 || hour() <5) {
  ReefAngel.DosingPumpRepeat( Port2,0,60,60 ); }
else {
  ReefAngel.Relay.Off( Port2 ); }  

// Dose CA and MG one time per hour for 1 minute between 9:00 am and 6:00 pm.
if ( hour() >=9 && hour() <18) {
  ReefAngel.DosingPumpRepeat( Port3,0,60,60 );
  ReefAngel.DosingPumpRepeat( Port4,0,60,60 ); }
else {
  ReefAngel.Relay.Off( Port3 );
  ReefAngel.Relay.Off( Port4 ); }

// END OF SECTION THAT IS NOT WORKING CORRECTLY

/* List of the possible alert codes.
   WifiSendAlert(0)="Nothing"
   WifiSendAlert(1)="Auto top-off timeout"
   WifiSendAlert(2)="Water temperature too high"
   WifiSendAlert(3)="Water temperature too low"
   WifiSendAlert(4)="Lights temperature too high"
   WifiSendAlert(5)="PH too high"
   WifiSendAlert(6)="PH too low Alert"

   Let's say you would like to receive a high water temperature alert.
   The line you have to add is:
   if (ReefAngel.Params.Temp1>820) WifiSendAlert(2);
*/
// Send SMS text message alert if temp2 is less than 74.5 degrees.    
if (ReefAngel.Params.Temp[2]<74.5 && ReefAngel.Params.Temp[2]>0) WifiSendAlert(3,true); 
// Send SMS text message alert if temp3 is greater than 82 degrees.
if (ReefAngel.Params.Temp[2]>820 && ReefAngel.Params.Temp[2]<1850) WifiSendAlert(2,false);

//// Send SMS text message alert if temp1 is less than 74.5 degrees.    
//if (ReefAngel.Params.Temp[1]<74.5 && ReefAngel.Params.Temp[1]>0) WifiSendAlert(3,true); 
// Send SMS text message alert if temp is greater than 82 degrees.
//if (ReefAngel.Params.Temp[1]>820 && ReefAngel.Params.Temp[1]<1850) WifiSendAlert(2,false);

//*** ATO *** added 12-29-12
// Shutoff ATO if ATO reservoir is empty or if the sump is going to overflow.        
    if (!ReefAngel.LowATO.IsActive() || !ReefAngel.HighATO.IsActive()){
      ReefAngel.Relay.Off (Port1);
      WifiSendAlert(1,true);} // Send SMS text message alert "Auto top-off timeout".
    else {
        ReefAngel.Relay.On (Port1);}

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

// This should always be the last line
//    ReefAngel.AddWifi();
    ReefAngel.Portal( "mudcat1" );
    ReefAngel.ShowInterface();
}
Also is there anyway to send custom SMS alerts beyond the ones listed below?
/* List of the possible alert codes.
WifiSendAlert(0)="Nothing"
WifiSendAlert(1)="Auto top-off timeout"
WifiSendAlert(2)="Water temperature too high"
WifiSendAlert(3)="Water temperature too low"
WifiSendAlert(4)="Lights temperature too high"
WifiSendAlert(5)="PH too high"
WifiSendAlert(6)="PH too low Alert"

Thank you in advance for your assistance.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Can you adding debugging commands and customize SMS aler

Post by rimai »

I'd use this for your functions:

Code: Select all

ReefAngel.DosingPumpRepeat( Port2,0,60,60 ); }
And this:

Code: Select all

  ReefAngel.DosingPumpRepeat( Port3,5,60,60 );
  ReefAngel.DosingPumpRepeat( Port4,10,60,60 ); }
This way, you don't dose two chemicals at once.
The last setting is for offset.
So, on the top of the hour, you dose port2. At 5 minutes past the hour, you does port3 and last at 10 minutes past the hour, you dose port4.
You will not see activity for those ports because they may start and end before the controller sends any info to the server. It's 5 minutes intervals.
I think this would send the alert:

Code: Select all

WifiSendAlert (2,ReefAngel.Relay.Status(Port2));
WifiSendAlert (3,ReefAngel.Relay.Status(Port3));
WifiSendAlert (4,ReefAngel.Relay.Status(Port4));
You will get the alert 2,3 and 4 but you will know what it is.
If I remember correctly, those are preset.
Roberto.
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: Can you adding debugging commands and customize SMS aler

Post by mudcat1 »

Roberto,
Thanks for the input. I am attempting to dose at different times to prevent a pH swing. I am using the following code but for some reason it is not running, but I don't understand why. I could run a offset when I dose CA and MG, but at this time the existing code does not run.

// THIS SECTION OF CODE IS NOT WORKING AS EXPECTED

// Dose Alk one time per hour for 1 minute between 8:00 pm and 5:00 am.
if ( hour() >=20 || hour() <5) {
ReefAngel.DosingPumpRepeat( Port2,0,60,60 ); }
else {
ReefAngel.Relay.Off( Port2 ); }

// Dose CA and MG one time per hour for 1 minute between 9:00 am and 6:00 pm.
if ( hour() >=9 && hour() <18) {
ReefAngel.DosingPumpRepeat( Port3,0,60,60 );
ReefAngel.DosingPumpRepeat( Port4,0,60,60 ); }
else {
ReefAngel.Relay.Off( Port3 );
ReefAngel.Relay.Off( Port4 ); }

Do you see a problem with it?
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: Can you adding debugging commands and customize SMS aler

Post by mudcat1 »

Here is a screenshot of the current Relay Activity in the web portal...
Relay Activity.jpg
You do not have the required permissions to view the files attached to this post.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Can you adding debugging commands and customize SMS aler

Post by rimai »

That's what I said...
The controller only sends data every 5 minutes.
Your pumps turn on and off in less than 5 minutes, so there is no way to capture the relay turning on.
Roberto.
mudcat1
Posts: 133
Joined: Sun Dec 09, 2012 7:23 pm

Re: Can you adding debugging commands and customize SMS aler

Post by mudcat1 »

Roberto I misunderstood what you meant. I understand now. I was able to observe the pump a few minutes ago and it is running correctly. Thanks for the clarification.
Post Reply