sfrwmaker / sunmoon Goto Github PK
View Code? Open in Web Editor NEWarduino library to calculate moon day and sunrise and sunset times
Home Page: https://www.hackster.io/sfrwmaker/sun-and-moon-times-cd1629
License: GNU General Public License v3.0
arduino library to calculate moon day and sunrise and sunset times
Home Page: https://www.hackster.io/sfrwmaker/sun-and-moon-times-cd1629
License: GNU General Public License v3.0
Hello,
this is no issue, but i didn´t know how to ask for help otherwise:
can you give me an example how to read out the sunrise and sunset values in variables like hour minutes and seconds ?
This library would be perfect, but i don´t unterstand it completely.
thank you very much
Picposter
Not sure if this is an issue with the code or with the example code but daylight savings time changes would be a problem for the code as in the example. Does one just execute the init inside the loop after identifying the correct offset or is there a method to adjust for DST before executing the sunRise and sunSet calls?
#include <sunMoon.h>
#include <Time.h>
#include <TimeLib.h>
#define OUR_latitude 22.5726723 // Moscow cordinates
#define OUR_longtitude 88.3638815
#define OUR_timezone 330 // localtime with UTC difference in minutes
sunMoon sm;
void setup() {
tmElements_t tm; // specific time
tm.Second = 0;
tm.Minute = 12;
tm.Hour = 12;
tm.Day = 2;
tm.Month = 2;
tm.Year = 2021 - 1970;
time_t s_date = makeTime(tm);
Serial.begin(9600);
sm.init(OUR_timezone, OUR_latitude, OUR_longtitude);
time_t sRise = sm.sunRise(s_date);
time_t sSet = sm.sunSet(s_date);
Serial.print("Specific date sunrise and sunset was: ");
printDate(sRise); Serial.print("; ");
printDate(sSet); Serial.println("");
}
void loop() {
// put your main code here, to run repeatedly:
}
void printDate(time_t date) {
char buff[20];
// sprintf(buff, "%2d-%02d-%4d %02d:%02d:%02d",
// day(date), month(date), year(date), hour(date), minute(date), second(date));
sprintf(buff, "%02d:%02d:%02d",
hour(date), minute(date), second(date));
Serial.print(buff);
}
for
Kolkata, West Bengal, 700 073, India
Latitude: 22.5726723
Longitude: 88.3638815
Time zone: 330 (5:30)
According to https://sunrise-sunset.org/search?location=kolkata
Sunrise time:
6:14:56 AM
Sunset time:
5:25:34 PM
Getting Output
Specific date sunrise and sunset was: 06:15:36; 17:25:13
Any help will be `appreciated
Line 78 in sunMoon.cpp should be:
int N3 = 1 + (year(date) - 4 * (year(date) / 4) + 2) / 3;
not:
int N3 = 1 + (year(date) - 4 * (year(date)) / 4 + 2) / 3;
Greetings, I'd like to note that the Timezone validation limits the difference from UTC to 720 minutes, I'm currently at 780, and some folks are even further from UTC than I am.
Hi, I need to use ezTime lib instead of TimeLib. I modified the sunMoon.h header:
`#ifndef _SUN_MOON_H
#define _SUN_MOON_H
#include <ezTime.h>
#include <math.h>
class sunMoon {
`
and supposed that it will work. But I got some strange compilation error which seems not to be related to this change, but somehow is:
In file included from D:\arduino\projects\libraries\ezTime\src/ezTime.h:41:0,
from D:\arduino\projects\libraries\sunMoon-master\src\sunMoon.h:4,
from D:\arduino\projects\libraries\sunMoon-master\src\sunMoon.cpp:1:
C:\Users\Dell\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/sdk/libc/xtensa-lx106-elf/include/sys/types.h:122:18: error: conflicting declaration 'typedef long int time_t'
typedef TIME_T time_t;
^
In file included from D:\arduino\projects\libraries\sunMoon-master\src\sunMoon.h:4:0,
from D:\arduino\projects\libraries\sunMoon-master\src\sunMoon.cpp:1:
D:\arduino\projects\libraries\ezTime\src/ezTime.h:36:24: error: 'time_t' has a previous declaration as 'typedef long unsigned int time_t'
typedef unsigned long time_t;
^
It has something to do with the time_t declaration, but I don't do anything with it.
The full test code is here:
`#include <Arduino.h>
//#include <TimeLib.h>
#include <ezTime.h>
#include <sunMoon.h>
#define OUR_latitude 49.4
#define OUR_longtitude 18.2
#define OUR_timezone 120 // localtime with UTC difference in minutes
sunMoon sm;
void printDate(time_t date) {
char buff[20];
sprintf(buff, "%2d-%02d-%4d %02d:%02d:%02d", day(date), month(date), year(date), hour(date), minute(date), second(date));
Serial.print(buff);
}
void setup() {
tmElements_t tm; // specific time
tm.Second = 0;
tm.Minute = 0;
tm.Hour = 12;
tm.Day = 26;
tm.Month = 4;
tm.Year = 2021 - 1970;
time_t s_date = makeTime(tm);
Serial.begin(115200);
Serial.println();
sm.init(OUR_timezone, OUR_latitude, OUR_longtitude);
uint32_t jDay = sm.julianDay(s_date); // Optional call
byte mDay = sm.moonDay(s_date);
time_t sRise = sm.sunRise(s_date);
time_t sSet = sm.sunSet(s_date);
Serial.print("Today is "); Serial.print(jDay); Serial.println(" Julian day");
Serial.print("Moon age is "); Serial.print(mDay); Serial.println("day(s)");
Serial.print("Today sunrise and sunset: ");
printDate(sRise); Serial.print("; ");
printDate(sSet); Serial.println("");
}
void loop() {
// put your main code here, to run repeatedly:
}
`
Please be so kind and help me to find the root cause.
Greetings, this light weight library is working great for me, I wanted to ask how I can go about adding a couple of decimals, specifically to the moon age, so I can use it for more a more accurate moon phase calculation, I couldn't figure it out in the code..
Not sure if this is by design or not but when the time passes the time of the calculated sunset, calls to sunrise and sunset return the next day's rise and set. Shouldn't the calls stick to the current day's sunrise and sunset until 24:59:59 (midnight)?
This is reproducible if you have your RTC set to UTC time and provide the sm.init call your offset and long and latitude. I've even validated that providing a t_time value to the sunRise() and sunSet() calls for a past date/time gives me tomorrow's sunrise and sunset. I'm using a -240 min offset with the init.
Dear Sfrwmaker,
I hereby request that you make a description of your good algorithms for this SunMoon module you have made. I am in doubt what the float t parameter is doing, and how it shall be formatted, (I assume that it is a time parameter - however - I do not understand if it is supposed to be a Julian time, a hour/minute/second time, a full year/month/day/hour/minute/second time, or a Unix time - or seconds-since-epoch, and so on. So it would be wonderful with some examples for us mortals :-)
If you can explain it to me, just by a line or two, then I wouldn't mind updating the software nicely, make good comments, update the example etc.
Let me know. My email is [email protected], and I respond typically within 24 hours.
Sincerely
David Svarrer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.