Browse Source

0.8.95

* fix NTP issues #1440 #1497 #1499
pull/1512/head
lumapu 10 months ago
parent
commit
4fc61dc01f
  1. 3
      src/CHANGES.md
  2. 26
      src/app.cpp
  3. 4
      src/app.h
  4. 2
      src/defines.h
  5. 6
      src/wifi/ahoywifi.cpp
  6. 6
      src/wifi/ahoywifi.h

3
src/CHANGES.md

@ -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

26
src/app.cpp

@ -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,20 +247,20 @@ 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 {
else
mNtpReceived = false;
isOK = true;
}
#else
isOK = mWifi.getNtpTime();
if (!mNtpReceived)
mWifi.updateNtpTime();
else
mNtpReceived = false;
#endif
if (isOK) {
this->updateNtp();
updateNtp();
nxtTrig = mConfig->ntp.interval * 60; // check again in 12h
// immediately start communicating
@ -273,7 +270,7 @@ void app::tickNtpUpdate(void) {
}
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
}
//-----------------------------------------------------------------------------

4
src/app.h

@ -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
@ -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 {

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 94
#define VERSION_PATCH 95
//-------------------------------------
typedef struct {

6
src/wifi/ahoywifi.cpp

@ -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;
@ -275,7 +276,7 @@ void ahoywifi::setupStation(void) {
//-----------------------------------------------------------------------------
bool ahoywifi::getNtpTime(void) {
bool ahoywifi::updateNtpTime(void) {
if(IN_STA_MODE != mStaConn)
return false;
@ -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);

6
src/wifi/ahoywifi.h

@ -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) {
@ -74,6 +75,7 @@ class ahoywifi {
settings_t *mConfig = nullptr;
appWifiCb mAppWifiCb;
OnTimeCB mOnTimeCb;
DNSServer mDns;
IPAddress mApIp;

Loading…
Cancel
Save