ThingPulse / esp8266-weather-station

ESP8266 Weather Station library supporting OpenWeatherMap, Aeris and other sources
MIT License
1.06k stars 359 forks source link

The weather station shows a wrong moon phase #200

Closed ZioJames closed 2 years ago

ZioJames commented 2 years ago

Expected behavior

The moon phase and age shown on the display should be consistent with actual lunar calendar.

Actual behavior

I live near Florence, Italy: all regional settings has been edited accordingly. Today, October 4th, according to moongiant.com website (and my calendar too!) the moon is still waning, with an illumination of about 5% and an age of 27.53 days. The weather station, on the contrary, already shows a new moon with illumination of 3% (that's almost right) and an age of 0.4 days. I understand that a certain degree of approximation is unavoidable, but there seems to be an annoying two-day advance in calculation of moon age. The new moon will in fact be the 6th of October. The date and time shown on the display are correct.

Weather Station version

2.0.1 (latest)

Hardware

Nodemcu ESP8266 Lolin v3 esp-12e Evaluation Board

marcelstoer commented 2 years ago

Which demo sketch are you using?

ZioJames commented 2 years ago

Hi Marcel, thanks for your reply. Demo? What do you mean?

marcelstoer commented 2 years ago

I'm simply wondering what your sketch is and whether you use the simple Astronomy class or the more elaborate SunMoonCalc class. There are examples for both: https://github.com/ThingPulse/esp8266-weather-station/blob/master/examples/AstronomyDemo/AstronomyDemo.ino, https://github.com/ThingPulse/esp8266-weather-station/blob/master/examples/SunMoonCalcDemo/SunMoonCalcDemo.ino

ZioJames commented 2 years ago

Okay, it's clear now. My sketch is based on Astronomyclass. Just a copy & paste of the demo code:

Astronomy *astronomy = new Astronomy(); moonData = astronomy->calculateMoonData(now); moonData.phase = astronomy->calculateMoonPhase(now); delete astronomy; astronomy = nullptr;

Then moonData.illumination and moonData.phase are used to estimate the moon age:

float lunarMonth = 29.53; gfx.drawString(235, 276, String(moonData.phase <= 4 ? lunarMonth * moonData.illumination / 2.0 : lunarMonth - moonData.illumination * lunarMonth / 2.0, 1) + "d");

The divergence seems to be more accentuated at the very beginning of lunar cycle (New Moon). Today October 18th, at almost half cycle, code returns Waxing Gibbous moon, with 97% illumination and 14,4 days age, which is pretty much exact. "Real" values are very close: 96% and 12,76 days age.

A better approximation (i.e. 29.53059...) of lunar month duration should not have any effect... right? Many thanks in advance for your suggestions.

marcelstoer commented 2 years ago

Maybe try the SunMoonCalc class instead as it's more elaborate. However, as disclosed in that class and in https://github.com/ThingPulse/esp8266-weather-station/blob/master/src/Astronomy.cpp all of those algorithms are not ours. We only ported existing code to Arduino/ESP8266. However, I just realized some links to the original sources are now void. Maybe we should replace them with Archive links like these https://web.archive.org/web/20210429120530/https://www.voidware.com/moon_phase.htm.

A better approximation (i.e. 29.53059...) of lunar month duration should not have any effect... right?

I don't think that's what you really meant 😜 It should have an effect - more accurate results - otherwise improving it would be pointless, no?

Feel free to propose changes if you can confirm that they yield more accurate results, thanks.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.