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

ETH NTP update bugfix #1385

Merged
merged 1 commit into from
Jan 22, 2024
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
29 changes: 18 additions & 11 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void app::onNetwork(bool gotIp) {
mMqttReconnect = true;
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
//tickNtpUpdate();
#if !defined(ETHERNET)
if (WIFI_AP == WiFi.getMode()) {
mMqttEnabled = false;
Expand Down Expand Up @@ -206,12 +205,7 @@ void app::regularTickers(void) {

#if defined(ETHERNET)
void app::onNtpUpdate(bool gotTime) {
uint32_t nxtTrig = 5; // default: check again in 5 sec
if (gotTime || mTimestamp != 0) {
this->updateNtp();
nxtTrig = gotTime ? 43200 : 60; // depending on NTP update success check again in 12 h or in 1 min
}
once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp");
mNtpReceived = true;
}
#endif /* defined(ETHERNET) */

Expand Down Expand Up @@ -255,13 +249,22 @@ void app::updateNtp(void) {
//-----------------------------------------------------------------------------
void app::tickNtpUpdate(void) {
uint32_t nxtTrig = 5; // default: check again in 5 sec
bool isOK = false;

#if defined(ETHERNET)
bool isOK = (mTimestamp != 0);
mEth.updateNtpTime();
if (!mNtpReceived)
{
mEth.updateNtpTime();
}
else
{
mNtpReceived = false;
isOK = true;
}
#else
bool isOK = mWifi.getNtpTime();
isOK = mWifi.getNtpTime();
#endif
if (isOK || mTimestamp != 0) {
if (isOK) {
this->updateNtp();

nxtTrig = isOK ? (mConfig->ntp.interval * 60) : 60; // depending on NTP update success check again in 12h (depends on setting) or in 1 min
Expand Down Expand Up @@ -565,6 +568,10 @@ void app::resetSystem(void) {
mSaveReboot = false;

mNetworkConnected = false;

#if defined(ETHERNET)
mNtpReceived = false;
#endif
}

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ class app : public IApp, public ah::Scheduler {
void tickNtpUpdate(void);
#if defined(ETHERNET)
void onNtpUpdate(bool gotTime);
bool mNtpReceived;
#endif /* defined(ETHERNET) */
void updateNtp(void);

Expand Down