Sunlocation?

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Sunlocation?

Post by cosmith71 »

Can someone explain a basic implementation of sunlocation?

Thanks,

--Colin
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

Here is the excerpt from my code that references SunLocation. I think it's pretty self explanatory. One thing to keep in mind is that if sun.UseMemory==true, which is the default, then it will write the Daylight on/off times each day.

$ egrep -i 'SunLocation|sun\.' Wizard65.ino

Code: Select all

#include <SunLocation.h>
SunLocation sun;
  sun.Init(InternalMemory.read_int(Mem_I_Latitude), InternalMemory.read_int(Mem_I_Longitude));
  sun.SetOffset(riseOffset,(acclDay*acclRiseOffset),setOffset,(-acclDay*acclSetOffset)); // Bahamas
  sun.CheckAndUpdate(); // Calculate today's Sunrise / Sunset
  tide.SetSpeed(PWMSlope(sun.GetRiseHour()-1,sun.GetRiseMinute(),
    sun.GetSetHour(),sun.GetSetMinute(),nightSpeed+tideMin,vtSpeed,120,nightSpeed+tideMin));
  } else if (!sun.IsDaytime() && nightRF) {
    if (sun.IsDaytime() && (now()+offset)%repeat==0) {
  sprintf(buf, "%02d:%02d", sun.GetRiseHour(), sun.GetRiseMinute());
  sprintf(buf, "%02d:%02d", sun.GetSetHour(), sun.GetSetMinute()); x+=36;
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sunlocation?

Post by cosmith71 »

Thanks, Lee, but I was looking for something more basic. You have a lot going on there!

--Colin
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

No, I don't. There's just a few examples.

The required ones are the include, the declaration, the init and the checkandupdate. The offset is optional, and the rest shows how I'm using it. If you don't do anything you can jsut declare a port StandardLights or use an LED function and it will use the rise/set to start/end whichever lighting you use.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

Colin you declare it and then you init it with the gps coordinates. Then you run CheckAndUpdate in your loop and each night it will refresh the sunrise and sunset times. You can then use those times in any function which I gave examples for. You can use SetOffset to adjust where you are and tune your viewing time. There are other functions to see if it's daytime or not and you can get the actual time_t (unsigned long) value for rise and set if you wanted to compare against now(). The default is to also set the memory for daylights so if you use memory for StandardLights() or if you use like Channel0PWMSlope() then it will get the sunrise and sunset from memory.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sunlocation?

Post by cosmith71 »

OK, that helps immensely. Thanks!
User avatar
CaliFSU
Posts: 11
Joined: Fri Mar 18, 2016 7:49 am

Re: Sunlocation?

Post by CaliFSU »

This may be a little off topic but I just implemented SunLocation to my lighting schedule and is there a post that has an explanation of the slopes? And also what is the difference between the high res slopes and the regular slopes?
>>--Cali-->
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Sunlocation?

Post by cosmith71 »

2016-04-13.png
2016-04-13.png (15.89 KiB) Viewed 7593 times
HighRes returns values from 0 to 4095 (raw 12 bit values) and the regular returns values from 0 to 100 (as in percents).

--Colin
User avatar
CaliFSU
Posts: 11
Joined: Fri Mar 18, 2016 7:49 am

Re: Sunlocation?

Post by CaliFSU »

My lights don't appear to play well with the "standard" modes, they only appear to respond with the HighRes variations. Not sure if it matters, but I am connecting my lights to the external dimming expansion on analog channels.

Also, I cannot seem to get my lights to come on/off automatically from the SunLocation::StdLightsOnOff_write() function in the SunLocation.cpp file. What would I need to configure to get this going?


--UPDATE--
Silly error on my part calling the PWMParabolaHighRes function. I accidentally reversed the hours/minutes variables. :roll:
Last edited by CaliFSU on Fri Apr 15, 2016 6:42 am, edited 2 times in total.
>>--Cali-->
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

Can you post your code?

You should see the on/off time in The portal under Internal Memory. It would be in the first tab. Please confirm what times you have there and make sure to post your code.
User avatar
madweazl
Posts: 44
Joined: Tue Dec 03, 2013 3:08 am
Location: Fredericksburg, VA

Re: Sunlocation?

Post by madweazl »

Where are the sunrise/sunset times coming from? I see GPS mentioned but don't understand where the information is being pulled from in the code.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

When you run the Init function you set the coordinates. If you don't specify it will use GBR coordinates by default
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

I think you have to set the GPS through the Init function.

There is a "Constructor" function for the SunLocation class, but I think the way we use it, it's never called.

Typically in C++ you use pointers and a constructor to do the following:

Code: Select all

SunLocation *sl = new SunLocation();
Notice the * that means we're pointing to a location in memory and the new function returns the memory address of a newly created SunLocation class. Since we're a bit more basic, we never actually run a constructor when you do this:

Code: Select all

SunLocation sl;
So with that you'd have to run the Init in order to set the coordinates. I may modify the class to have an Init() with no args so you can use the defaults.

For the record the code is in Libraries/SunLocation and you can see in SunLocation.cpp the first two functions, the first being the constructor I mentioned and the second being the Init function.
User avatar
madweazl
Posts: 44
Joined: Tue Dec 03, 2013 3:08 am
Location: Fredericksburg, VA

Re: Sunlocation?

Post by madweazl »

lnevo wrote:When you run the Init function you set the coordinates. If you don't specify it will use GBR coordinates by default
I see reference to Great Barrier Reef in there but nothing else; is that just a reference? I dont have any issues using that lat/long, I was just curious. I'm not even going to try and make sense out of the moon library yet; that one left me googly eyed.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

Yeah I'd say for now it only works as a reference :) but yes feel free to use those with the Init function with those values.
User avatar
madweazl
Posts: 44
Joined: Tue Dec 03, 2013 3:08 am
Location: Fredericksburg, VA

Re: Sunlocation?

Post by madweazl »

lnevo wrote:Here is the excerpt from my code that references SunLocation. I think it's pretty self explanatory. One thing to keep in mind is that if sun.UseMemory==true, which is the default, then it will write the Daylight on/off times each day.

$ egrep -i 'SunLocation|sun\.' Wizard65.ino

Code: Select all

#include <SunLocation.h>
SunLocation sun;
  sun.Init(InternalMemory.read_int(Mem_I_Latitude), InternalMemory.read_int(Mem_I_Longitude));
  sun.SetOffset(riseOffset,(acclDay*acclRiseOffset),setOffset,(-acclDay*acclSetOffset)); // Bahamas
  sun.CheckAndUpdate(); // Calculate today's Sunrise / Sunset
  tide.SetSpeed(PWMSlope(sun.GetRiseHour()-1,sun.GetRiseMinute(),
    sun.GetSetHour(),sun.GetSetMinute(),nightSpeed+tideMin,vtSpeed,120,nightSpeed+tideMin));
  } else if (!sun.IsDaytime() && nightRF) {
    if (sun.IsDaytime() && (now()+offset)%repeat==0) {
  sprintf(buf, "%02d:%02d", sun.GetRiseHour(), sun.GetRiseMinute());
  sprintf(buf, "%02d:%02d", sun.GetSetHour(), sun.GetSetMinute()); x+=36;
I'd like to get this going but my lights dont dim to 0 (SBReef basic black boxes) so I use relays 5 and 6 for on/off functionality. Is there a way to tie that in so the relay and rise/set functions work together?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

Yes, what I do is if my dim % is >= the percent they go off, the. i turn the relay on. Otherwise they are off.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Sunlocation?

Post by lnevo »

The other thing you can do is set the start and end percentage to be when your lights go off. This way you get the full photoperiod.
Post Reply