New ReefAngel

New members questions
Post Reply
Albe
Posts: 20
Joined: Thu Dec 19, 2013 8:13 am

New ReefAngel

Post by Albe »

Hi everyone - I have been lurking here for quite a while so I thought it is time for my first post here.

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)); 
    }
  }
}
Another thing which I have noticed is that sometimes the /wifi page loads the default page, but then it seems to connect to the reefangel site to download the labels and other information. This *sometimes* takes a while so the page never gets to the point of actually displaying information. I have seen the same on a fellow reefer's RA. I think it is caused by the internet connection. Is there any way I can already specify that information in the RA's memory so that it doesn't try to get that information from the portal? Generally for american/european users it might not be an issue but down here at the bottom of Africa it can be a problem when international bandwidth is at a premium.
ReEfnWrX
Posts: 234
Joined: Tue Nov 05, 2013 8:40 am
Location: Houston TX

Re: New ReefAngel

Post by ReEfnWrX »

You can register your RA at www.reeftronics.net Anytime the site cannot communicate with your RA it will send you an email. This is a good backup/failsafe to your battery back up and RA/Portal email alerts.
Image
Albe
Posts: 20
Joined: Thu Dec 19, 2013 8:13 am

Re: New ReefAngel

Post by Albe »

Thanks, I have already registered there.

I need to distinguish between a power outage and just an internet disconnect as well, thats where a notification would help a lot.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: New ReefAngel

Post by lnevo »

Look at the function CheckPower() in my INO file. You would have to change the condition from looking at the relay expansion that I am to looking at the ATO port your using. But same concept. Same things to do before / after.

Note that the WiFiAlert() functions are not in the current production libraries.
Albe
Posts: 20
Joined: Thu Dec 19, 2013 8:13 am

Re: New ReefAngel

Post by Albe »

Thanks Lee, I am trying to dissect your file at the moment.

Any suggestions on the other labels and custom modes for the jebao's in conjunction with the Else mode?
Albe
Posts: 20
Joined: Thu Dec 19, 2013 8:13 am

Re: New ReefAngel

Post by Albe »

Ok I have found the code in your INO, I added the #include <WiFiAlert.h> and your wifialert files to libraries folder.

When I add the first few lines of your code I get this error:
Albe_v0_1.cpp: In function 'void CheckPower()':
Albe_v0_1:127: error: 'WiFiAlert' does not name a type
Albe_v0_1:143: error: 'powerAlert' was not declared in this scope
Albe_v0_1:155: error: 'powerAlert' was not declared in this scope

I am probably leaving something out, my programming skills are rusty to non-existent at the moment, last time I touched something like this prior to getting a RA was in 1997...

Please help?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: New ReefAngel

Post by lnevo »

Look at Sacohen's INO for what i did with his Jaebo. As far as the /wifi code its still in development and I dont use it since it doesnt work right for me.. So no comment on that part :)
Albe
Posts: 20
Joined: Thu Dec 19, 2013 8:13 am

Re: New ReefAngel

Post by Albe »

Got the wifialert working - just reimported the library, must have made a mistake the first time.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: New ReefAngel

Post by lnevo »

Cool
Post Reply