Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NTP client build #28

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@
// Use OBSERVED_PLACE for no refraction.

// TIME AND LOCATION ---------------------------------------------- see https://onstep.groups.io/g/main/wiki/Configuration_Mount#TLS
#define TIME_LOCATION_SOURCE OFF // OFF, DS3231 (I2c,) DS3234 (Spi,) TEENSY (T3.2 internal,) or GPS source. Option
#define TIME_LOCATION_SOURCE OFF // OFF, DS3231 (I2c,) DS3234 (Spi,) TEENSY (T3.2 internal,), NTP or GPS source. Option
// Provides Date/Time, and if available, PPS & Lat/Long also.
// NTP source is only awailable for #SERIAL_IP_MODE = STATION and don't forget to
// configure NTP server address with #TIME_IP_ADDR
#define TIME_LOCATION_PPS_SENSE OFF // OFF, HIGH senses PPS (pulse per second,) signal rising edge, or use LOW for Option
// falling edge, or use BOTH for rising and falling edges.
// Better tracking accuracy especially for Mega2560's w/ceramic resonator.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/NTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void TimeLocationSource::get(JulianDate &ut1) {
hour() <= 23 && minute() <= 59 && second() <= 59) {
GregorianDate greg; greg.year = year(); greg.month = month(); greg.day = day();
ut1 = calendars.gregorianToJulianDay(greg);
ut1.hour = hour() + minute()/60.0 + second()/3600.0;
ut1.hour = hour() + minute()/60.0 + (second() + DUT1)/3600.0;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/lib/tls/NTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

#if defined(TIME_LOCATION_SOURCE) && TIME_LOCATION_SOURCE == NTP

#include <EthernetUdp.h>
#if OPERATIONAL_MODE == WIFI
#include <WiFiUdp.h>
#else
#include <Ethernet.h>
#endif
#include "../calendars/Calendars.h"

class TimeLocationSource {
Expand All @@ -31,6 +35,9 @@ class TimeLocationSource {
// update from NTP
void poll();

// for conversion from UTC to UT1
double DUT1 = 0.0L;

private:
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address);
Expand Down
32 changes: 32 additions & 0 deletions src/telescope/mount/site/Site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,33 @@ IRAM_ATTR void clockTickWrapper() { fracLAST++; }
}
#endif

#if TIME_LOCATION_SOURCE == NTP
void ntpCheck() {
if (tls.isReady()) {
VLF("MSG: Mount, setting date/time from NTP");
JulianDate jd;
tls.get(jd);
site.dateIsReady = true;
site.timeIsReady = true;
site.setDateTime(jd);
#if GOTO_FEATURE == ON
if (park.state == PS_PARKED) park.restore(false);
#endif

VLF("MSG: Mount, stopping NTP monitor task");
tasks.setDurationComplete(tasks.getHandleByName("ntpChk"));
} else

if ((long)(millis() - site.updateTimeoutTime) > 0) {
VLF("MSG: Mount, NTP timed out stopping monitor task");
tasks.setDurationComplete(tasks.getHandleByName("ntpChk"));
VLF("WRN: TLS, NTP timed out stopping monitor task");
tasks.setDurationComplete(tasks.getHandleByName("ntp"));
initError.tls = true;
}
}
#endif

void Site::init() {
// get location
VLF("MSG: Mount, site get Latitude/Longitude from NV");
Expand All @@ -82,6 +109,11 @@ void Site::init() {
VF("MSG: Transform, start GPS check task (rate 5000ms priority 7)... ");
if (tasks.add(5000, 0, true, 7, gpsCheck, "gpsChk")) { VLF("success"); } else { VLF("FAILED!"); }
#endif
#if TIME_LOCATION_SOURCE == NTP
updateTimeoutTime = millis() + NTP_TIMEOUT_SECONDS*1000UL;
VF("MSG: Transform, start NTP check task (rate 5000ms priority 7)... ");
if (tasks.add(5000, 0, true, 7, ntpCheck, "ntpChk")) { VLF("success"); } else { VLF("FAILED!"); }
#endif
}
} else {
DLF("WRN: Site::init(), Warning TLS initialization failed");
Expand Down