Page 1 of 5
Re: Custom code, please help
Posted: Mon Apr 23, 2012 12:43 am
by d0lph1n
it looks like it was a weird contact issue. I was able to fix it by taping the t2&t3 cables to the ph connector.
Regarding PWMSlope, after midnight, it doesn't work anymore and the AP & DP are set to zero.
Please advise. Thank you.
if (hour() > 6 && hour() < 22)
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
else
ReefAngel.PWM.SetDaylight(PWMSlope(22,0,6,0,0,80,240,0));
if (hour() > 6 && hour() < 22)
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
else
ReefAngel.PWM.SetActinic(PWMSlope(22,0,6,0,0,80,180,0));
Re: Custom code, please help
Posted: Mon Apr 23, 2012 9:05 am
by rimai
The slope can't cross over to next day

What is that you are trying to achieve?
Re: Custom code, please help
Posted: Mon Apr 23, 2012 1:50 pm
by d0lph1n
I'm trying to have different settings between 10pm and 6am next day, for both drivers.
Re: Custom code, please help
Posted: Mon Apr 23, 2012 2:03 pm
by rimai
But, is the PWM supposed to be at 80% overnight?
Re: Custom code, please help
Posted: Mon Apr 23, 2012 2:43 pm
by d0lph1n
probably you don't remember, I have 2 drivers and 2 lights. Each light has A&D circuits. Practically, the drivers are shared by the lights ..on opposite schedule.
Re: Custom code, please help
Posted: Mon Apr 23, 2012 3:09 pm
by rimai
Ok, in this case, we will have to do some other logic.
Try this code and let me know if it works:
Code: Select all
#include <Salinity.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <ReefAngel.h>
void setup()
{
ReefAngel.Init();
}
void loop()
{
if (hour() > 6 && hour() < 22)
{
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
}
else
{
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,80,240,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,80,180,0));
}
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 8:34 am
by d0lph1n
Thanks Roberto. I'll test it tonight.
Re: Custom code, please help
Posted: Tue Apr 24, 2012 1:11 pm
by d0lph1n
I tested it and at midnight the ap/dp values go to zero. this is the code:
// Autogenerated file by RAGen (v1.2.2.171), (04/14/2012 20:36)
// RA_041412_2036.ino
//
// This version designed for v0.9.0 or later
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#include <Salinity.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.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 = Port4Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port1Bit | Port2Bit | Port7Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
////// Place additional initialization code below here
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
////// Place additional initialization code above here
}
void loop()
{
// Specific functions that use Internal Memory values
ReefAngel.StandardLights(Port1,10,0,19,0);
ReefAngel.StandardLights(Port2,22,0,6,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
////// Place your custom code below here
if (hour() > 6 && hour() < 22)
{
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
}
else
{
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,80,240,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,80,180,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
////// Place your custom code above here
// This should always be the last line
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 1:59 pm
by rimai
I changed the function.
It should work now
Code: Select all
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 2:22 pm
by d0lph1n
Binary sketch size: 32,378 bytes (of a 32,256 byte maximum)
processing.app.debug.RunnerException: Sketch too big;
Re: Custom code, please help
Posted: Tue Apr 24, 2012 2:52 pm
by rimai
You must have more than those features shown on your code.
Those defines are just comments from the time the code was generated.
You must have enabled some other feature since then.
Make sure you only use those.
Re: Custom code, please help
Posted: Tue Apr 24, 2012 3:40 pm
by d0lph1n
I don't know what to do. This is all the code I have. RAgen features
wifi
date/setup
version
display ap/dp
font 8x8
this is the code i'm trying to upload:
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define SIMPLE_MENU
#define FONT_8x8
*/
#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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
ReefAngel.FeedingModePorts = Port4Bit;
ReefAngel.WaterChangePorts = Port3Bit | Port1Bit | Port2Bit | Port7Bit;
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
ReefAngel.LightsOnPorts = 0;
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
}
void loop()
{
ReefAngel.StandardLights(Port1,10,0,19,0);
ReefAngel.StandardLights(Port2,22,0,6,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
if (hour() > 6 && hour() < 22)
{
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
}
else
{
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,80,240,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,80,180,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
Serial.print(now());
Serial.print("-");
Serial.print(Start);
Serial.print("-");
Serial.print(StartD);
Serial.print("-");
Serial.print(StopD);
Serial.print("-");
Serial.println(End);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
return oldValue;
}
Binary sketch size: 33,622 bytes (of a 32,256 byte maximum)
Re: Custom code, please help
Posted: Tue Apr 24, 2012 3:52 pm
by rimai
remove the date/time and font8x8
Re: Custom code, please help
Posted: Tue Apr 24, 2012 3:52 pm
by rimai
and add simple menu
Re: Custom code, please help
Posted: Tue Apr 24, 2012 4:23 pm
by d0lph1n
1. I tried reloading my old code and it didn't work
2. I went to a dif laptop and tried to upload the old code ...it worked
3. I tried uploading the latest code from that laptop, it worked
4. I enabled web portal from ragen and tried to reload the code...failed...too big
5. disabled the web portal, save features..reload the code..same error...too big
The good news , your code is working..the PWMSlopeOvernight works
The bad news, I can't compile & upload the code..what to do?
..and 10.0.2.22:200/wifi page is generating massive flood of:
1335312804-1335304800-1335319200-1335319200-1335333600
1335312804-1335304800-1335315600-1335322800-1335333600
1335312804-1335304800-1335319200-1335319200-1335333600
1335312804-1335304800-1335315600-1335322800-1335333600
1335312804-1335304800-1335319200-1335319200-1335333600
1335312804-1335304800-1335315600-1335322800-1335333600
1335312804-1335304800-1335319200-1335319200-1335333600
1335312804-1335304800-1335315600-1335322800-1335333600
1335312804-1335304800-1335319200-1335319200-1335333600
Re: Custom code, please help
Posted: Tue Apr 24, 2012 4:47 pm
by rimai
Sorry... My bad... I left stuff in the code that wasn't supposed to be there.
It was my debugging code

Remove these lines:
Serial.print(now());
Serial.print("-");
Serial.print(Start);
Serial.print("-");
Serial.print(StartD);
Serial.print("-");
Serial.print(StopD);
Serial.print("-");
Serial.println(End);
To get the code to compile, open RAGen.
Go to features tab
Make sure you only have these checked:
Wifi
Watchdog Timer
Simple Menu
Version Menu
Display LED PWM
Click the save button
Now upload your code.
Re: Custom code, please help
Posted: Sun May 06, 2012 6:16 am
by d0lph1n
Sorry, I didn't see your last reply.
Meantime, I bought a proper router. I'll check again the wifi module in the next few days. Thanks
Re: Custom code, please help
Posted: Wed May 09, 2012 3:28 pm
by d0lph1n
I've fixed the wifi, I was able to connect the wifi module online, it takes ip, I fwd the port...but when i access either the internal IP:2000 or the external ip:2000 I get a blank page.
What am I doing wrong?
Thanks
Re: Custom code, please help
Posted: Wed May 09, 2012 4:44 pm
by rimai
Does it work when you load the wifi test code?
File->Sketchbook->Example Codes->WifiTestCode
Re: Custom code, please help
Posted: Wed May 09, 2012 4:44 pm
by binder
d0lph1n wrote:I've fixed the wifi, I was able to connect the wifi module online, it takes ip, I fwd the port...but when i access either the internal IP:2000 or the external ip:2000 I get a blank page.
What am I doing wrong?
Thanks
Does the page just say "Reef Angel Web Server"? If so, that's correct. To get your data, you need IP:2000/wifi
Re: Custom code, please help
Posted: Wed May 09, 2012 5:11 pm
by d0lph1n
I reloaded the code and it works now.
The iPhone app displays the correct values, there external IP too.
But the web portal shows zero values (Check my signature)
What am I missing here?
Re: Custom code, please help
Posted: Wed May 09, 2012 5:23 pm
by rimai
Good.
You need to add the Portal() function to your code now.
Re: Custom code, please help
Posted: Wed May 09, 2012 5:48 pm
by d0lph1n
Great. Thanks. It's working.
Re: Custom code, please help
Posted: Thu May 10, 2012 8:58 am
by d0lph1n
is it possible to display the pwm values and labels on the local interface ip:2000/wifi?
Re: Custom code, please help
Posted: Thu May 10, 2012 9:03 am
by binder
d0lph1n wrote:is it possible to display the pwm values and labels on the local interface ip:2000/wifi?
No, it's not currently possible. It could be done but that page hasn't been updated for a while. Roberto would have to update it on the server to change it.
Re: Custom code, please help
Posted: Thu May 10, 2012 9:11 am
by d0lph1n
I didn't know it's running code from the reefangel site:
<script language='javascript' src='
http://www.reefangel.com/wifi/ra1.js'></script>
K. I'll be waiting for Roberto to update it. Thanks
Re: Custom code, please help
Posted: Thu May 10, 2012 9:11 am
by rimai
It's in my list to do

I want to make it the same as the portal page
Re: Custom code, please help
Posted: Sat Jul 28, 2012 1:28 pm
by d0lph1n
hey Roberto,
What's the default Actinic/Daylight PWM value outside the PWMSlop schedule or how can i set it the default value to zero. Thank you
Re: Custom code, please help
Posted: Sat Jul 28, 2012 1:30 pm
by rimai
The last parameter on the PWMSlope defines the returned value for outside the slope schedule.
Simply set it to 0.
Re: Custom code, please help
Posted: Sat Jul 28, 2012 1:32 pm
by d0lph1n
Great. This is how it's setup right now. I just wanted to make sure. Thanks