Skip to content

Commit

Permalink
0.8.95
Browse files Browse the repository at this point in the history
* fix NTP issues #1440 #1497 #1499
  • Loading branch information
lumapu committed Mar 16, 2024
1 parent 6af07f5 commit 4fc61dc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Development Changes

## 0.8.95 - 2024-03-17
* fix NTP issues #1440 #1497 #1499

## 0.8.94 - 2024-03-16
* switched AsyncWebServer library
* Ethernet version now uses same AsyncWebServer library as Wifi version
Expand Down
48 changes: 21 additions & 27 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,7 +135,6 @@ void app::setup() {
});
#endif /*ENABLE_SIMULATOR*/


esp_task_wdt_reset();
regularTickers();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -561,10 +558,7 @@ void app::resetSystem(void) {
mSaveReboot = false;

mNetworkConnected = false;

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

//-----------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class app : public IApp, public ah::Scheduler {
#if defined(ETHERNET)
mEth.updateNtpTime();
#else /* defined(ETHERNET) */
mWifi.getNtpTime();
mWifi.updateNtpTime();
#endif /* defined(ETHERNET) */
}
else
Expand Down Expand Up @@ -389,10 +389,8 @@ class app : public IApp, public ah::Scheduler {
}

void tickNtpUpdate(void);
#if defined(ETHERNET)
void onNtpUpdate(bool gotTime);
bool mNtpReceived = false;
#endif /* defined(ETHERNET) */
void updateNtp(void);

void triggerTickSend() override {
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 94
#define VERSION_PATCH 95

//-------------------------------------
typedef struct {
Expand Down
6 changes: 4 additions & 2 deletions src/wifi/ahoywifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ ahoywifi::ahoywifi() : mApIp(192, 168, 4, 1) {}
*/

//-----------------------------------------------------------------------------
void ahoywifi::setup(settings_t *config, uint32_t *utcTimestamp, appWifiCb cb) {
void ahoywifi::setup(settings_t *config, uint32_t *utcTimestamp, appWifiCb cb, OnTimeCB onTimeCb) {
mConfig = config;
mUtcTimestamp = utcTimestamp;
mAppWifiCb = cb;
mOnTimeCb = onTimeCb;

mGotDisconnect = false;
mStaConn = DISCONNECTED;
Expand Down Expand Up @@ -275,7 +276,7 @@ void ahoywifi::setupStation(void) {


//-----------------------------------------------------------------------------
bool ahoywifi::getNtpTime(void) {
bool ahoywifi::updateNtpTime(void) {
if(IN_STA_MODE != mStaConn)
return false;

Expand All @@ -302,6 +303,7 @@ bool ahoywifi::getNtpTime(void) {

*mUtcTimestamp = secsSince1900 - 2208988800UL; // UTC time
DPRINTLN(DBG_INFO, "[NTP]: " + ah::getDateTimeStr(*mUtcTimestamp) + " UTC");
mOnTimeCb(true);
return true;
} else
delay(10);
Expand Down
6 changes: 4 additions & 2 deletions src/wifi/ahoywifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class app;
class ahoywifi {
public:
typedef std::function<void(bool)> appWifiCb;
typedef std::function<void(bool)> OnTimeCB;

ahoywifi();


void setup(settings_t *config, uint32_t *utcTimestamp, appWifiCb cb);
void setup(settings_t *config, uint32_t *utcTimestamp, appWifiCb cb, OnTimeCB onTimeCB);
void tickWifiLoop(void);
bool getNtpTime(void);
bool updateNtpTime(void);
void scanAvailNetworks(void);
bool getAvailNetworks(JsonObject obj);
void setStopApAllowedMode(bool allowed) {
Expand Down Expand Up @@ -74,6 +75,7 @@ class ahoywifi {

settings_t *mConfig = nullptr;
appWifiCb mAppWifiCb;
OnTimeCB mOnTimeCb;

DNSServer mDns;
IPAddress mApIp;
Expand Down

0 comments on commit 4fc61dc

Please sign in to comment.