An open API service indexing awesome lists of open source software.

https://github.com/celliesprojects/moonphase-esp32

An ESP32 library to get the moon phase angle and visible percentage of the moon that is illuminated.
https://github.com/celliesprojects/moonphase-esp32

arduino-ide esp32-arduino lunar-phase moon moon-phase moon-phase-angle

Last synced: 5 months ago
JSON representation

An ESP32 library to get the moon phase angle and visible percentage of the moon that is illuminated.

Awesome Lists containing this project

README

          

### MoonPhase

A library for esp32 to get the moon phase angle and amount of the moon that is illuminated. (as seen from Earth)

For esp8266 non-os or avr (Arduino) you can use the [steve-sienk fork](https://github.com/steve-sienk/moonPhaser-avr).

### Breaking changes upgrading from 1.x to 2.0

The include path changed from `#include ` to `#include "MoonPhase.hpp"`

The class name changed from `moonPhase` to `MoonPhase`

Struct member names were clarified:

`angle` → `angleDeg`

`percentLit` → `amountLit`

| Before (v1.x) | After (v2.0) |
| ----------------------- | ---------------------- |
| `moonPhase` | `MoonPhase` |
| `moonData_t.angle` | `moonData_t.angleDeg` |
| `moonData_t.percentLit` | `moonData_t.amountLit` |

The library now compiles cleanly with `-Wall` and `-Werror` enabled.

### Add to PlatformIO project

```c++
lib_deps = celliesprojects/moonPhase-esp32@^2.0.0
```

#### Functions

- `getPhase()` Get the current moon phase.
First set freeRTOS system time - see the example below.

- `getPhase(time_t t)` Get the moon phase from time `t`.

#### Example code

```c++
#include
#include
#include

const char *wifissid = "network name";
const char *wifipsk = "network password";

MoonPhase moonPhase;

struct tm timeinfo{};

void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println("moonPhase esp32-sntp example.");
Serial.print("Connecting to ");
Serial.println(wifissid);
WiFi.begin(wifissid, wifipsk);
while (!WiFi.isConnected())
delay(10);
Serial.println();

Serial.println("Connected. Syncing NTP...");

// find your local timezone string at
// https://remotemonitoringsystems.ca/time-zone-abbreviations.php

// timezone: Amsterdam, Netherlands
const char timeZone[]{"CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"};

const char countryCode[]{"nl"};

char ntpPool[64];
snprintf(ntpPool, sizeof(ntpPool), "%s.pool.ntp.org", countryCode);

configTzTime(timeZone, ntpPool);

while (!getLocalTime(&timeinfo, 0))
delay(10);
}

void loop()
{
getLocalTime(&timeinfo);
Serial.print(asctime(&timeinfo));

moonData_t moon = moonPhase.getPhase();

Serial.print("Moon phase angle: ");
Serial.print(moon.angleDeg); // angleDeg is a integer between 0-360
Serial.println("° (Where 0° is new moon and 180° is full moon)");

Serial.print("Illuminated: ");
Serial.print(moon.amountLit * 100); // amountlit is a real between 0-1
Serial.println("% as seen from Earth");
Serial.println();
delay(1000);
}
```