Custom code, please help

Do you have a question on how to do something.
Ask in here.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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));
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

The slope can't cross over to next day :(
What is that you are trying to achieve?
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

I'm trying to have different settings between 10pm and 6am next day, for both drivers.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

But, is the PWM supposed to be at 80% overnight?
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post 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;
}
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Thanks Roberto. I'll test it tonight.
Image
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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;
}
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post 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;
}
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Binary sketch size: 32,378 bytes (of a 32,256 byte maximum)
processing.app.debug.RunnerException: Sketch too big;
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post 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.
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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)
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

remove the date/time and font8x8
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

and add simple menu
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post 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.
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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
Image
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Does it work when you load the wifi test code?
File->Sketchbook->Example Codes->WifiTestCode
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Custom code, please help

Post 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
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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?
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

Good.
You need to add the Portal() function to your code now.

Code: Select all

ReefAngel.Portal("d0lph1n");
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Great. Thanks. It's working.
Image
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

is it possible to display the pwm values and labels on the local interface ip:2000/wifi?
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Custom code, please help

Post 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.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

It's in my list to do :)
I want to make it the same as the portal page
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post 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
Last edited by d0lph1n on Sat Jul 28, 2012 1:31 pm, edited 1 time in total.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Custom code, please help

Post by rimai »

The last parameter on the PWMSlope defines the returned value for outside the slope schedule.
Simply set it to 0.
Roberto.
d0lph1n
Posts: 121
Joined: Tue Dec 06, 2011 10:16 am

Re: Custom code, please help

Post by d0lph1n »

Great. This is how it's setup right now. I just wanted to make sure. Thanks
Image
Post Reply