Solar Calculator

Arduino library to support calculation of sunrise / sunset times

See SystemClock NTP for example usage.

This is straight port of the code used by https://www.esrl.noaa.gov/gmd/grad/solcalc/

Javascript reference: https://www.esrl.noaa.gov/gmd/grad/solcalc/main.js

API Documentation

class SolarCalculator

Calculation of apparent time of sunrise and sunset.

Note: Months are 1-based

Unnamed Group

int sunRiseSet(bool isRise, int y, int m, int d)

a sunrise or sunset figure for a given day.

Parameters
  • isRise – true for sunrise, false for sunset

  • y – Absolute year

  • m – Month number (1 - 12)

  • d – Day of month (1 - 31)

Returns

int – Minutes since midnight, -1 if there is no sunrise/sunset

Public Functions

inline SolarCalculator()

Default constructor, uses Royal Observatory, Greenwich as default.

inline SolarCalculator(const SolarRef &ref)

Perform calculations using the given solar reference.

inline const SolarRef &getRef() const

Get the current location reference in use.

inline void setRef(const SolarRef &ref)

Set the location reference for calculations.

struct SolarRef

A location is required to compute solar times.

References

Used by

SoC support

  • esp32

  • esp32c3

  • esp32s2

  • esp32s3

  • esp8266

  • host

  • rp2040