sunMoon icon indicating copy to clipboard operation
sunMoon copied to clipboard

Wrong Result

Open Prabindas001 opened this issue 4 years ago • 2 comments

#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

Prabindas001 avatar Feb 02 '21 17:02 Prabindas001

Perhaps, the coordinates are wrong. https://en.wikipedia.org/wiki/All_India_Institute_of_Hygiene_and_Public_Health 22.5761885°N 88.3586926°E

sfrwmaker avatar Feb 03 '21 18:02 sfrwmaker

The exact times depend on a lot of things. A common definition is when the sun is 10 arc-minutes below the horizon. This is what this library calculates. But the sun is not a single point that is above or below the horizon. It appears as a disc and the sun appears even larger near the horizon. Height above sealevel makes also a difference. It takes about two minutes from the first light until you can see the whole disc. So when is the exact time? I think it doesn't really make sense to tell it to the exact second. I found a german page that even considers the temperature: https://www.arndt-bruenner.de/scripts/sonnenaufunduntergaenge.htm Btw. if you use the API: https://api.sunrise-sunset.org/json?lat=22.5726723&lng=88.3638815&date=2021-02-02 you get a different value...

ulegan avatar Feb 16 '21 21:02 ulegan