Giter VIP home page Giter VIP logo

sunset's Introduction

Peter Buelow

BeachBall

About this image

I can't take credit, this was randomly taken by my 6 year old daughter at her grandma's pool. I just love the color and lighting. It's a crop of a close up of what may be a 10 yeaar old bbeach ball. It was in the shed when my parents bought their house. My daughter was playing with our little water proof camera and captured this. She was copying her dad by just taking a lof pictures of little random stuff around the backyard.

About Me

I have been working with Linux and embedded electronics for nearly 25 years now. Starting in college, where I got my first pass at programming 8 bit micros and talking to them over slow UART on my super advanced Slackware 3.6 installation running on a Gateway2000 486 with 8MB of RAM (I upgraded). I remember how hard it was to get even simple things working, but what a learning experience. Fast forward to today, when I get to run an 8 core laptop with more RAM than my entire dorm had in all computers combined. Now Linux makes life easy, and I'm much better at using it.

Fast forward a few years, and I was a lucky young engineer at what used to be Motorola, working on learning how to integrate Linux into cellular network controllers. It was me and a few friends in suburban Chicago who got a first pass at brining MontaVista Linux into a Freescale PPC cage, and make it work. Then we got to integrate with WindRiver, making Linux and VxWorks function together in the same cage. Motorola also got me my first introduction to DD-WRT and consumer grade networking. I was priveledged to be a lead engineer helping on a project for what was a precursor to 4G. Motorola bet big on WiMAX, which was not smart in hindsight, but we created a really cool WiMAX home router which was deployed in Germany and Pakistan for a while.

I got to work at Continental AG, building their first Linux based products for a while. There is a lot of Linux in cars as it stands.

And most recently, I got to help create a Linux platform for Lifefitness. All of the consoles they build now are Linux and Android based. It was my team that dreamed up HOW to do that, and then work out the details. I loved that work, and being at the front line of doing something great for people, making it work for Lifefitness in a smart and cost effective way, was a dream come true.

I have a lot of projects here which let me keep track of a lot of things around my house. I can automatically refill my fishtank and monitor a lot of sensors related to keeping fish alive. I maintain a weather station in my backyard. I control a LOT of lights around the house (FastLED and Hue), and I dream big about what's next. Ideally, that would be a robot bartender, but honestly, I don't have the space right now. I need a new bar I guess!

sunset's People

Contributors

buelowp avatar chegancasb avatar glichy avatar ivankravets avatar jbuelop avatar nliviu avatar programminghoch10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sunset's Issues

Moonphase test is failing

The test SunsetTesting.MoonphaseNoArgs fails right now, and I don't know why. This should be resolved.

 RUN      ] SunsetTesting.MoonphaseNoArgs
/home/pete/Projects/sunset/test/sunset_tests.cpp:369: Failure
Expected equality of these values:
  sun.moonPhase()
    Which is: 8
  4
Returned: 8, epoch is 1579097467

Incorrect Sample Longitude in readme.md

Hi,

The example longitude to readme.md is:
"#define LONGITUDE 89.0000"
I believe this is incorrect as it would be for a location in China. If the longitude is correct, then it conflicts with the time zone of -5.
I believe the longitude value should be:
"#define LONGITUDE -89.0000"

Incorrect Instructions in Details Section of readme.md

Hi,

Section five of details section in readme.md states:
"... returns a double that indicates how many seconds past midnight relative to the set date ..."
I believe this should read " ... how many minutes past midnight ..."

Problem input date

I application in the date sun.setCurrentDate (2018, 12, 17);
but returned the following date in the sunrise and sunset function
sunrise 1-01-1970 00:06:27;
sunset 1-01-1970 00:19:15

License mistake

The README states

This is a modification of the sunrise.c posted by Mike Chirico back in 2004.

but at the same time

This is governed by the MIT license. Use it as you want, make changes as you want.

Whereas Mike's original code is under GPLv2 (check out this archive), which says, among other things:

You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.

meaning that the whole Sunset library together with C++ modifications must be distributed as GPL, so putting it out as MIT is a mistake.

It would be cool if that could be corrected. Without a valid license, it's impossible to know under what terms this code can be distributed, making it effectively useless outside of personal projects.

Arduino incompatibility, fix suggestion

Hi,
Thanks for the great library
I just tried to compile this inside a PlatformIO Arduino project, and I got a compilation error because Arduino redefines min and max macros

Adding this fixes the problem. I wonder if you would like to add it to the repo, or maybe there is a better way to do it

#undef min
#undef max

#include <math.h>
#include <time.h>
#include <chrono>

Wrong Results for Rome

I have wrong UTC values (and conseguently localtimes) for Italy - Rome with this sample code:

// Rome Coord
#define CUR_LAT 41.89193
#define CUR_LON 12.51133

#define TIMEZONE_DEC 1
#define TIMEZONE_JUN 2

int getHoursFromVal(int minutes) {
return (int) (minutes / 60);
}

int getMinutesFromVal(int minutes) {
return minutes - (getHoursFromVal(minutes) * 60);
}

void printCalculation(double lat, double lon, int tz, int year, int month, int day) {
SunSet s;
s.setCurrentDate(year, month, day);
s.setPosition(lat, lon, tz);
double sunriseUTC = s.calcSunriseUTC();
double sunsetUTC = s.calcSunsetUTC();
std::cout << "###################### "<< std::endl;
std::cout << "Latitude:" << lat << " | Longitude:" << lon << " | Year:" << year << " | Month:" << month << " | Day:" << day << " | Tz:" << tz << std::endl ;
std::cout << "Sunrise UTC Val: " << sunriseUTC << " (" << getHoursFromVal(sunriseUTC) << ":" << getMinutesFromVal(sunriseUTC) << " past midnight)" << std::endl;
std::cout << "Sunset UTC Val: " << sunsetUTC << " (" << getHoursFromVal(sunsetUTC) << ":" << getMinutesFromVal(sunsetUTC) << " past midnight)" << std::endl;
std::cout << std::endl;
}

int main() {
double lat = CUR_LAT;
double lon = CUR_LON;
int year = 2018;
int month = 6;
int day = 1;
int tz = TIMEZONE_JUN;
printCalculation(lat, lon, tz, year, month, day);
month = 12;
tz = TIMEZONE_DEC;
printCalculation(lat, lon, tz, year, month, day);
}

##################################
Console output
##################################

######################
Latitude:41 | Longitude:12 | Year:2018 | Month:6 | Day:1 | Tz:2
Sunrise UTC Val: 318.25 (5:18 past midnight) // Wrong! -> Attended: 3:18 -> utc+2=5:18
Sunset UTC Val: 1213.81 (20:13 past midnight) // Wrong! -> Attended: 18:13 -> utc+2=20:13

######################
Latitude:41 | Longitude:12 | Year:2018 | Month:12 | Day:1 | Tz:1
Sunrise UTC Val: 473.311 (7:53 past midnight) // Wrong! -> Attended utc 5:53 -> utc+1=6:53
Sunset UTC Val: 1040.49 (17:20 past midnight) // Wrong! -> Attended utc 15:20 -> utc+1= 16:20

It seems that UTC have a 2 hours offset, what i'm doing wrong?

Member functions that should be const aren't

Almost all functions of this library are purely computational thus, can be marked const.

I think only these functions need to be non-const:

    void setPosition(double, double, int);
    void setPosition(double, double, double);
    void setTZOffset(int);
    void setTZOffset(double);
    double setCurrentDate(int, int, int);

This allows to preserve const correctness of client code.

This is related to Con.2 from CppCoreGuidelines.
Also you might consider adding noexcept F.6 from CppCoreGuidelines

Expose `calcAbsSunset` style interface, so custom offsets can be used

I need to adjust the offset for sunrise/sunset calculation to match the one used in existing hardware.
calcAbsSunset can't be exposed directly, as it doesn't take into account timezone offset.

I'm proposing to add calcCustomSunset and calcCustomSunrise that would take offset as an argument and calculate appropriate time accounting for timezone offset. then all existing functions could be modified to only call the new interface with appropriate constant.

check for NaN in calcHourAngleSunset/-Sunrise

Hello,
great work your library.
On my location around 21st of June the lib gives no proper values for astronomical sunrise/sunset. Reason is that the hour Angle goes near Pi, so that the result of acos(...) results in NaN.
Adding
if(std::isnan(HA)) HA = M_PI;
in both functions Solved the problem for me.

Kind regards
Stephan

Can't use on Mega or Uno

It would be awesome if this library was compatible with the"core" arduino boards such as th Mega and the Uno.

Mistake in Readme

double sunsetUTC = sun.calcSunriseUTC();

Should be sun.calcSunrsetUTC();

Wrong times, problem with TZ and TzOffset

Hello,

Somehow i cannot get the library to display correct values for my location in Austria.
Austria is normally UTC+1 during winter and UTC+2 (DST of 1h) between end of March and end of October.
No matter what I enter as Timezone (1 or 2) the smallest difference to the actuall sunset time according to the internet is at least 1h and 4mins.

My Date and Time that i feed the library are from an RTC and are correct and precise.
Project runs on an ESP32 and programmed via VsCode (Platform IO).

Here is my code:

#include <RTClib.h>
#include <sunset.h>

#define TIMEZONE 2
#define LATITUDE 48.330
#define LONGITUDE 14.300

SunSet sun; 

void setup() {
  DateTime time = rtc.now(); 
  sun.setPosition(LONGITUDE,LATITUDE,TIMEZONE);
  sun.setCurrentDate(time.year(), time.month(), time.day()); 

  Serial.print("date: "); 
  Serial.print(time.day()); 
  Serial.print("."); 
  Serial.print(time.month()); 
  Serial.print("."); 
  Serial.println(time.year()); 
  Serial.print("Time: "); 
  Serial.print(time.hour()); 
  Serial.print(":"); 
  Serial.print(time.minute()); 
  Serial.print(":"); 
  Serial.println(time.second()); 
  Serial.println("__________________________________"); 

  int sunset = static_cast<int>(sun.calcSunset()); 
  Serial.print("Sunset: "); 
  Serial.println(sunset); 
  Serial.print("Sunset: "); 
  Serial.print(sunset/60); 
  Serial.print(":"); 
  Serial.println((sunset%60)); 
  Serial.println("__________________________________"); 

  sunset = static_cast<int>(sun.calcCivilSunset());
  Serial.print("Civil Sunset: "); 
  Serial.println(sunset); 
  Serial.print("Sunset: "); 
  Serial.print(sunset/60); 
  Serial.print(":"); 
  Serial.println((sunset%60));  
  Serial.println("__________________________________"); 

  sunset = static_cast<int>(sun.calcNauticalSunset());
  Serial.print("Nautical Sunset: "); 
  Serial.println(sunset); 
  Serial.print("Sunset: "); 
  Serial.print(sunset/60); 
  Serial.print(":"); 
  Serial.println((sunset%60));  
  Serial.println("__________________________________"); 

  sunset = static_cast<int>(sun.calcAstronomicalSunset());
  Serial.print("Astronomical Sunset: "); 
  Serial.println(sunset); 
  Serial.print("Sunset: "); 
  Serial.print(sunset/60); 
  Serial.print(":"); 
  Serial.print((sunset%60));  
}

Here the Output:

Date: 25.9.2022
Time: 13:32:2  
__________________________________
Sunset: 1000   
Sunset: 16:40
__________________________________
Civil Sunset: 1022
Sunset: 17:2
__________________________________
Nautical Sunset: 1046
Sunset: 17:26
__________________________________
Astronomical Sunset: 1071
Sunset: 17:51

The sunset for this location should be around 18:54 according to various internet sites. I don't mind a few minutes off but none of the calculated sunsets come even close.

Are the calculated values in my local time (UCT+2)?
What does setTzOffset() do? Is it intended for DST use?

Help is really appreciated!
Thank you!
Best regards,
watzi

Fix missing precision cast in calcJD

I hadn't noticed, but there is an implicit cast in calcJD from a float/double to an int. This will implement a static_cast to force it and avoid having the compiler guess.

This isn't an issue right now, but is being done for correctness.

Error compiling for board ESP32 Dev Module.

I'm in the process of writing a sketch that will automate my living room light timer so it recognizes: DST, Seasons and my Location. It looks like your library would do that. I used the library manager in my ARDUINO IDE to download the library and tried to run the example untouched to see if I had all the libraries needed. I couldn't get it to compile. It claims it doesn't like my ESP32 Dev Module selection. I tried enabling PSRAM.. no better. Any ideas?
These are the same board defs I have used successfully for all my other development on this board.

Here is a copy of the error listing. Have it on verbose. I'll try to attach it.

sunset.txt

Negative values for moonphase

hi,

I get negative values for moonphase. (i.e -6). Sunset and Sunrise calculations are OK.
Environment ESP8266 (Lolin D1 mini)

15:06:48.120 -> Sunrise at 5:44, Sunset at 20:50 moonphase: -6

Regards

SunSet::SunSet()

I can't seem get this to build on the Particle Web IDE - The cpp module appears to have multiple definitions for a number of items - e.g. SunSet::SunSet() seems to occur at least three times. Am I missing something or is that an upload error on the code? Thanks!

Add option to override cmake build settings via variables

Hi, thanks for making this library!

I want to integrate this library into embedded project as a git submodule. Unfortunately it's not possible because of this code in your CMakeLists.txt:

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_FLAGS -pthread)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")

-pthread appears to be not needed at all (probably it's required for gtest), also depending on target platform it might not be correct way to link pthread. For example see this stackoverflow question.
Also because you use set (CMAKE_CXX_FLAGS -pthread) instead of set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread)" it resets all previously set flags.

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic") in my opinion should also be optional - gated behind a flag. Maybe you should also consider using target_compile_options

add_library (${PROJECT_NAME} SHARED ${SOURCES}) - embedded platforms usually don't support shared libraries, while cmake ignores this and issues a warning this really should be configurable with a variable.

Remove dependency on ctime

There is only one function that uses ctime header - int moonPhase() const. In some applications (including mine) this header is unavailable or local time is not available (so the std::time is unavailable).

Since it's really only convenience wrapper it would be nice if it was possible to disable it with compile option.

Code quality issue in function calcGeomMeanLongSun?

Dear Buelowp,

thank you for providing this wonderful library, which I use in my flight navigation app https://github.com/Akaflieg-Freiburg/enroute. Using you code, my compiler warned about a unused result in the function calcGeomMeanLongSun:

double SunSet::calcGeomMeanLongSun(double t)
{
    if (std::isnan(t)) {
        return nan("");
    }
    double L = 280.46646 + t * (36000.76983 + 0.0003032 * t);

    std::fmod(L, 360.0);
  
    return L;              // in degrees
}

Is seems that the result of the call std::fmod(L, 360.0) is never used. I presume that you wish to change the value for L, correct?

Best wishes from Germany,

Stefan Kebekus.

Request for documentation -- help with specific use case

Dear Buelowp,

I was wondering if I use your library correctly. If you have a minute, could you please tell me how to use your library correctly for the following use case? Through trial and error, I have found a way to compute the following data, but I am unsure if my solution is actually correct.

I have the following data:

  • Current Time and Date in UTC
  • Coordinate of a geographic location on earth (might be north of the arctic circle)

I would like to compute the Time and Date (in UTC) of the next sunset or sunrise at the location, whatever comes earlier.

Best,

Stefan Kebekus.

Some latitudes can cause hangs

First found by trying to test the new functions with Alert, Nunavut, Canada (82.31, -62.18).
It kept causing it (NodeMCU 1.0, Arduino framework) to hang and be reset by the software watchdog.
Tried to disable the software watchdog to see what would happen, but it just causes the hardware watchdog to trigger the reset.
I then tested it with this (after going back to 1.0.11 and with a bigger change in lat first):

#include <Arduino.h>
#include <SunSet.h>

SunSet sun;
double sunrise;
double lat = 67.9; // 67.9 or -69.5

void setup()
{
  Serial.begin(115200);
  Serial.println();
}

void loop()
{
  Serial.printf("%f\t", lat);
  sun.setPosition(lat, 0, 0);
  sun.setCurrentDate(2020, 5, 26);
  sunrise = sun.calcSunrise();
  Serial.println(sunrise);
  lat += .01; // += or -=
}

After increasing then decreasing lat , this is what i got:

67.980000       6.99
67.990000       3.99
68.000000
Soft WDT reset
-69.570000      708.34
-69.580000      712.67
-69.590000      nan
-69.600000      nan
-69.610000      nan
-69.620000      nan
-69.630000      nan
-69.640000      nan
-69.650000      nan
-69.660000      nan
-69.670000
Soft WDT reset

I'm guessing it happens because those areas either have daylight throughout the day or none at all.
Is it possible to make it fail in a graceful way?

Publish latest version to Platformio package library

Hi

Would you be able to publish v1.1.6 to the platformio package library please? v1.1.3 is the latest in there so is a couple of versions behind:

buelowp/sunset
Library • 1.1.3 • Published on Thu May 28 10:41:38 2020
Allows calculation of sunrise, sunset, and moonphase. Calculates Sunrise and Sunset, along with the Civil, Nautical, and Astronomical times for Sunrise/Sunset. It can also tell you the moon phase for a given time.

Thank you!

Negative longitude

Hi,
thank you very much for this library.
If I can't use negative longitude, what do I have to use instead of -80 (for example)? +80? 360-80=280? other?
Thanks

Warn Windows users about filename collision

Windows filenames are case insensitive, so sunset.h and SunSet.h can't be present in the same folder.

When downloading and extracting the repo zip, it will ask to replace or rename one of them. (In my case, 7zip will extract SunSet.h first then ask to replace it with sunset.h or auto rename.)

GitHub Desktop seems to always end up with SunSet.h but with the contents of sunset.h when trying to clone the repo.

PlatformIO seems to end up with sunset.h but with the contents of SunSet.h. Including it in projects is also case insensitive. (Tried with SUnSeT.H and it compiled just fine for both the ESP8266 and the STM32F103.)

Civil, nautical and astronomical twilight?

Would it be possible to add them to this library?
My use case needs to know the time difference between sunset and them and i can't seem to find a library that has them.
I think it mainly needs functions similar to calcHourAngleSunrise and calcHourAngleSunset that use 96, 102 and 108 instead of 90.833 but i'm not completely sure about that.
Thank you.

convert result to a certain time

Hello i tried to use your code but the output is a double(like you shown in example), something like 356.582274
What this is mean? minutes from start of the day?
I need to convert the output into time, to make the program usefull.
Sorry maybe is a dumb question , but i am stuck here.

Ty


Ah yes i see now in your comments, need to convert that double - sorry

moonphase: UTC or local

Quick question on how to use the moonphase function:
Is the input parameter expected to be in UTC time or in the local time zone?
Thanks!

Remove unnecessary define statements

Since C++14 is required for this project these define statements

#define SUNSET_OFFICIAL         90.833
#define SUNSET_NAUTICAL         102
#define SUNSET_CIVIL            96
#define SUNSET_ASTONOMICAL      108

#define SUNSET_INVALID_TZ_D     99.9
#define SUNSET_INVALID_TZ_I     99

can easily be converted to static constexpr double inside the class body - removing the need for defines.
Also please consider adding documentation to them, as first 4 are quite clear to me, but I'm clueless what's the usage of the latter 2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.