Closed tytoalba99 closed 2 years ago
Can you give me some testable code and tell me which release?
sun.setPosition(LATITUDE, LONGITUDE, TIMEZONE);
sun.setCurrentDate(time.year(),time.month(), time.day());
// If you have daylight savings time, make sure you set the timezone appropriately as well
sun.setTZOffset(TIMEZONE);
double sunrise = sun.calcSunrise();
double sunset = sun.calcSunset();
int moonphase = sun.moonPhase();
String salidasol = String(int(sunrise/60))+":"+twoDigits(fmod(sunrise,60));
String puestasol = String(int(sunset/60))+":"+twoDigits(fmod(sunset,60));
int minutoactual = (time.hour()*60 + time.minute());
Serial.print("Sunrise at ");
Serial.print(salidasol);
Serial.print(", Sunset at ");
Serial.print(puestasol);
Serial.print(" Luna: ");
Serial.print(moonphase);
Serial.print(" minuto Actual: ");
Serial.println(minutoactual);
Serial.println("\n");
Current version 1.1.6
OK, this really isn't a bug, but it is confusing. The time on your system is empty, so time_t == 0
which the calculation cannot manage, and that causes the return value to be incorrect. This is a good error code though and I'll add it to the docs. Because the moonphase uses the current time, you will need to make sure
time_t t = std::time(0);
can return a positive real value. You can also set the value you want std::time
to return by calling moonphase(int epoch) with a positive value. Note, this calculation cannot work for times before the Unix epoch, and not 0 either, it's not that sophisticated.
Solved
int moonphase = sun.moonPhase(time.unixtime());
thank you.
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