Mike's RSM 500 Code

Share you PDE file with our community
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

You must also remove the Ecotech RF module before you can upload or it will thing the serial data is supposed to be sent to the vortech drivers.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

It's been awhile since I have needed to update code, but the power outage function wasn't working.

Not sure why but the power outage was below "// This should always be the last line" When I moved it up I couldn't compile. What did I do wrong here?

Thanks!

Getting the following compile error at: void CheckPower() {

Code: Select all

updated_code.cpp: In function 'void loop()':
updated_code:165: error: a function-definition is not allowed here before '{' token
updated_code:257: error: expected `}' at end of input

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>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x,y;
char text[10];

////// Place global variable code above here

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    
    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5
    
    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off(Unused);

    ////// Place additional initialization code below here
    
    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval(5);
    
    ////// Place additional initialization code above here
}
////// Setup End

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer,2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump,770,773 );
    ReefAngel.StandardHeater( HeaterDisp,767,770 );
    ReefAngel.StandardFan( Fan,810,814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5,9,0,20,0 );
        if (hour()==14 && minute()>=0 && minute()<=59) ReefAngel.Relay.Off(CenterT5);
    ReefAngel.StandardLights( FrontT5,10,0,18,0 );
	if (hour()==15 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    ReefAngel.StandardLights( BackT5,11,0,19,0 );
        if (hour()==16 && minute()>=0 && minute()<=29) ReefAngel.Relay.Off(BackT5);

////// Place your custom code below here
    
    // RSM MoonLED Schedule
    if (hour()>=6 && hour()<=8) ReefAngel.StandardLights( MoonLED,6,0,8,59 ); //Morning
    else if(hour()>=20 && hour()<=23) ReefAngel.StandardLights( MoonLED,20,0,23,45 ); //Evening
    else if(hour()>=23 || hour()<=4) if (MoonPhase()>=90) ReefAngel.StandardLights( MoonLED,23,46,4,0 ); //Full Moon
    
    // Moonphase LED Schedule
    if (hour()>=20 || hour()<4)
    {
      ReefAngel.PWM.SetActinic(MoonPhase());
      ReefAngel.PWM.SetDaylight(MoonPhase());
    }
    else
    {
      ReefAngel.PWM.SetActinic(0);
      ReefAngel.PWM.SetDaylight(0);
    }
    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5); 
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    
    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if (ReefAngel.DisplayedMenu!=FEEDING_MODE || ReefAngel.DisplayedMenu!=WATERCHANGE_MODE)
    {
      if (hour()>=16 && hour()<=19)
      {
        ReefAngel.RF.UseMemory=false;
        ReefAngel.RF.SetMode(LongWave,50,30);
      }
        else if (hour()>=20 || hour()<7)
        {
          ReefAngel.RF.UseMemory=false;
          ReefAngel.RF.SetMode(Lagoon,25,0);
        }
        else
        {
          ReefAngel.RF.UseMemory=true;
        }
     }

    // When Return pump is off so is Skimmer
    if (!ReefAngel.Relay.Status(Return)) {
      ReefAngel.Relay.Override(Skimmer,0); 
    }

void CheckPower() {
  static boolean PowerOutage=false;
  static boolean DelayedPowerOutage=false;
    
    // Power Outage - Leave Single Flow Pump Powered
    if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY)) PowerOutage=true; //Expansion Relay 1 has lost power
    if (!PowerOutage)
    { 
      ReefAngel.Timer[1].Start();
    } 
    if (ReefAngel.Timer[1].IsTriggered())
    { 
      DelayedPowerOutage=true;
    }
    if (DelayedPowerOutage)
    {
    ReefAngel.Relay.Off (Flow1);
    ReefAngel.Relay.Off (Flow2);
    ReefAngel.Relay.Off (Flow3);
    ReefAngel.Relay.Off (Return);
    ReefAngel.Relay.Off (Skimmer);
    ReefAngel.Relay.Off (HeaterDisp);
    //set vortechs to low power
    }
    
    // Power Restored
    if (PowerOutage && ReefAngel.Relay.IsRelayPresent(EXP1_RELAY))
    {
      PowerOutage=false;
      DelayedPowerOutage=false;
      LastStart=now();
    }
}
////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "*****","*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate(5, 2);
    ReefAngel.LCD.Clear(COLOR_BLACK, 1, 11, 132, 11);
    pingSerial();

// Display Water Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
    ReefAngel.LCD.DrawHugeNumbers(COLOR_CRIMSON, 255, 5, 14, text);
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText(COLOR_INDIGO,255,80,14,"pH");
// Display pH Value
    ConvertNumToString(text, ReefAngel.Params.PH, 100);
    ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 95, 14, text, Num8x16);
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText(COLOR_ROYALBLUE,255,80,24,"Rm");
// Display Room Temp Value
    ConvertNumToString(text, ReefAngel.Params.Temp[T3_PROBE], 10);
    ReefAngel.LCD.DrawLargeText(COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16);
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear(DefaultBGColor,5,88,95,95);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,5,88,MoonPhaseLabel());
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText(COLOR_NAVY,255,5,98, "MoonLEDs:");
    ReefAngel.LCD.Clear(DefaultBGColor,59,98,75,106);
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,59,98, ReefAngel.PWM.GetActinicValue());
    ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,75,98, "%");
  // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

you cannot define a function within another function. your checkpower function is being defined inside the loop function code.
move it out and that should help.


Sent from my Nexus 7
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

I went ahead and updated your code and moved everything around how it should be. I test compiled and everything compiles just fine. I did not upload the code to a controller though.

The formatting is updated too. You will also need to put your portal information back in since you removed it before.
Hope this helps.

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>

// Define Named Relay Ports
#define Flow1           1
#define Flow2           2
#define Flow3           3
#define Return          4
#define Skimmer         5
#define VortechL        6
#define VortechR        7
#define HeaterDisp      8

#define CenterT5        Box1_Port1
#define FrontT5         Box1_Port2
#define BackT5          Box1_Port3
#define MoonLED         Box1_Port4
#define Unused          Box1_Port5
#define Reactor         Box1_Port6
#define Fan             Box1_Port7
#define HeaterSump      Box1_Port8

////// Place global variable code below here
// Custom Main
byte x, y;
char text[10];

////// Place global variable code above here

////// Setup Begin
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller

    // Controlled Modes Toggled Ports
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port7Bit | Port8Bit; //Fan,HeaterSump
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port8Bit; // Flow1-3,Return,Skimmer,HeaterDisp
    ReefAngel.WaterChangePortsE[0] = Port2Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; //Front+BackT5,Reactor,Fan,HeaterSump
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit; //Center+Front+BackT5

    // Water Temperature Settings & Overheat
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 820 );
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterDisp
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port8Bit; //Front+BackT5,HeaterSump

    // Ports that are always on
    ReefAngel.Relay.On( Flow1 );
    ReefAngel.Relay.On( Flow2 );
    ReefAngel.Relay.On( Flow3 );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    ReefAngel.Relay.On( Reactor );
    // Ports that are always off
    ReefAngel.Relay.Off( Unused );

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

    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval( 5 );

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

////// Loop Begin
void loop()
{
    // Ports that are Delayed
    ReefAngel.Relay.DelayedOn( Skimmer, 2 );
    // Temperature Control
    ReefAngel.StandardHeater( HeaterSump, 770, 773 );
    ReefAngel.StandardHeater( HeaterDisp, 767, 770 );
    ReefAngel.StandardFan( Fan, 810, 814 );
    // T5 Light Schedule
    ReefAngel.StandardLights( CenterT5, 9, 0, 20, 0 );

    if ( hour() == 14 && minute() >= 0 && minute() <= 59 ) {
        ReefAngel.Relay.Off( CenterT5 );
    }

    ReefAngel.StandardLights( FrontT5, 10, 0, 18, 0 );

    if ( hour() == 15 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( FrontT5 );
    }

    ReefAngel.StandardLights( BackT5, 11, 0, 19, 0 );

    if ( hour() == 16 && minute() >= 0 && minute() <= 29 ) {
        ReefAngel.Relay.Off( BackT5 );
    }

////// Place your custom code below here

    // RSM MoonLED Schedule
    if ( hour() >= 6 && hour() <= 8 ) {
        ReefAngel.StandardLights( MoonLED, 6, 0, 8, 59 );    //Morning
    } else if( hour() >= 20 && hour() <= 23 ) {
        ReefAngel.StandardLights( MoonLED, 20, 0, 23, 45 );    //Evening
    } else if( hour() >= 23 || hour() <= 4 ) if ( MoonPhase() >= 90 ) {
            ReefAngel.StandardLights( MoonLED, 23, 46, 4, 0 );    //Full Moon
        }

    // Moonphase LED Schedule
    if ( hour() >= 20 || hour() < 4 ) {
        ReefAngel.PWM.SetActinic( MoonPhase() );
        ReefAngel.PWM.SetDaylight( MoonPhase() );
    } else {
        ReefAngel.PWM.SetActinic( 0 );
        ReefAngel.PWM.SetDaylight( 0 );
    }

    //T5 Light Off Variable
    //if (hour()==12 && minute()>=30 && minute()<=44) ReefAngel.Relay.Off(CenterT5);
    //if (hour()==12 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==16 && minute()>=15 && minute()<=29) ReefAngel.Relay.Off(FrontT5);
    //if (hour()==13 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);
    //if (hour()==16 && minute()>=45 && minute()<=59) ReefAngel.Relay.Off(BackT5);

    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
        if ( hour() >= 16 && hour() <= 19 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( LongWave, 50, 30 );
        } else if ( hour() >= 20 || hour() < 7 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( Lagoon, 25, 0 );
        } else {
            ReefAngel.RF.UseMemory = true;
        }
    }

    // When Return pump is off so is Skimmer
    if ( !ReefAngel.Relay.Status( Return ) ) {
        ReefAngel.Relay.Override( Skimmer, 0 );
    }
    
    // Check the power here, the function is defined below
    CheckPower();

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

    // This should always be the last line
    ReefAngel.Portal( "*****", "*****" );
    ReefAngel.ShowInterface();
}
////// Loop End

////// Custom Function
void CheckPower()
{
    static boolean PowerOutage = false;
    static boolean DelayedPowerOutage = false;

    // Power Outage - Leave Single Flow Pump Powered
    if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = true;    //Expansion Relay 1 has lost power
    }

    if ( !PowerOutage ) {
        ReefAngel.Timer[1].Start();
    }

    if ( ReefAngel.Timer[1].IsTriggered() ) {
        DelayedPowerOutage = true;
    }

    if ( DelayedPowerOutage ) {
        ReefAngel.Relay.Off ( Flow1 );
        ReefAngel.Relay.Off ( Flow2 );
        ReefAngel.Relay.Off ( Flow3 );
        ReefAngel.Relay.Off ( Return );
        ReefAngel.Relay.Off ( Skimmer );
        ReefAngel.Relay.Off ( HeaterDisp );
        //set vortechs to low power
    }

    // Power Restored
    if ( PowerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = false;
        DelayedPowerOutage = false;
        LastStart = now();
    }
}
////// Custom Function End

////// Custom Main Begin
void DrawCustomMain()
{
// Display Date & Time
    ReefAngel.LCD.DrawDate( 5, 2 );
    ReefAngel.LCD.Clear( COLOR_BLACK, 1, 11, 132, 11 );
    pingSerial();

// Display Water Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T1_PROBE], 10 );
    ReefAngel.LCD.DrawHugeNumbers( COLOR_CRIMSON, 255, 5, 14, text );
    pingSerial();
// Display pH Text
    ReefAngel.LCD.DrawText( COLOR_INDIGO, 255, 80, 14, "pH" );
// Display pH Value
    ConvertNumToString( text, ReefAngel.Params.PH, 100 );
    ReefAngel.LCD.DrawLargeText( COLOR_INDIGO, 255, 95, 14, text, Num8x16 );
    pingSerial();
// Display Room Temp Text
    ReefAngel.LCD.DrawText( COLOR_ROYALBLUE, 255, 80, 24, "Rm" );
// Display Room Temp Value
    ConvertNumToString( text, ReefAngel.Params.Temp[T3_PROBE], 10 );
    ReefAngel.LCD.DrawLargeText( COLOR_ROYALBLUE, 255, 95, 24, text, Num8x16 );
    pingSerial();
// Vortech Info

//Moon Phase
    ReefAngel.LCD.Clear( DefaultBGColor, 5, 88, 95, 95 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 5, 88, MoonPhaseLabel() );
//Dimmable Moon LEDs
    ReefAngel.LCD.DrawText( COLOR_NAVY, 255, 5, 98, "MoonLEDs:" );
    ReefAngel.LCD.Clear( DefaultBGColor, 59, 98, 75, 106 );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 59, 98, ReefAngel.PWM.GetActinicValue() );
    ReefAngel.LCD.DrawText( COLOR_CORNFLOWERBLUE, 255, 75, 98, "%" );
    // Display Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 2, 107, TempRelay );
    pingSerial();
// Display Expansion Relay Box 1
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 2, 119, TempRelay );
    pingSerial();
}
////// Custom Main End

////// Custom Graph Begin
void DrawCustomGraph()
{}
///// Custom Graph End

modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Thanks a lot!

I uploaded the updated code and the power outage is working now.

Strange thing is that the overheat function isn't working now...I did a full power off and it temp is 82.0 and the overheat light isn't coming on and the ports aren't shutting off....any ideas?
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Mike's RSM 500 Code

Post by binder »

hmmm...more checking is needed. nothing is standing out to me at quick glance.


Sent from my iPad mini
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I recalibrated my pH probe for the first time since I set it up (Nov 2012). Before the calibration I had a pH or 8.34 and now after its at 7.75.

Could the pH be off by that much after about 2.5 years?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Forgot to mention that I moved the pH probe from the back of the display tank to the sump, could that be the difference? I'll move it back tonight and report back.

Any ideas on the overheat function not working?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

If you get T1 above 82F, nothing happens?
Not even the status LED?
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Correct, last week t1 was at 82 and ports did not shut off and the red light did not come on. I could try and get t1 above 82.

Sent from my HTC One_M8 using Tapatalk
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mike's RSM 500 Code

Post by rimai »

It has to go more than 82F and stay there for at least 3 seconds to be considered overheat.
Roberto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Ok it's working, sorry for the false alarm. Just never had it sit right at 82 for awhile.

I moved the ph probe gettin the sump to the DT and the ph reading hasn't changed much.

Sent from my HTC One_M8 using Tapatalk
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

pH was reading under 7 for the past two nights...doing the calibration again. Now its around 7.5, but its still way lower than it was at 8.5. Do I need a new probe?
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I recently ditched my T5 lights for the RSM S Series LEDs. I also did some wiring cleanup, added a skimmate container using High ATO, and just got an Avast Swabbie retrofit.

During the last few days I have been playing around with the Swabbie code. Not using timing in the memory I could get the port to switch on at 4am, but that was the only time (it wasn't running every 4 hours).

So I tried adding lnevo's code for the Swabbie. Compiles fine, but the relay does not run.

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 <PAR.h>
#include <ReefAngel.h>

// Define Custom Memory Locations
#define Mem_B_SwabbieRepeat   100
#define Mem_B_SwabbieTime     101

void init_memory() {
  // Initialize Custom Memory Locations
  InternalMemory.write(Mem_B_SwabbieRepeat,6); 
  InternalMemory.write(Mem_B_SwabbieTime,1);
  }

// Define Named Relay Ports
#define FlowPumps       1
#define Lights          2
#define Return          3
#define VortechL        4
#define VortechR        5
#define Skimmer         6
#define FanSump         7
#define HeaterSump      8

#define Reactor         Box1_Port1
#define Swabbie         Box1_Port2
#define Unused          Box1_Port3
#define Unused          Box1_Port4
#define Unused          Box1_Port5
#define WCMix           Box1_Port6
#define WCFlow          Box1_Port7
#define WCHeater        Box1_Port8

////// Place global variable code below here


////// Place global variable code above here

////// Setup Begin (on controller startup/reset)
void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen
    // Define labels for LCD screen
    ReefAngel.CustomLabels[0]="Flow Pumps";
    ReefAngel.CustomLabels[1]="Lights";
    ReefAngel.CustomLabels[2]="Return";
    ReefAngel.CustomLabels[3]="Vortech L";
    ReefAngel.CustomLabels[4]="Vortech R";
    ReefAngel.CustomLabels[5]="Skimmer";
    ReefAngel.CustomLabels[6]="Fan";
    ReefAngel.CustomLabels[7]="Heater";

    ReefAngel.CustomLabels[Box1_Port1Label] = "Reactor";
    ReefAngel.CustomLabels[Box1_Port2Label] = "Swabbie";
    ReefAngel.CustomLabels[Box1_Port3Label] = "";
    ReefAngel.CustomLabels[Box1_Port4Label] = "";
    ReefAngel.CustomLabels[Box1_Port5Label] = "";
    ReefAngel.CustomLabels[Box1_Port6Label] = "WCMix";
    ReefAngel.CustomLabels[Box1_Port7Label] = "WCFlow";
    ReefAngel.CustomLabels[Box1_Port8Label] = "WCHeater";
    
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit | Port5Bit; //Unused ports for testing RF module and random feedmode
    
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port6Bit | Port7Bit | Port8Bit; // Flowpumps,Return,VortechL,Skimmer,Fan,HeaterSump
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit ; //Reactor,Swabbie    
    
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port6Bit; //Lights
    ReefAngel.LightsOnPortsE[0] = 0;
    
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port8Bit; //HeaterSump
    ReefAngel.OverheatShutoffPortsE[0] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Ports that default on
    ReefAngel.Relay.On( FlowPumps );
    ReefAngel.Relay.On( Return );
    ReefAngel.Relay.On( VortechL );
    ReefAngel.Relay.On( VortechR );
    
    // Ports that default off
    ReefAngel.Relay.Off( Unused );
    ReefAngel.Relay.Off( Swabbie );
    ReefAngel.Relay.Off( WCMix );
    ReefAngel.Relay.Off( WCFlow );
    ReefAngel.Relay.Off( WCHeater );

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

    //5 second timer for power outage detection
    ReefAngel.Timer[1].SetInterval( 5 );    

    ////// Place additional initialization code above here
}
////// Setup End
////// Loop Begin
void loop()
{
    ReefAngel.Relay.On(Reactor); 
    ReefAngel.StandardHeater( HeaterSump );
    ReefAngel.StandardFan( FanSump );
    ReefAngel.StandardLights( Lights );  
    
////// Place your custom code below here

    //HighATO=on, delay start Skimmer | HighATO=off, Skimmer shuts off
    if (ReefAngel.HighATO.IsActive())
      ReefAngel.Relay.DelayedOn( Skimmer );
    else
      ReefAngel.Relay.Off( Skimmer );

    // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
    if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
        if ( hour() >= 16 && hour() <= 20 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( LongWave, 70, 30 );
        } else if ( hour() >= 20 || hour() < 7 ) {
            ReefAngel.RF.UseMemory = false;
            ReefAngel.RF.SetMode( ReefCrest, 40, 0 );
        } else {
            ReefAngel.RF.UseMemory = true;
        }
    }
    
//    ReefAngel.StandardHeater( HeaterWC, 775, 778 );

    
    // Turn off Skimmer & FanSump & Reactor if Return Pump is off
    if ( !ReefAngel.Relay.Status( Return ) ) {
        ReefAngel.Relay.Override( Skimmer, 0 );
        ReefAngel.Relay.Override( FanSump, 0 );
        ReefAngel.Relay.Override( Reactor, 0 );
    }
    
    // Check the power here, the function is defined below
    CheckPower();
    
////// Place your custom code above here

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

////// Custom Function
void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;
 
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}

void CheckPower()
{
    static boolean PowerOutage = false;
    static boolean DelayedPowerOutage = false;

    // Power Outage - Leave Only Vortech Pumps active
    if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = true;    //Expansion Relay 1 has lost power
    }

    if ( !PowerOutage ) {
        ReefAngel.Timer[1].Start();
    }

    if ( ReefAngel.Timer[1].IsTriggered() ) {
        DelayedPowerOutage = true;
    }

    if ( DelayedPowerOutage ) {
        ReefAngel.Relay.Off ( FlowPumps );
        ReefAngel.Relay.Off ( Return );
        ReefAngel.Relay.Off ( Skimmer );
        ReefAngel.Relay.Off ( Lights );
        ReefAngel.Relay.Off ( FanSump);
        ReefAngel.Relay.Off ( HeaterSump);
        //set vortechs to long wave? something that ripples surface
    }

    // Power Restored
    if ( PowerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
        PowerOutage = false;
        DelayedPowerOutage = false;
        LastStart = now();
    }
}
////// Custom Function End
When I read the custom memory location of 100 & 101, both result in 255. So I am assuming the memory locations aren't being written. Also when I manually changed the memory from 255 to 6 or 1 the relay has not turned on every six or one hours.

I am guessing maybe it has to do with this line which I do not have. I am not sure how to update it to write the memory for the Swabbie.

Code: Select all

InternalMemory.write(Mem_B_ResetMemory,false);
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

Ignore the init_memory function, it doesnt always work right. but please manually set both memory locations. One needs the runtime and the other gets the repeat value. Runtime should be 1 for one minute and repeat should be 6 for one hour.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

You mean 6 for six hours, right?

So remove init_memory lines and set manually...do I need to update the controller in order to see the swabbie port activate?

I set 100 to 6, and 101 to 1...
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You will not see it in the portal if thats what your looking for.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

The memory values or the relay switching on? I do see the relay switch at 4am.

Sent from my A0001 using Tapatalk
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You won't reliably see the port in the portal for relay activity.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

You also need to call RunSwabbie(); in your loop. I don see it there which means its never getting called.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Haha OK..guess I missed it from yours...I'll give it a shot

Sent from my A0001 using Tapatalk
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Yup adding run swabbie worked... Thanks Lee!

Sent from my A0001 using Tapatalk
Image
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

So I have my Swabbie installed and working, can't wait to see the skimmer in a few days.

I've updated a few things, curiosity of Lee's code.

I tested the ATO high, when the skimmate container is full, and the skimmer went off and sent me the alert.
  • Although when I return the float switch down, I got a Power Restored email?!?!
  • Also the skimmer does not go back to Auto when the float switch is back down. I got a fewDo I need to clear ATO for it to return to Auto?
I also tested turning the Return pump off, which does shut off the ports correctly.
  • But I also got the Power Restored email.
  • And when I manually turned on the ports, I got an email saying Skimmer Container full (maybe just a coincidence from testing ATO High).
Any idea what's going on with the items above?
Tomorrow I will have to test a few more things.

EDIT: Although my ATO High is set for 'On" now and I am getting emails. I did a controller restart and it's not making a difference.
Maybe I am getting many emails because I do not have this line in?

Code: Select all

skimmerAlert.SetDelay(3600); 

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 <PAR.h>
#include <WiFiAlert.h>
#include <ReefAngel.h>

// Define Custom Memory Locations
#define Mem_B_SwabbieRepeat   100
#define Mem_B_SwabbieTime     101

// Define Named Relay Ports
#define FlowPumps       1
#define Lights          2
#define Return          3
#define VortechL        4
#define VortechR        5
#define Skimmer         6
#define FanSump         7
#define HeaterSump      8

#define Reactor         Box1_Port1
#define Swabbie         Box1_Port2
#define Unused          Box1_Port3
#define Unused          Box1_Port4
#define Unused          Box1_Port5
#define WCMix           Box1_Port6
#define WCFlow          Box1_Port7
#define WCHeater        Box1_Port8

// Place global variable code below here
// Place global variable code above here

// #################### Setup (controller starting) ####################
void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen

  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = 0;
  ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit | Port5Bit; //Unused ports for testing random feeding

  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port3Bit; // Flowpumps,Return

  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port2Bit; //Lights

  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port2Bit | Port8Bit; //Lights,HeaterSump

  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // ON by default
  ReefAngel.Relay.On(FlowPumps);
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(VortechL);
  ReefAngel.Relay.On(VortechR);

  // OFF by default
  ReefAngel.Relay.Off(Unused);
  ReefAngel.Relay.Off(Swabbie);
  ReefAngel.Relay.Off(WCMix);
  ReefAngel.Relay.Off(WCFlow);
  ReefAngel.Relay.Off(WCHeater);

// ##### Place additional initialization code below here #####
  // Define labels for LCD screen
  ReefAngel.CustomLabels[0]="Flow Pumps";
  ReefAngel.CustomLabels[1]="Lights";
  ReefAngel.CustomLabels[2]="Return";
  ReefAngel.CustomLabels[3]="Vortech L";
  ReefAngel.CustomLabels[4]="Vortech R";
  ReefAngel.CustomLabels[5]="Skimmer";
  ReefAngel.CustomLabels[6]="Fan";
  ReefAngel.CustomLabels[7]="Heater";

  ReefAngel.CustomLabels[Box1_Port1Label] = "Reactor";
  ReefAngel.CustomLabels[Box1_Port2Label] = "Swabbie";
  ReefAngel.CustomLabels[Box1_Port3Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port4Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port5Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port6Label] = "WCMix";
  ReefAngel.CustomLabels[Box1_Port7Label] = "WCFlow";
  ReefAngel.CustomLabels[Box1_Port8Label] = "WCHeater";

  // 5 second timer for power outage detection
  ReefAngel.Timer[1].SetInterval( 5 );    

}

// #################### Loop ####################
void loop()
{
  ReefAngel.Relay.On( Reactor ); 
  ReefAngel.StandardHeater( HeaterSump );
  ReefAngel.StandardFan( FanSump );
  ReefAngel.StandardLights( Lights );  

  // ##### Place your custom code below here #####

  RunSwabbie();         // Skimmer neck cleaner
  SetRF();              // Set Vortech modes
  CheckPower();         // Monitor for power loss
  CheckSwitches();      // Monitor Float switches

  /*
  if (ReefAngel.DisplayedMenu = WATERCHANGE_MODE) {
   WaterchangeHeater( HeaterWC, 775, 778 );
   }
   */

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

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

// #################### Custom Function  ####################
void CheckSwitches() {
  static boolean returnOverride=true;
  static WiFiAlert skimmerAlert, atoAlert;

  if (ReefAngel.DisplayedMenu==FEEDING_MODE || ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
    returnOverride=true;

  // HighATO=on, delay start Skimmer | HighATO=off, Skimmer shuts off
  if (ReefAngel.HighATO.IsActive())
    ReefAngel.Relay.DelayedOn(Skimmer);
  else
    ReefAngel.Relay.Override(Skimmer,0);
  skimmerAlert.Send("Skimmate+container+full!+Skimmer+shutoff.");

  // If Return pump is off, kill power to others
  if (!ReefAngel.Relay.Status(Return)) {
    ReefAngel.Relay.Override(Skimmer,0);
    ReefAngel.Relay.Override(FanSump,0);
    ReefAngel.Relay.Override(Reactor,0);
    ReefAngel.Relay.Override(HeaterSump,0);
  }

  // Alert if ATO timeput flag
  if (bitRead(ReefAngel.AlertFlags,ATOTimeOutFlag))
    atoAlert.Send("ATO+timeout!+ATO+disabled.");
}

void SetRF() {

  // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
  if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
    if ( hour() >= 16 && hour() <= 20 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( LongWave, 70, 30 );
    } 
    else if ( hour() >= 20 || hour() < 7 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( ReefCrest, 40, 0 );
    } 
    else {
      ReefAngel.RF.UseMemory = true;
    }
  }
}
void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;

  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } 
  else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}

void CheckPower()
{
  static boolean powerOutage = false;
  static WiFiAlert powerAlert;
  static boolean delayedPowerOutage = false;

  // Power Outage - Leave Only Vortech Pumps active
  if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
    powerOutage = true;    //Expansion Relay 1 has lost power
  }

  if ( !powerOutage ) {
    ReefAngel.Timer[1].Start();
  }

  if ( ReefAngel.Timer[1].IsTriggered() ) {
    delayedPowerOutage = true;
  }

  if (delayedPowerOutage) {
    ReefAngel.Relay.Off(FlowPumps);
    ReefAngel.Relay.Off(Return);
    ReefAngel.Relay.Off(Skimmer);
    ReefAngel.Relay.Off(Lights);
    ReefAngel.Relay.Off(FanSump);
    ReefAngel.Relay.Off(HeaterSump);
    ReefAngel.RF.SetMode(Constant,70,0);
    powerAlert.Send("Power+lost!");
  }

  // Power Restored - return equipment back to normal power state
  if ( powerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
    powerOutage = false;
    delayedPowerOutage = false;
    LastStart = now();
    powerAlert.Send("Power+restored.",true);
  }
}

void WaterchangeHeater(byte HeaterRelay, int LowTemp, int HighTemp)
{
  if (ReefAngel.Params.Temp[T3_PROBE] == 0) return;  // Don't turn the heater on if the temp is reading 0
  if (ReefAngel.Params.Temp[T3_PROBE] <= LowTemp && ReefAngel.Params.Temp[T3_PROBE] > 0) ReefAngel.Relay.On(WCHeater);
  if (ReefAngel.Params.Temp[T3_PROBE] >= HighTemp) ReefAngel.Relay.Off(WCHeater);
}
// #################### Custom Function End ####################

Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

I'll take a look at your code later this week. The way my code is written it sets the override when these conditions occur so you just have to reset the ports to auto.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

I modified the code a bit and not am not getting skimmate full emails. But for some reason I have power restored emails.

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 <PAR.h>
#include <WiFiAlert.h>
#include <ReefAngel.h>

// Define Custom Memory Locations
#define Mem_B_SwabbieRepeat   100
#define Mem_B_SwabbieTime     101

// Define Named Relay Ports
#define FlowPumps       1
#define Lights          2
#define Return          3
#define VortechL        4
#define VortechR        5
#define Skimmer         6
#define FanSump         7
#define HeaterSump      8

#define Reactor         Box1_Port1
#define Swabbie         Box1_Port2
#define Unused          Box1_Port3
#define Unused          Box1_Port4
#define Unused          Box1_Port5
#define WCMix           Box1_Port6
#define WCFlow          Box1_Port7
#define WCHeater        Box1_Port8

// Place global variable code below here
// Place global variable code above here

// #################### Setup (controller starting) ####################
void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen

    // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = 0;
  ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit | Port5Bit; //Unused ports for testing random feeding

  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port3Bit; // Flowpumps,Return

  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port2Bit; //Lights

  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port2Bit | Port8Bit; //Lights,HeaterSump

  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // ON by default
  ReefAngel.Relay.On(FlowPumps);
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(VortechL);
  ReefAngel.Relay.On(VortechR);

  // OFF by default
  ReefAngel.Relay.Off(Unused);
  ReefAngel.Relay.Off(Swabbie);
  ReefAngel.Relay.Off(WCMix);
  ReefAngel.Relay.Off(WCFlow);
  ReefAngel.Relay.Off(WCHeater);

  // ##### Place additional initialization code below here #####
  // Define labels for LCD screen
  ReefAngel.CustomLabels[0]="Flow Pumps";
  ReefAngel.CustomLabels[1]="Lights";
  ReefAngel.CustomLabels[2]="Return";
  ReefAngel.CustomLabels[3]="Vortech L";
  ReefAngel.CustomLabels[4]="Vortech R";
  ReefAngel.CustomLabels[5]="Skimmer";
  ReefAngel.CustomLabels[6]="Fan";
  ReefAngel.CustomLabels[7]="Heater";

  ReefAngel.CustomLabels[Box1_Port1Label] = "Reactor";
  ReefAngel.CustomLabels[Box1_Port2Label] = "Swabbie";
  ReefAngel.CustomLabels[Box1_Port3Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port4Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port5Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port6Label] = "WCMix";
  ReefAngel.CustomLabels[Box1_Port7Label] = "WCFlow";
  ReefAngel.CustomLabels[Box1_Port8Label] = "WCHeater";

  // 5 second timer for power outage detection
  ReefAngel.Timer[1].SetInterval( 5 );    
}

// #################### Loop ####################
void loop()
{
  ReefAngel.Relay.On(Reactor); 
  ReefAngel.StandardHeater(HeaterSump);
  ReefAngel.StandardFan(FanSump);
  ReefAngel.StandardLights(Lights); 
  ReefAngel.Relay.DelayedOn(Skimmer);

  // ##### Place your custom code below here #####

  RunSwabbie();         // Skimmer neck cleaner
  SetRF();              // Set Vortech modes
  CheckPower();         // Monitor for power loss
  CheckSwitches();      // Monitor float switches

  /*
  if (ReefAngel.DisplayedMenu = WATERCHANGE_MODE) {
   WaterchangeHeater( HeaterWC, 775, 778 );
   }
   */

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

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

// #################### Custom Function  ####################
void CheckSwitches() {
  static boolean returnOverride=true;
  static WiFiAlert skimmerAlert, atoAlert;
  skimmerAlert.SetDelay(3600);
  atoAlert.SetDelay(3600);

  if (ReefAngel.DisplayedMenu==FEEDING_MODE || ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
    returnOverride=true;

  // HighATO=off, Skimmer shuts off
  if (!ReefAngel.HighATO.IsActive()) {
    skimmerAlert.Send("Skimmate+container+is+full!+Skimmer+has+been+shutoff.");
    ReefAngel.Relay.Override(Skimmer,0);
  }

  // If Return pump is off, kill power to others
  if (!ReefAngel.Relay.Status(Return)) {
    ReefAngel.Relay.Override(Skimmer,0);
    ReefAngel.Relay.Override(FanSump,0);
    ReefAngel.Relay.Override(Reactor,0);
    ReefAngel.Relay.Override(HeaterSump,0);
  }

  // Alert if ATO timeout flag
  if (bitRead(ReefAngel.AlertFlags,ATOTimeOutFlag))
    atoAlert.Send("ATO+timeout!+ATO+disabled.");
}

void SetRF() {
  // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
  if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
    if ( hour() >= 16 && hour() <= 20 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( LongWave, 70, 30 );
    } 
    else if ( hour() >= 20 || hour() < 7 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( ReefCrest, 40, 0 );
    } 
    else {
      ReefAngel.RF.UseMemory = true;
    }
  }
}

void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;

  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } 
  else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}

void CheckPower()
{
  static boolean powerOutage = false;
  static WiFiAlert powerAlert;
  static boolean delayedPowerOutage = false;

  // Power Outage - Leave Only Vortech Pumps active
  if ( !ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
    powerOutage = true;    //Expansion Relay 1 has lost power
  }

  if ( !powerOutage ) {
    ReefAngel.Timer[1].Start();
  }

  if ( ReefAngel.Timer[1].IsTriggered() ) {
    delayedPowerOutage = true;
  }

  if (delayedPowerOutage) {
    ReefAngel.Relay.Off(FlowPumps);
    ReefAngel.Relay.Off(Return);
    ReefAngel.Relay.Off(Skimmer);
    ReefAngel.Relay.Off(Lights);
    ReefAngel.Relay.Off(FanSump);
    ReefAngel.Relay.Off(HeaterSump);
    ReefAngel.RF.SetMode(Constant,70,0);
    powerAlert.Send("Power+lost!");
  }

  // Power Restored - return equipment back to normal power state
  if ( powerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) {
    powerOutage = false;
    delayedPowerOutage = false;
    LastStart = now();
    powerAlert.Send("Power+restored.",true);
  }
}

void WaterchangeHeater(byte HeaterRelay, int LowTemp, int HighTemp)
{
  if (ReefAngel.Params.Temp[T3_PROBE] == 0) return;  // Don't turn the heater on if the temp is reading 0
  if (ReefAngel.Params.Temp[T3_PROBE] <= LowTemp && ReefAngel.Params.Temp[T3_PROBE] > 0) ReefAngel.Relay.On(WCHeater);
  if (ReefAngel.Params.Temp[T3_PROBE] >= HighTemp) ReefAngel.Relay.Off(WCHeater);
}
// #################### Custom Function End ####################
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

I updated my code the other day. I'm using a different mechanism to delay the power outage. I dont recommend the way you are doing it with the Timer class. I'm not sire whats happening but clearly you are falsely triggering the power outage and this could cause robertos code to not send you the right alert.

Does the skimmer turn off when your float switch changes? If so the code to send the skimmer full alarm should be fine.
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

OK, I see you include a delay in the poweroutage code, cool! I will give it a shot and update my code later tonight.

The skimmer does shutoff when the float switch is up, and I got the email. So that seems to be working well. I am waiting for the container to actually fill up for a real test. (It might be two months unless I change to a wetter skimmate)
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

Cool. Yeah I was getting tired of false alarms :)
modulok
Posts: 166
Joined: Wed Oct 24, 2012 8:37 am

Re: Mike's RSM 500 Code

Post by modulok »

Not sure why, but the checkpower function isn't working right.

When I kill power to exp relay box only the return shuts off like it should. Lights stay on, skimmer, fan, heater, reactor shut off due to return being off. No email from Power Lost.

After power is returned I get emails every few minutes for Power Restored, and I hear relays but do not see anything switching on or off. The Return does not come back on (waited 5 minutes). Also the ports that shut off when return is off do not reset to auto.

I am curious what this line does. Wait for 300 seconds to signal poweroutage?

Code: Select all

if (now()-powerOutage > 300) {
      ReefAngel.Relay.Set(Return, now()%3600<300);
    }

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 <PAR.h>
#include <WiFiAlert.h>
#include <ReefAngel.h>

// Define Custom Memory Locations
#define Mem_B_SwabbieRepeat   100
#define Mem_B_SwabbieTime     101

// Define Named Relay Ports
#define FlowPumps       1
#define Lights          2
#define Return          3
#define VortechL        4
#define VortechR        5
#define Skimmer         6
#define FanSump         7
#define HeaterSump      8

#define Reactor         Box1_Port1
#define Swabbie         Box1_Port2
#define Unused          Box1_Port3
#define Unused          Box1_Port4
#define Unused          Box1_Port5
#define WCMix           Box1_Port6
#define WCFlow          Box1_Port7
#define WCHeater        Box1_Port8

// Place global variable code below here

  // Vortech Variables
  byte vtMode, vtSpeed, vtDuration;
    
// Place global variable code above here

// #################### Setup (controller starting) ####################
void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen

    // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = 0;
  ReefAngel.FeedingModePortsE[0] = Port3Bit | Port4Bit | Port5Bit; //Unused ports for testing random feeding

  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port1Bit | Port3Bit; // Flowpumps,Return

  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port2Bit; //Lights

  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port2Bit | Port8Bit; //Lights,HeaterSump

  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;

  // ON by default
  ReefAngel.Relay.On(FlowPumps);
  ReefAngel.Relay.On(Return);
  ReefAngel.Relay.On(VortechL);
  ReefAngel.Relay.On(VortechR);

  // OFF by default
  ReefAngel.Relay.Off(Unused);
  ReefAngel.Relay.Off(Swabbie);
  ReefAngel.Relay.Off(WCMix);
  ReefAngel.Relay.Off(WCFlow);
  ReefAngel.Relay.Off(WCHeater);

  // ##### Place additional initialization code below here #####
  // Define labels for LCD screen
  ReefAngel.CustomLabels[0]="Flow Pumps";
  ReefAngel.CustomLabels[1]="Lights";
  ReefAngel.CustomLabels[2]="Return";
  ReefAngel.CustomLabels[3]="Vortech L";
  ReefAngel.CustomLabels[4]="Vortech R";
  ReefAngel.CustomLabels[5]="Skimmer";
  ReefAngel.CustomLabels[6]="Fan";
  ReefAngel.CustomLabels[7]="Heater";

  ReefAngel.CustomLabels[Box1_Port1Label] = "Reactor";
  ReefAngel.CustomLabels[Box1_Port2Label] = "Swabbie";
  ReefAngel.CustomLabels[Box1_Port3Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port4Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port5Label] = "Unused";
  ReefAngel.CustomLabels[Box1_Port6Label] = "WCMix";
  ReefAngel.CustomLabels[Box1_Port7Label] = "WCFlow";
  ReefAngel.CustomLabels[Box1_Port8Label] = "WCHeater"; 
}

// #################### Loop ####################
void loop()
{
  ReefAngel.Relay.On(Reactor); 
  ReefAngel.StandardHeater(HeaterSump);
  ReefAngel.StandardFan(FanSump);
  ReefAngel.StandardLights(Lights); 
  ReefAngel.Relay.DelayedOn(Skimmer);

  // ##### Place your custom code below here #####

  RunSwabbie();         // Skimmer neck cleaner
  SetRF();              // Set Vortech modes
  CheckPower();         // Monitor for power loss
  CheckSwitches();      // Monitor float switches

  /*
  if (ReefAngel.DisplayedMenu = WATERCHANGE_MODE) {
   WaterchangeHeater( HeaterWC, 775, 778 );
   }
   */

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

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

// #################### Custom Function  ####################
void CheckSwitches() {
  static boolean returnOverride=true;
  static WiFiAlert skimmerAlert, atoAlert;
  skimmerAlert.SetDelay(3600);
  atoAlert.SetDelay(3600);

  if (ReefAngel.DisplayedMenu==FEEDING_MODE || ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
    returnOverride=true;

  // HighATO=off, Skimmer shuts off
  if (!ReefAngel.HighATO.IsActive()) {
    skimmerAlert.Send("Skimmate+container+is+full!+Skimmer+has+been+shutoff.");
    ReefAngel.Relay.Override(Skimmer,0);
  }

  // If Return pump is off, kill power to others
  if (!ReefAngel.Relay.Status(Return)) {
    ReefAngel.Relay.Override(Skimmer,0);
    ReefAngel.Relay.Override(FanSump,0);
    ReefAngel.Relay.Override(Reactor,0);
    ReefAngel.Relay.Override(HeaterSump,0);
  }

  // Alert if ATO timeout flag
  if (bitRead(ReefAngel.AlertFlags,ATOTimeOutFlag))
    atoAlert.Send("ATO+timeout!+ATO+disabled.");
}

void SetRF() {
  // Vortech MP40 | Constant | Lagoon | ReefCrest | ShortWave 1=10ms | LongWave 1=1s | NutrientTransport 1=10ms | TidalSwell
  if ( ReefAngel.DisplayedMenu != FEEDING_MODE || ReefAngel.DisplayedMenu != WATERCHANGE_MODE ) {
    if ( hour() >= 16 && hour() <= 20 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( LongWave, 70, 30 );
    } 
    else if ( hour() >= 20 || hour() < 7 ) {
      ReefAngel.RF.UseMemory = false;
      ReefAngel.RF.SetMode( ReefCrest, 40, 0 );
    } 
    else {
      ReefAngel.RF.UseMemory = true;
    }
  }
}

void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;

  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } 
  else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}

void CheckPower() {
  static time_t powerOutage=false;
  static WiFiAlert powerAlert;

  // Power Outage - Leave Only Vortech Pumps active
  if (!ReefAngel.Relay.IsRelayPresent(EXP1_RELAY) && !powerOutage) //Relay Expansion NOT detected
  {
    powerOutage=now();
    if (now()-powerOutage > 300) {
      ReefAngel.Relay.Set(Return, now()%3600<300);
    }
 
    ReefAngel.Relay.Off(FlowPumps);
    ReefAngel.Relay.Off(Return);
    ReefAngel.Relay.Off(Skimmer);
    ReefAngel.Relay.Off(Lights);
    ReefAngel.Relay.Off(FanSump);
    ReefAngel.Relay.Off(HeaterSump);
    ReefAngel.RF.SetMode(Constant,70,0);
    if (now()-powerOutage > 10) { // Wait 10 seconds before sending to avoid false alarms
      powerAlert.Send("Power+lost!");
      }
  }
  
  // Power Restored - return equipment back to normal power state
  if (powerOutage && ReefAngel.Relay.IsRelayPresent( EXP1_RELAY ) ) 
  {
    powerOutage=0;
    LastStart=now();
    ReefAngel.RF.SetMode(vtMode,vtSpeed,vtDuration);
    powerAlert.Send("Power+restored.",true);
  }
}

void WaterchangeHeater(byte HeaterRelay, int LowTemp, int HighTemp)
{
  if (ReefAngel.Params.Temp[T3_PROBE] == 0) return;  // Don't turn the heater on if the temp is reading 0
  if (ReefAngel.Params.Temp[T3_PROBE] <= LowTemp && ReefAngel.Params.Temp[T3_PROBE] > 0) ReefAngel.Relay.On(WCHeater);
  if (ReefAngel.Params.Temp[T3_PROBE] >= HighTemp) ReefAngel.Relay.Off(WCHeater);
}
// #################### Custom Function End ####################
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Mike's RSM 500 Code

Post by lnevo »

That line says after the power is out for 5 minutes, run the return pump for 5 minutes each hour. This way my UPS conserves power to run the mp40s
Post Reply