From 8a764af09ba1aa73575f90707900434956d5a464 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Jan 2019 09:03:18 +0100 Subject: [PATCH 1/5] blink TimeSync display --- src/display.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 7f9adbea..8e143742 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -139,6 +139,12 @@ void refreshtheDisplay() { uint8_t msgWaiting; char buff[16]; // 16 chars line buffer + const char timeNosyncSymbol = '?'; +#ifdef HAS_IF482 + const char timesyncSymbol = '°'; +#else + const char timesyncSymbol = '*'; +#endif // update counter (lines 0-1) snprintf( @@ -210,10 +216,15 @@ void refreshtheDisplay() { #else // update time/date display (line 6) time_t t = myTZ.toLocal(now()); + char timeState = + timeStatus() == timeSet ? timesyncSymbol : timeNosyncSymbol; +#ifdef RTC_INT // make timestatus symbol blinking + if (second(t) % 2) + timeState = ' '; +#endif // RTC_INT u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t), - timeStatus() == timeSet ? '*' : '?', day(t), - printmonth[month(t)]); -#endif + timeState, day(t), printmonth[month(t)]); +#endif // HAS_RTC // update LMiC event display (line 7) u8x8.setCursor(0, 7); From 8459eec8efb6f27b98618ca28e1bbb55a5df2d61 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Jan 2019 09:04:31 +0100 Subject: [PATCH 2/5] IF482 depends on RTC_INT not HAS_RTC --- src/if482.cpp | 12 +++++++----- src/main.cpp | 5 ++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/if482.cpp b/src/if482.cpp index 3914c7d2..f64e0c07 100644 --- a/src/if482.cpp +++ b/src/if482.cpp @@ -1,13 +1,14 @@ -#if defined HAS_IF482 && defined HAS_RTC +#if defined HAS_IF482 && defined RTC_INT /* NOTE: The IF482 Generator needs an high precise 1 Hz clock signal which cannot be acquired in suitable precision on the ESP32 SoC itself. Additional clocking hardware is required, ususally the clock signal is generated by external RTC or -GPS chip or a GPS chip which can generate a precise clock signal (+/- 2ppm). In -this example code we use a Maxim DS3231 RTC chip, and configure it's interrupt -output as clock output. The clock signal triggers an interrupt on the ESP32, -which controls the realtime output of IF482 telegram. This is why code in +GPS which can generate a precise time pulse signal (+/- 2ppm). + +In this example code we use a Maxim DS3231 RTC chip, and configure the chips's +interrupt output pin as clock. The clock signal triggers an interrupt on the +ESP32, which controls the realtime output of IF482 telegram. This is why code in IF482.cpp depends on code in RTCTIME.cpp. */ @@ -16,6 +17,7 @@ IF482.cpp depends on code in RTCTIME.cpp. /* IF482 Generator to control clocks with IF482 telegram input (e.g. BÜRK BU190) + Example IF482 telegram: "OAL160806F170400" IF482 Specification: diff --git a/src/main.cpp b/src/main.cpp index 64c50093..6d7a324b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -198,6 +198,7 @@ void setup() { else ESP_LOGI(TAG, "RTC has set the system time"); setSyncInterval(TIME_SYNC_INTERVAL_RTC); +#endif // HAS_RTC #ifdef HAS_IF482 strcat_P(features, " IF482"); @@ -212,8 +213,6 @@ void setup() { 0); // CPU core #endif // HAS_IF482 -#endif // HAS_RTC - // initialize wifi antenna #ifdef HAS_ANTENNA_SWITCH strcat_P(features, " ANT"); @@ -433,7 +432,7 @@ void setup() { #endif // start RTC interrupt -#if defined HAS_IF482 && defined HAS_RTC +#if defined HAS_IF482 && defined RTC_INT // setup external interupt for active low RTC INT pin assert(IF482Task != NULL); // has if482loop task started? ESP_LOGI(TAG, "Starting IF482 output..."); From 2fd3b6725c186a7b9a1e430d7b6278606e2de227 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Jan 2019 09:04:56 +0100 Subject: [PATCH 3/5] set RTC by GPS & LORA --- src/gpsread.cpp | 4 ++++ src/lorawan.cpp | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 2aff4947..07bfd9ee 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -73,6 +73,10 @@ time_t get_gpstime(void) { if (gps.time.age() < 1500) { t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(), gps.time.hour(), gps.time.minute(), gps.time.second()); +#ifdef HAS_RTC + if (!set_rtctime(t)) + ESP_LOGE(TAG, "RTC set time failure"); +#endif } else { ESP_LOGW(TAG, "GPS has no confident time"); } diff --git a/src/lorawan.cpp b/src/lorawan.cpp index fa53fdd7..d8350b5b 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -455,12 +455,9 @@ void user_request_network_time_callback(void *pVoidUserUTCTime, // Update system time with time read from the network setTime(*pUserUTCTime); + ESP_LOGI(TAG, "LoRaWAN network has set the system time"); #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)); -} +} \ No newline at end of file From 98d6e1283661ba39d10a1d99d9e7e027d2172d60 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Jan 2019 09:06:10 +0100 Subject: [PATCH 4/5] v1.7.143 --- platformio.ini | 2 +- src/hal/ttgofox.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 3f2f9c0d..d64d1be7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,7 +30,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 1.7.141 +release_version = 1.7.143 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 3 diff --git a/src/hal/ttgofox.h b/src/hal/ttgofox.h index daff6a38..f7cd3033 100644 --- a/src/hal/ttgofox.h +++ b/src/hal/ttgofox.h @@ -25,11 +25,11 @@ #define RTC_INT GPIO_NUM_34 // interrupt input from rtc // Settings for IF482 interface -//#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters +#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters // Settings for external GPS chip -//#define HAS_GPS 1 // use on board GPS -//#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_17, GPIO_NUM_16 // UBlox NEO 6M or 7M with default configuration +#define HAS_GPS 1 // use on board GPS +#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_17, GPIO_NUM_16 // UBlox NEO 6M or 7M with default configuration // Pins for LORA chip SPI interface, reset line and interrupt lines #define LORA_SCK (5) From 110e969ba8ba78d92ada1118f7db94ffbb1c8a60 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 29 Jan 2019 19:52:54 +0100 Subject: [PATCH 5/5] bugfixes in realtime handling --- src/display.cpp | 2 +- src/gpsread.cpp | 4 ---- src/lorawan.cpp | 2 +- src/main.cpp | 11 ++++++++--- src/paxcounter.conf | 6 +++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 8e143742..cf3207c7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -141,7 +141,7 @@ void refreshtheDisplay() { char buff[16]; // 16 chars line buffer const char timeNosyncSymbol = '?'; #ifdef HAS_IF482 - const char timesyncSymbol = '°'; + const char timesyncSymbol = '+'; #else const char timesyncSymbol = '*'; #endif diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 07bfd9ee..2aff4947 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -73,10 +73,6 @@ time_t get_gpstime(void) { if (gps.time.age() < 1500) { t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(), gps.time.hour(), gps.time.minute(), gps.time.second()); -#ifdef HAS_RTC - if (!set_rtctime(t)) - ESP_LOGE(TAG, "RTC set time failure"); -#endif } else { ESP_LOGW(TAG, "GPS has no confident time"); } diff --git a/src/lorawan.cpp b/src/lorawan.cpp index d8350b5b..654b1469 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -457,7 +457,7 @@ void user_request_network_time_callback(void *pVoidUserUTCTime, setTime(*pUserUTCTime); ESP_LOGI(TAG, "LoRaWAN network has set the system time"); #ifdef HAS_RTC - if (!set_rtctime(*pUserUTCTime)) + if (set_rtctime(*pUserUTCTime)) ESP_LOGE(TAG, "RTC set time failure"); #endif } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6d7a324b..5703501f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,7 +197,7 @@ void setup() { ESP_LOGI(TAG, "Unable to sync system time with RTC"); else ESP_LOGI(TAG, "RTC has set the system time"); - setSyncInterval(TIME_SYNC_INTERVAL_RTC); + setSyncInterval(TIME_SYNC_INTERVAL_RTC * 60); #endif // HAS_RTC #ifdef HAS_IF482 @@ -426,9 +426,14 @@ void setup() { setSyncProvider(&get_gpstime); if (timeStatus() != timeSet) ESP_LOGI(TAG, "Unable to sync system time with GPS"); - else + else { ESP_LOGI(TAG, "GPS has set the system time"); - setSyncInterval(TIME_SYNC_INTERVAL_GPS); +#ifdef HAS_RTC + if (set_rtctime(now())) + ESP_LOGE(TAG, "RTC set time failure"); +#endif + } + setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60); #endif // start RTC interrupt diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 11151144..a97f8b9e 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -82,9 +82,9 @@ #define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] // settings for syncing time of node and external time sources -#define TIME_SYNC_INTERVAL_GPS 5 // sync time each ... minutes with GPS [default = 5], comment out means off -#define TIME_SYNC_INTERVAL_RTC 5 // sync time each ... minutes with RTC [default = 5], comment out means off -//#define TIME_SYNC_INTERVAL_LORA 60 // sync time each ... minutes with LORA network [default = 60], comment out means off +#define TIME_SYNC_INTERVAL_GPS 60 // sync time each ... minutes with GPS [default = 60], comment out means off +#define TIME_SYNC_INTERVAL_RTC 60 // sync time each ... minutes with RTC [default = 60], comment out means off +//#define TIME_SYNC_INTERVAL_LORA 60 // sync time each ... minutes with LORA network [default = 60], comment out means off #define IF482_OFFSET 984 // 1sec minus IF482 serial transmit time [ms]: e.g. 9 bits * 17 bytes * 1/9600 bps = 16ms // time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino