|
|
@ -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"); |
|
|
|
} |
|
|
|
|
|
|
|
mMqttReconnect = false; |
|
|
|
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"); |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|