timekeeper fixes

This commit is contained in:
Klaus K Wilting committed 2019-02-24 15:08:41 +01:00
1 parent a676658977
commit c20ef02ce8
7 files changed
+28 -20

No files matched your search

+2 -2
View File
@@ -46,7 +46,7 @@ const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
uint8_t DisplayState = 0;
char timeSource = '?';
timesource_t timeSource = _unsynced;
// helper function, prints a hex key on display
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) {
@@ -217,7 +217,7 @@ void refreshtheDisplay() {
u8x8.printf("%-16s", display_line6);
#else // we want a systime display instead LoRa status
t = myTZ.toLocal(now());
timeState = TimePulseTick ? ' ' : timeSource;
timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource];
TimePulseTick = false;
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
timeState, day(t), printmonth[month(t)]);
+3 -2
View File
@@ -361,10 +361,11 @@ void setup() {
ESP_LOGI(TAG, "Starting Timekeeper...");
assert(timepulse_init()); // setup timepulse
timepulse_start();
time_sync(); // sync time
#ifdef TIME_SYNC_INTERVAL
setSyncInterval(TIME_SYNC_INTERVAL * 60); // controls timeStatus()
setSyncInterval(TIME_SYNC_INTERVAL * 60); // controls timeStatus() via Time.h
setSyncProvider(syncProvider_CB); // is called by Time.h
#endif
time_sync(); // sync time
// start wifi in monitor mode and start channel rotation timer
ESP_LOGI(TAG, "Starting Wifi...");
+2 -2
View File
@@ -66,8 +66,8 @@
#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds]
// settings for syncing time of node with external time source
#define TIME_SYNC_INTERVAL 2 // sync time attempt each .. minutes from time source (GPS/LORA), comment out means [default = 5]
#define TIME_SYNC_LORA 1 // use LORA network as time source, comment out means off [default = off]
#define TIME_SYNC_INTERVAL 60 // sync time attempt each .. minutes from time source (GPS/LORA) [default = 60], comment out means off
//#define TIME_SYNC_LORA 1 // use LORA network as time source, comment out means off [default = off]
// time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino
#define DAYLIGHT_TIME {"CEST", Last, Sun, Mar, 2, 120} // Central European Summer Time
+16 -11
View File
@@ -3,6 +3,9 @@
// Local logging tag
static const char TAG[] = "main";
// symbol to display current time source
const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
void time_sync() {
// synchonization of systime with external time source (GPS/LORA)
// frequently called from cyclic.cpp
@@ -31,20 +34,16 @@ void time_sync() {
#endif // TIME_SYNC_INTERVAL
} // time_sync()
// helper function to sync time on start of next second
uint8_t syncTime(time_t const t, uint8_t const caller) {
// symbol to display current time source
const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
// sync time on start of next second
uint8_t syncTime(time_t const t, timesource_t const caller) {
if (TimeIsValid(t)) {
uint8_t const TimeIsPulseSynced =
wait_for_pulse(); // wait for next 1pps timepulse
setTime(t); // sync time and reset timeStatus() to timeSet
adjustTime(1); // forward time to next second
timeSource = timeSetSymbols[caller];
ESP_LOGD(TAG, "Time source %c set time to %02d:%02d:%02d", timeSource,
hour(t), minute(t), second(t));
timeSource = caller;
ESP_LOGD(TAG, "Time source %c set time to %02d:%02d:%02d",
timeSetSymbols[timeSource], hour(t), minute(t), second(t));
#ifdef HAS_RTC
if ((TimeIsPulseSynced) && (caller != _rtc))
set_rtctime(now());
@@ -53,11 +52,17 @@ uint8_t syncTime(time_t const t, uint8_t const caller) {
} else {
ESP_LOGD(TAG, "Time source %c sync attempt failed", timeSetSymbols[caller]);
timeSource = timeSetSymbols[_unsynced];
timeSource = _unsynced;
return 0; // failure
}
} // syncTime()
// callback function called by Time.h in interval set in main.cpp
time_t syncProvider_CB(void) {
timeSource = _unsynced;
return 0;
}
// helper function to sync moment on timepulse
uint8_t wait_for_pulse(void) {
// sync on top of next second with 1pps timepulse
@@ -204,7 +209,7 @@ void clock_loop(void *pvParameters) { // ClockTask
xTaskNotifyWait(0x00, ULONG_MAX, &wakeTime,
portMAX_DELAY); // wait for timepulse
if (timeStatus() != timeSet) // no confident time -> no output to clock
if (timeStatus() == timeNotSet) // no confident time -> no output to clock
continue;
t = now(); // payload to send to clock