I am in South Africa - running a 75G mixed reef.
I recently got an RA+, expansion module, salinity, dimming, jebao cables and wifi. I am struggling a bit with the salinity probe giving extremely varying results, to the point where the local distributor replaced the box (not the probe). I have since figured my DIY LED unit causes some stray voltage in the tank. I have absolutely no idea how that happens as it is not touching the water but it is causing some stray voltage when it is on. When the lights are unplugged completely only then does the stray voltage disappear. Just switching off the socket does not solve it, I have remove the plug.
Anyway - I need some of the clever guys here to help me with a few things.
1: I am running the jebao cables and got some nice code here for Else mode which I do like. I have also different power modes at different times. What I need help with is to be able to change the mode from the wifi page. How can I do that?
2: Then secondly, I have built a little ghetto power sensor. I want to connect the whole RA system to my backup power, but when power goes out I want it to be sensed and switch off some of the devices. I have a 12 V power supply connected to a relay. The relay is connected to one of the ATO ports. I have tested the sensing ability, that works a charm, I just need some help on the code with that.
3: Notifications - I have set up some notifications on the portal, and linked that to a sms service. Therefore, whenever I get a portal notification, I get an sms. Ideally I want the RA to trigger the notification when the power goes out as the internet connection will only stay up for a minute or two when the power goes out. In South Africa power outages are regular occurrences so I need to get that working.
Here is my current code:
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>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
ReefAngel.SetTemperatureUnit( Celsius ); // set to Celsius Temperatures
ReefAngel.Timer[FEEDING_TIMER].SetInterval(180); // Set Feeding time to 3 mins
ReefAngel.Use2014Screen(); // Let's use 2014 Screen
ReefAngel.AddSalinityExpansion(); // Salinity Expansion Module
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | 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 = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T2_PROBE;
ReefAngel.OverheatProbe = T2_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 265 );
// Feeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
// Ports that are always on
ReefAngel.Relay.On( Port2 );
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port6 );
ReefAngel.Relay.On( Port7 );
ReefAngel.Relay.On( Port8 );
////// Place additional initialization code below here
ReefAngel.CustomLabels[0]="Skimmer";
ReefAngel.CustomLabels[1]="Return";
ReefAngel.CustomLabels[2]="Heater";
ReefAngel.CustomLabels[3]="Fans";
ReefAngel.CustomLabels[4]="Reactor";
ReefAngel.CustomLabels[5]="Unused";
ReefAngel.CustomLabels[6]="Unused";
ReefAngel.CustomLabels[7]="Vertex";
ReefAngel.PHMin=527;
ReefAngel.PHMax=825;
ReefAngel.UseFlexiblePhCalibration();
//* ReefAngel.SalMax=2780;*//
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.Relay.DelayedOn( Port1,5 );
ReefAngel.StandardHeater( Port3,245,255 );
ReefAngel.StandardFan( Port4,250,265 );
ReefAngel.Relay.DelayedOn( Port5,3 );
ReefAngel.DCPump.UseMemory = false;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.SetMode( Custom,70,10 );
ReefAngel.DCPump.ActinicChannel = AntiSync;
ReefAngel.DCPump.ExpansionChannel[0] = None;
ReefAngel.DCPump.ExpansionChannel[1] = None;
ReefAngel.DCPump.ExpansionChannel[2] = None;
ReefAngel.DCPump.ExpansionChannel[3] = None;
ReefAngel.DCPump.ExpansionChannel[4] = None;
ReefAngel.DCPump.ExpansionChannel[5] = None;
////// Place your custom code below here
if (hour()>=11 && hour()<21)
{
ReefAngel.PWM.SetDaylight( ElseMode(30,30,true)); // Else at 30% +/- 30% on sync mode
ReefAngel.PWM.SetActinic( ElseMode(30,30,false));
}
else if (hour()>=21 && hour()<23)
{
ReefAngel.PWM.SetDaylight( NutrientTransportMode(40,30,4000,true) ); // Nutrient Transport 30%minspeed - 40%maxspeed - 200ms
ReefAngel.PWM.SetActinic( NutrientTransportMode(40,30,4000,false) );
}
else if (hour()>=23 || hour()<11)
{
ReefAngel.PWM.SetDaylight( ElseMode(25,15,true) ); // Else at 25% +/- 15% on sync mode
ReefAngel.PWM.SetActinic( ElseMode(25,15,false) );
}
///// Sample code for notifications
/*
if (ReefAngel.Params.Temp[1]<750 && ReefAngel.Params.Temp[1]>0) WifiSendAlert(3,true);
if (ReefAngel.Params.Temp[1]>760 && ReefAngel.Params.Temp[1]<1850) WifiSendAlert(3,false);
*/
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "albe" );
ReefAngel.ShowInterface();
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
// Static's only initialize the first time they are called
static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
static int Delay = random( 500, 2000); // Set the initial delay
static int NewSpeed = MidPoint; // Set the initial speed
static int AntiSpeed = MidPoint; // Set the initial anti sync speed
if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
{
Delay=random(500,2000); // If so, come up with a new delay
int ChangeUp = random(Offset); // Amount to go up or down
if (random(100)<50) // 50/50 chance of speed going up or going down
{
NewSpeed = MidPoint - ChangeUp;
AntiSpeed = MidPoint + ChangeUp;
}
else
{
NewSpeed = MidPoint + ChangeUp;
AntiSpeed = MidPoint - ChangeUp;
}
LastChange=millis(); // Reset the time of the last change
}
if (WaveSync)
{
return NewSpeed;
}
else
{
return AntiSpeed;
}
}
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=xxxxxxxxxx@xxxxxxxxxx&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));
}
}
}