* fix NTP issues #1440 #1497 #1499
This commit is contained in:
lumapu 2024-03-17 00:42:58 +01:00
parent 6af07f5a33
commit 4fc61dc01f
6 changed files with 33 additions and 34 deletions

View file

@ -59,7 +59,7 @@ void app::setup() {
#endif // ETHERNET
#if !defined(ETHERNET)
mWifi.setup(mConfig, &mTimestamp, std::bind(&app::onNetwork, this, std::placeholders::_1));
mWifi.setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
#if !defined(AP_ONLY)
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
#endif
@ -135,7 +135,6 @@ void app::setup() {
});
#endif /*ENABLE_SIMULATOR*/
esp_task_wdt_reset();
regularTickers();
}
@ -164,7 +163,7 @@ void app::loop(void) {
//-----------------------------------------------------------------------------
void app::onNetwork(bool gotIp) {
DPRINTLN(DBG_DEBUG, F("onNetwork"));
DPRINTLN(DBG_INFO, F("onNetwork"));
mNetworkConnected = gotIp;
ah::Scheduler::resetTicker();
regularTickers(); //reinstall regular tickers
@ -205,11 +204,9 @@ void app::regularTickers(void) {
#endif /*ENABLE_SIMULATOR*/
}
#if defined(ETHERNET)
void app::onNtpUpdate(bool gotTime) {
mNtpReceived = true;
}
#endif /* defined(ETHERNET) */
//-----------------------------------------------------------------------------
void app::updateNtp(void) {
@ -250,30 +247,30 @@ void app::updateNtp(void) {
//-----------------------------------------------------------------------------
void app::tickNtpUpdate(void) {
uint32_t nxtTrig = 5; // default: check again in 5 sec
bool isOK = false;
#if defined(ETHERNET)
if (!mNtpReceived)
mEth.updateNtpTime();
else {
mNtpReceived = false;
isOK = true;
}
#else
isOK = mWifi.getNtpTime();
if (!mNtpReceived)
mEth.updateNtpTime();
else
mNtpReceived = false;
#else
if (!mNtpReceived)
mWifi.updateNtpTime();
else
mNtpReceived = false;
#endif
if (isOK) {
this->updateNtp();
nxtTrig = mConfig->ntp.interval * 60; // check again in 12h
// immediately start communicating
if (mSendFirst) {
mSendFirst = false;
once(std::bind(&app::tickSend, this), 1, "senOn");
}
updateNtp();
nxtTrig = mConfig->ntp.interval * 60; // check again in 12h
mMqttReconnect = false;
// immediately start communicating
if (mSendFirst) {
mSendFirst = false;
once(std::bind(&app::tickSend, this), 1, "senOn");
}
mMqttReconnect = false;
once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp");
}
@ -561,10 +558,7 @@ void app::resetSystem(void) {
mSaveReboot = false;
mNetworkConnected = false;
#if defined(ETHERNET)
mNtpReceived = false;
#endif
}
//-----------------------------------------------------------------------------