Use PHControl on PH Expansion

Expansion modules and attachments
Post Reply
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Use PHControl on PH Expansion

Post by mng777777 »

Hi all,
I am looking for some help coding. I want to use PHControl with my PH Expansion module so that I can edit the internal memory values from the app. What is the correct way to code this?
Image
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

To elaborate further, I actually need CO2 Control, but I am already using it so what I came up with was to use PHControl and just swap some values. will this work?

Code: Select all

void ReefAngelClass::PHControl(byte PHControlRelay, int LowPH, int HighPH)
{
	if (Params.PHExp <= LowPH) Relay.Off(PHControlRelay);  // If PHExp <= LowPH - turn Off PHControlRelay
	if (Params.PHExp >= HighPH) Relay.On(PHControlRelay);  // If sensor PHExp >= HighPH - turn On PHControlRelay
Assuming this is correct, then can I just add it as custom code, or do I need to edit the ReefAngel.cpp library?

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.Use2014Screen();  // Let's use 2014 Screen 
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit | Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit | Port3Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port4Bit | Port6Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;


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

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

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

void loop()
{
    ReefAngel.CO2Control( Port1 );
    ReefAngel.SingleATOLow( Port3 );
    ReefAngel.StandardHeater( Port4 );
    ReefAngel.Relay.DelayedOn( Port5 );
    ReefAngel.MoonLights( Port6 );
    ////// Place your custom code below here

/// Custom Labels    
ReefAngel.CustomLabels[0]="CO2";  
ReefAngel.CustomLabels[1]="Reactor";  
ReefAngel.CustomLabels[2]="ATO";  
ReefAngel.CustomLabels[3]="Heater";  
ReefAngel.CustomLabels[4]="Power Heads";  
ReefAngel.CustomLabels[5]="Fuge Light";  
ReefAngel.CustomLabels[6]="Return";  
ReefAngel.CustomLabels[7]="Skimmer";

/// PHExp params to control Reactor feed pump 
if ( ReefAngel.Params.PHExp < 800 ) ReefAngel.Relay.Off( Port2 ); // Reactor Feed
if ( ReefAngel.Params.PHExp >= 840 ) ReefAngel.Relay.On( Port2 ); // Reactor Feed

/// DT Float switch to control Return in emergency overflow condition
if (ReefAngel.HighATO.IsActive()) // DT Float Switch

    ReefAngel.Relay.On(Port7); 
else
    ReefAngel.Relay.Off(Port7);    

/// Check for system uptime to delay ATO 
bool atoSpanReached;  //flag to determine if the controller has been running long enough to start ATO functionality

  if(!atoSpanReached) 
  {
     if(millis() >= 300000) //Has program been running for 5 minutes?
       atoSpanReached = true;  //It has so then set the flag
  }
  if(atoSpanReached) //Only run the ATO operations if the flag has been set
  {
     if (ReefAngel.LowATO.IsActive())
        ReefAngel.SingleATO( true,Port3,60,10 );
     else
        ReefAngel.Relay.Off( Port3 );
  }    
  
///// Defines custom variables to use for notifications on alerts in the app
  ReefAngel.ShowInterface();
if ( InternalMemory.read(ATO_Single_Exceed_Flag) == 1 )
{
ReefAngel.CustomVar[0]=1;
}
else
{
ReefAngel.CustomVar[0]=0;
}
if ( InternalMemory.read(Overheat_Exceed_Flag) == 1 )
{
ReefAngel.CustomVar[1]=1;
}
else
{
ReefAngel.CustomVar[1]=0;
}
if ( InternalMemory.read(BusLockFlag) == 1 )
{
ReefAngel.CustomVar[2]=1;
}
else
{
ReefAngel.CustomVar[2]=0;
}
  

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

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

Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Use PHControl on PH Expansion

Post by rimai »

Looks like you got it :)
Roberto.
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

Thank you! Does is just go in the custom code section?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Use PHControl on PH Expansion

Post by rimai »

No, the code you posted already had that.
This is from your own code:

Code: Select all

/// PHExp params to control Reactor feed pump 
if ( ReefAngel.Params.PHExp < 800 ) ReefAngel.Relay.Off( Port2 ); // Reactor Feed
if ( ReefAngel.Params.PHExp >= 840 ) ReefAngel.Relay.On( Port2 ); // Reactor Feed
Roberto.
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

The problem is that my current code has to be uploaded every time I want to change the values. I'm looking for a way to change it to an internal memory setting

Justin (San Francisco),
sent from tapatalk
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Use PHControl on PH Expansion

Post by lnevo »

I just created a patch to the dev library to add a flag to PHControl and CO2Control to use the expansion or not. The default without the argument is false.

You would need to use the command like this to use the ph Expansion

ReefAngel.PHControl(Port2, 800, 840, true);

Additionally, I added the following functions to set and read the memory locations.

int PHEControlOn_read();
void PHEControlOn_write(const int value);
int PHEControlOff_read();
void PHEControlOff_write(const int value);

You could also use the wifi to set the memory as well.

The branch is located here https://github.com/lnevo/Libraries/tree/phecontrol

If you could test it I will submit the patch to Roberto.
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

is there a simple way to download all 5 of the files that were patched? I am still a newb!
Image
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

I think I figured it out. I downloaded the zip, then backed up my library by renaming the 5 files in my current library then pasted the 5 new files into my library. I am going to update my custom code, upload all of it, and give it a test run. I'll let you know how it goes.
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Use PHControl on PH Expansion

Post by lnevo »

No thats the dev libraries you need the whole zip file. Not just the 5 files..
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

lnevo wrote:I just created a patch to the dev library to add a flag to PHControl and CO2Control to use the expansion or not. The default without the argument is false.

You would need to use the command like this to use the ph Expansion

ReefAngel.PHControl(Port2, 800, 840, true);

Additionally, I added the following functions to set and read the memory locations.

int PHEControlOn_read();
void PHEControlOn_write(const int value);
int PHEControlOff_read();
void PHEControlOff_write(const int value);

You could also use the wifi to set the memory as well.

The branch is located here https://github.com/lnevo/Libraries/tree/phecontrol

If you could test it I will submit the patch to Roberto.
So the same would work for CO2Control, but the custom line added would read something like:

Code: Select all

ReefAngel.CO2Control(Port2, 800, 840, true); 
Right?
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Use PHControl on PH Expansion

Post by lnevo »

Yep.
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

Getting this error on RA Client when trying to read values:
*****11/7/2014 2:09:20 PM*****
Message:
This request operation sent to net.tcp://localhost:8733/ReefAngelListener/ did not receive a reply within the configured timeout (00:01:00). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.
StackTrace:

Server stack trace:
at System.ServiceModel.Dispatcher.DuplexChannelBinder.SyncDuplexRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at ReefAngelClient.Classes.MemoryController.GetMemoryValues(ReefAngelListenerClient raService)
at ReefAngelClient.Form1.RefreshMemoryValues()
Any ideas?
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Use PHControl on PH Expansion

Post by lnevo »

Yes, there's an INI file that contains the memory locations for the RA. The dev libraries and my patch added a lot to the number of memory locations. You will need to update that file. I don't use the client so I'm not exactly familiar with it. Roberto may be able to give a better suggestion plus he's better at searching the forum than I.

I did give you the functions to read/write the variables in code so you don't have to change them through the client... but I dont' know if not having the client helps you much....
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

If not using the client, what other method would you use? They aren't loaded in the app either.

Justin (San Francisco),
sent from tapatalk
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Use PHControl on PH Expansion

Post by lnevo »

I'm not sure what you are asking. Can you clarify what you still need to do?
mng777777
Posts: 29
Joined: Tue Sep 30, 2014 2:05 pm

Re: Use PHControl on PH Expansion

Post by mng777777 »

How do you read/write the variables if you're not using the client? Are you doing it through the portal?

Justin (San Francisco),
sent from tapatalk
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Use PHControl on PH Expansion

Post by rimai »

The Client doesn't have those memory location options.
The Portal and iphone app can change the most used and the android app can change them all.
Do you have any memory location in particular you would like to change? Maybe it is already in the Portal already.
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Use PHControl on PH Expansion

Post by lnevo »

You can do it in the code also. The functions to do so are in post 7. You can also do it with straight http requests...

http://reefangelwifi/mi365

That will read PHEControlOn

http://reefangelwifi/mi367,800

That will set PHEControlOff to 8.00
Post Reply