GithubHelp home page GithubHelp logo

risacher / sunwait Goto Github PK

View Code? Open in Web Editor NEW
164.0 13.0 38.0 153 KB

Sunwait calculates sunrise or sunset times with civil, nautical, astronomical and custom twilights, for use with Windows Task Scheduler or 'cron' on Linux.

License: GNU General Public License v3.0

Makefile 2.48% C 97.52%

sunwait's Introduction

sunwait

Sunwait calculates sunrise or sunset times with civil, nautical, astronomical and custom twilights.

It is intended for use in home automation with Windows Task Scheduler or cron. Use it to turn lights on before it gets dark! The program can wait from invocation until the event specified on the command line occurs or it can return immediately indicating if it is day or night. It's best to schedule Sunwait to run a little before the earliest opportunity for the event to occur each year - ie dusk range is 3:30pm to 10:30pm here, so it reasonable to schedule a dusk task at 3pm and allow Sunwait to pause the task for between 30mins and 7 and a half hours. If you scheduled the task for 6pm, then your lights will come on no earlier than 6pm.

The sun's position is calculated using time, and position - latitude and longitude should be specified on the command line.

Features:

  • Calculates sunrise and sunset for given coordinates
  • Can wait for sunrise/sunset, or return DAY or NIGHT codes
  • Works with Windows Task Scheduler (or cron)
  • Supports custom twilight angles
  • Used to automate domestic lighting with Arduino transmitter and radio controlled sockets

History:

This project is a "reclaimed fork". I (Dan Risacher) wrote the original version around 2000, and maintained it until 2004. In 2013, Ian Craig made a version that compiled cleanly on Windows and added some useful features. In 2019, I'm moving it to GitHub as a better collaborative development platform. If you have feature requests or issues, please report them here.

sunwait's People

Contributors

ahorn42 avatar allanlaal avatar ckuethe avatar danieldjewell avatar kadorken avatar lbdroid avatar linuxkidd avatar risacher 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  avatar  avatar  avatar

sunwait's Issues

Typo

Hi,
there is a little typo in the error message for wrong parameter.

./sunwait -typo
Error: Unknown command-line argument: typpo

Thx for sunwait.

Negative longitude reported as E instead of W.

sunriset.c
Has:
/* Note: Eastern longitude positive, Western longitude negative */

I changed sunwait.h to my location:
//#define DEFAULT_LATITUDE 52.952308
//#define DEFAULT_LONGITUDE 359.048052 /* The Buttercross, Bingham, England /
#define DEFAULT_LATITUDE 40.767218
#define DEFAULT_LONGITUDE -111.902899 /
Salt Lake City, Utah */

It looks like the times are right, but is says E instead of W.
I am not sure what is setting the E or W in the code.

# ./sunwait report

  Current Date and Time: 15-Jun-2019 21:23 MDT

Target Information ...

               Location:  40.767218N, -111.902899E
                   Date: 15-Jun-2019
               Timezone: MDT

Sun directly north/south: 13:27
Twilight angle: -0.83 degrees (daylight)
Day with twilight: 05:54 to 21:01
It is: Night

OpenBSD

Initial attempt to compile with make in OpenBSD resulted in compilation error.
Changing the abs() function to fabs() at line 95 of sunriset.cpp seemed to fix that.
Program now runs but returns error(1) as far as I can see as the output is always the following:-

--:--, --:-- (Midnight sun)

My coding skills are beyond fixing this.

Sunwait usage question

Hi,
I browsed around through the internet about how to use sunwait with cron.
I followed one of the source and make the sunwait as well as cp the made sunwait into usr/local/bin

  1. The sunwait -p seem no longer work?
  2. The sunwait report [latitude] [longitude] is woking.

In case of I want to edit the crontab as below for everyday at 5AM, wait until astronomical twilight begin, then stop my overnight running system via http, the crontab should be as below?

00 05 * * * /usr/local/bin/sunwait wait astronomical rise [latitude] [longitude] ; curl -X POST http://<ip>/api/stop

Please advise.
Thank you very much.

Wait reduced for no apparent reason

Hi! I think the idea of this program is really nice and I would like to use it to control lights outside of the house. Time for sunrise and sunset are being correctly calculated for my location.
Unfortunately, when using example stated in the documentation it doesn't work as I expect it.
I expect program to terminate 30 min prior sunset. For some reason it terminates after 10 sec.
Below is a debug printout. Last line in debug printout is a mystery to me. Why "wait" is being reduced!?
I'm running "latest" version that I fetched and built about a week ago. Running on RPi3.

pi@pismart:~ $ sunwait wait debug set offset -00:30:00 <My Latitude> <My Longitude>
Debug: argv[1]: >wait<
Debug: argv[2]: >debug<
Debug: argv[3]: >set<
Debug: argv[4]: >offset<
Debug: argv[6]: >XXXXXXXXXX<
Debug: argv[7]: >XXXXXXXXXX<
Debug: All output to use local timezone (nogmt).
Debug: Now utcTm: Mon Apr 22 11:09:26 2019 GMT
Debug: Now localTm: Mon Apr 22 13:09:26 2019 CEST
Debug: Now UTC bias (add to GMT to get CEST) hours: 2.000000
Debug: UTC Bias (hours): 2.000000
Debug: Now: Days since 2000: 7051
Debug: Target year set to: 119
Debug: Target mon set to: 3
Debug: Target mday set to: 22
Debug: Target utcTm: Mon Apr 22 00:00:00 2019 GMT
Debug: Target localTm: Mon Apr 22 02:00:00 2019 CEST
Debug: Target UTC bias (add to GMT to get CEST) hours: 2.000000
Debug: Target: Days since 2000: 7051
Debug: Co-ordinates - Latitude: XXXXXXXXX
Debug: Co-ordinates - Longitude: XXXXXXXXX
Debug: Twilight - Daylight
Debug: User specified offset (hours): -0.500000
Debug: Function selected: Wait
Debug: sunriset.cpp: Sun directly south: 10.940656 UTC, Dirunal Arc = 14.845321 hours
Debug: sunriset.cpp: Days since 2000: 7050
Debug: sunriset.cpp: Sun directly south: 10.937158 UTC, Dirunal Arc = 14.929036 hours
Debug: sunriset.cpp: Days since 2000: 7051
Debug: sunriset.cpp: Sun directly south: 10.933778 UTC, Dirunal Arc = 15.012551 hours
Debug: sunriset.cpp: Days since 2000: 7052
Debug: Wait reduced from 27880 to 10 seconds.
pi@pismart:~ $ echo $?
0

Solar Noon

Avro on Sourceforge asked for ability to trigger events at solar noon, which seems like a good thing. Presumably solar midnight too.

Warning when compiling sunwait.cpp and sunriset.cpp

I just compiled the sunwait package and got some warnings.

make[2]: Entering directory '/home/pi/allsky/src/sunwait-src'
gcc -c -Wall  sunwait.cpp -o sunwait.o
sunwait.cpp: In function ‘int main(int, char**)’:
sunwait.cpp:665:62: warning: value computed is not used [-Wunused-value]
     if (arg[0] == '-' && arg[1] != '\0' && !isdigit(arg[1])) *arg++;
                                                              ^~~~~~
gcc -c -Wall  sunriset.cpp -o sunriset.o
sunriset.cpp: In function ‘void sun_RA_dec(double, double*, double*, double*)’:
sunriset.cpp:151:18: warning: variable ‘zs’ set but not used [-Wunused-but-set-variable]
   double xs, ys, zs;
                  ^~

Can these be fixed so end users don't see them? They won't know what to do when they see the messages.
Thanks

MacOS

I am building sunwait on my Mac. Everything builds (albeit with a couple of minor warnings), but sunwait returns odd times that change every time I run the command. Can you help me figure out what libraries or build flags need to be changed to get sunwait to build correctly on a Mac?

Syntax error in sunwait.cpp

Hi, thanks for this very useful piece of code that I've used for some time.
I've just cloned it onto my new Raspberry Pi and tried to run "make", and it fails in compilation in sunwait.cpp at lines 707 on, where the if statement has incorrect bracketing. I think it should be:

else if   (!strcmp (arg, "debug")           ||
              !strcmp (arg, "--debug")      ||
              !strcmp (arg, "--verbose")    ||
              !strcmp (arg, "-v"))           pRun->debug = ONOFF_ON;

If I trusted my C++ and git skills more, I'd send a pull request.

day off by one?

Donald Fore says:

Hi Dan,

I think your "day" calculation is 1 day off.
' compensated for it in a quick little script using day+1.

Very nice program!

Investigate this

Sunwait in poll mode returns 512 or 768

First, sunwait is a very handy program and thanks for all your work.

I am running sunwait on a Raspberry Pi, using C/C++ code developed with the Code::Blocks IDE.

I installed sunwait using snap as described here https://snapcraft.io/install/sunwait/raspbian. The version I got is "Sunwait for Windows. Version 0.800000 (IFC)." A little odd that is says "Windows".

I use the system() command to run sunwait with an appropriate command string

#define TEMP_STR_LENGTH 15
char    latitudeStr[TEMP_STR_LENGTH];
char    longitudeStr[TEMP_STR_LENGTH];
int     sunAngle;
#define CMD_STR_LEN 100
#define DAY_RETURN_CODE 512  // should be 2
#define NIGHT_RETURN_CODE 768 // should be 3

char commandString[CMD_STR_LEN];
int  systemResult;

sprintf(latitudeStr,"43.68608N");
sprintf(longitudeStr,"87.95198W");
sunAngle = -6;
sprintf(commandString,"sunwait %s %s poll",latitudeStr,longitudeStr);
systemResult = system(commandString);
printf("Resultcode is: %d\n",systemResult);

The command that is executed is

  sunwait 43.68608N 87.95198W poll

The return codes for DAY and NIGHT are 512 and 768, not 2 and 3 as described in the documentation. So the 2 and 3 are in the 2nd least significant byte of the result.

Am I doing something wrong? Or is it that the snap installer sort of compiles for Windows and that has different return codes than expected in Linux?

TIA

Publish a release?

Hi,

Just wanted to drop a line and ask for a tagged release. The reason being that for packages to be accepted on Void Linux it needs to be tied to a release.

Would greatly appreciate a release for sunwait because at the current state the package on Void is 2 years old missing things like the poll option and can't be updated.

I've built it manually and use it as such - really great old project 👍

Issue with latitude impacting report and list values

42.319167N, 3.321944E is peninsular Spain's easternmost location.

Please, note Location values displayed by sunwait 87.000000N, 3.321944E While longitude is ok, latitude seems to have been converted almost to a latitude in the North Pole, which is why it showing It is night or no daylight when actually it is Day. Also, there are no values for daylight, nautical or astronomical twilight but there are for civil twilight.

user@machine:~$ sunwait report d 08 m 03 y 23 42.319167N, 3.321944E

      Current Date and Time: 08-Mar-2023 12:50 CET


Target Information ...

                   Location:  87.000000N,   3.321944E
                       Date: 08-Mar-2023
                   Timezone: CET
   Sun directly north/south: 12:57
             Twilight angle: -0.83 degrees (daylight)
          Day with twilight: --:-- to --:-- (Polar night)
                      It is: Night

General Information (no offset) ...

 Times ...         Daylight: --:-- to --:-- (Polar night)
        with Civil twilight: 06:15 to 19:39
     with Nautical twilight: --:-- to --:-- (Midnight sun)
 with Astronomical twilight: --:-- to --:-- (Midnight sun)

 Duration ...    Day length: 00:00 hours
        with civil twilight: 13:23 hours
     with nautical twilight: 24:00 hours
 with astronomical twilight: 24:00 hours

y [YYYY] Set the target Year to calculate for. 2000 to 2099.
but

user@machine:~$ sunwait report d 08 m 03 y 2023 42.319167N, 3.321944E
Error: "Year" must be between 0 and 99: 2023

that is why I entered y 23

Should input values differently? Compilation went flawless (Debian 11 Bullseye)

Thank you for sunwait!

Re-Merge with 7-Year-Old Fork?

Hello Mr. Risacher, and welcome back!

Back in 2015, someone forked your project on Github here: https://github.com/klada/sunwait

Since this new maintainer was more responsive at the time, I submitted to him my DST bug fix from 2018. I also recommended a change of upstream to the maintainers of Macports: https://trac.macports.org/ticket/57657

I suppose we should compare the best changes across both repos and settle on an authoritative maintainer again?

If that's you, we should tell the Macports people again.

Thanks!

Time changes - British Summer Time etc

Short: How can I make sunwait wait take into account time changes, if it does not already?

Explanation:
In Estonia on 30th of October sunset is at 17:52. Also, in Estonia 3am becomes 2am on 31st of October 2021. So on 31st of October sunset is at 16:49 - note the time jumped about an hour.
However, when I run: sunwait list 2 d 30 m 10 y 21 58.252106N 22.489471E
I get 17:49 (not 16:49) for sunset time on 31st of October.

Now I have set up a Scheduled Task in Windows 10 that will fire sunwait wait set 58.252106N 22.489471E.
Given Windows adjusts daylight saving time automatically, will sunwait wait exit at the correct time of 16:49 on 31st of October or will it exit at the incorrect time an hour too late at 17:49? (

If it exits at the wrong time, is there any way to get a scheduled task to do its thing at the correct time throughout the year?

Negative days does not work

Checking for today and tomorrow works (sunwait list 2 58.31N 15.13) but yesterday does not (sunwait list -1 58.31N 15.13E) is it a bug or do I not know how to use it?

Question: sunwait version history

Do you have access to a sunwait version history? do you know which version added the poll function?

I made a small utility with a sunwait poll dependency. Some linux distributions like Fedora are shipping older versions of sunwait without this function. I'd like to be able to tell users they need sunwait -v > ???

Thanks in advance!

Show version

A way to display the current version from the CLI would be really useful to check whether the latest version has been installed on a device. The usual way is an arg of -v or -V

Western Hemisphere, Not By Default

On CentOS 7, the compiler strips the negative sign (-77 degrees) from the define directive DEFAULT_LONGITUDE (sunwait.h), eliminating the possibility of referencing the western hemisphere by default. It probably happens for the southern hemisphere. Furthermore, the large positive version (282 degrees) is converted into the eastern equivalent of the small angle. I have a work around for this bug.

I replaced DEFAULT_LONGITUDE in the two uses with the negative decimal angle, allowing 'sunwait report' to run accurately without feeding the coordinates every time. This work around doesn't seem to have an effect on other functionality.

I like sunwait. I'll use it to feed dunst and i3blocks with fun information.

Thanks :-)

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.