diff --git a/include/globals.h b/include/globals.h index 890e93cc..daff28ea 100644 --- a/include/globals.h +++ b/include/globals.h @@ -4,6 +4,10 @@ // The mother of all embedded development... #include +// Time functions +#include +#include + // std::set for unified array functions #include #include @@ -102,6 +106,7 @@ extern std::array::iterator it; extern std::array beacons; extern TaskHandle_t irqHandlerTask, wifiSwitchTask; +extern Timezone myTZ; // make Timezone myTZ globally available // application includes #include "led.h" diff --git a/include/gpsread.h b/include/gpsread.h index f98e4d62..affde231 100644 --- a/include/gpsread.h +++ b/include/gpsread.h @@ -2,7 +2,6 @@ #define _GPSREAD_H #include // library for parsing NMEA data -#include #ifdef GPS_I2C // Needed for reading from I2C Bus #include diff --git a/include/lorawan.h b/include/lorawan.h index 2bd1b55b..05aba7cd 100644 --- a/include/lorawan.h +++ b/include/lorawan.h @@ -3,7 +3,6 @@ #include "globals.h" #include "rcommand.h" -#include // LMIC-Arduino LoRaWAN Stack #include diff --git a/include/rtctime.h b/include/rtctime.h index e308ec20..d47ae19c 100644 --- a/include/rtctime.h +++ b/include/rtctime.h @@ -2,8 +2,6 @@ #define _RTCTIME_H #include "globals.h" -#include -#include #include // must be included here so that Arduino library object file references work #include @@ -20,7 +18,6 @@ typedef enum { } clock_state_t; extern RtcDS3231 Rtc; // make RTC instance globally available -extern Timezone myTZ; // make Timezone myTZ globally available int rtc_init(void); int set_rtctime(uint32_t UTCTime); diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 4a1c2599..dc9fe12f 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -132,10 +132,10 @@ void do_timesync() { #ifdef HAS_RTC if (!set_rtctime(RtcDateTime(now()))) ESP_LOGE(TAG, "RTC set time failure"); +#endif time_t tt = myTZ.toLocal(now()); ESP_LOGI(TAG, "GPS has set system time to %02d/%02d/%d %02d:%02d:%02d", month(tt), day(tt), year(tt), hour(tt), minute(tt), second(tt)); -#endif return; } else { ESP_LOGI(TAG, "No valid GPS time"); diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 31827bbc..dcf8e3a4 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -458,9 +458,9 @@ void user_request_network_time_callback(void *pVoidUserUTCTime, #ifdef HAS_RTC if (!set_rtctime(*pUserUTCTime)) ESP_LOGE(TAG, "RTC set time failure"); +#endif time_t t = myTZ.toLocal(now()); ESP_LOGI(TAG, "LORA Network has set system time to %02d/%02d/%d %02d:%02d:%02d", month(t), day(t), year(t), hour(t), minute(t), second(t)); -#endif } diff --git a/src/main.cpp b/src/main.cpp index 57350e70..c671f4d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,6 +77,11 @@ std::set, Mallocator> macs; // initialize payload encoder PayloadConvert payload(PAYLOAD_BUFFER_SIZE); +// set Time Zone, fetch user setting from paxcounter.conf +TimeChangeRule myDST = DAYLIGHT_TIME; +TimeChangeRule mySTD = STANDARD_TIME; +Timezone myTZ(myDST, mySTD); + // local Tag for logging static const char TAG[] = "main"; diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 4262b25e..d0a7b403 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -7,11 +7,6 @@ static const char TAG[] = "main"; RtcDS3231 Rtc(Wire); // RTC hardware i2c interface -// set Time Zone, fetch user setting from paxcounter.conf -TimeChangeRule myDST = DAYLIGHT_TIME; -TimeChangeRule mySTD = STANDARD_TIME; -Timezone myTZ(myDST, mySTD); - // initialize RTC int rtc_init(void) {