From b5395661fcf61d8022227a7af6f9681a89716c16 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 31 Mar 2019 15:32:22 +0200 Subject: [PATCH] fix issue #332 --- include/lorawan.h | 3 +++ include/timesync.h | 2 +- platformio.ini | 2 +- src/hal/generic.h | 4 ++-- src/lmic_config.h | 2 +- src/lorawan.cpp | 4 +++- src/main.cpp | 5 +++++ src/timesync.cpp | 4 ++-- 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/lorawan.h b/include/lorawan.h index 3c207c02..cb4158e0 100644 --- a/include/lorawan.h +++ b/include/lorawan.h @@ -36,6 +36,9 @@ void lora_send(osjob_t *job); void lora_enqueuedata(MessageBuffer_t *message, sendprio_t prio); void lora_queuereset(void); void lora_housekeeping(void); +#if (TIME_SYNC_LORAWAN) void user_request_network_time_callback(void *pVoidUserUTCTime, int flagSuccess); +#endif + #endif \ No newline at end of file diff --git a/include/timesync.h b/include/timesync.h index 9df72171..232ac541 100644 --- a/include/timesync.h +++ b/include/timesync.h @@ -14,6 +14,6 @@ void send_timesync_req(void); int recv_timesync_ans(uint8_t buf[], uint8_t buf_len); void process_timesync_req(void *taskparameter); void store_time_sync_req(uint32_t t_millisec); -int adjustTime(uint32_t t_sec, uint16_t t_msec); +void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec); #endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index e4421de0..74bc9871 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,7 +31,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.41 +release_version = 1.7.422 ; 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/generic.h b/src/hal/generic.h index 1151b57f..7511ffff 100644 --- a/src/hal/generic.h +++ b/src/hal/generic.h @@ -62,8 +62,8 @@ //#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters // Settings for DCF77 interface -#define HAS_DCF77 GPIO_NUM_1 -#define DCF77_ACTIVE_LOW 1 +//#define HAS_DCF77 GPIO_NUM_1 +//#define DCF77_ACTIVE_LOW 1 // Pins for LORA chip SPI interface, reset line and interrupt lines #define LORA_SCK (5) diff --git a/src/lmic_config.h b/src/lmic_config.h index c35cbd19..9e90a439 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -22,7 +22,7 @@ //#define LMIC_USE_INTERRUPTS 1 //time sync via LoRaWAN network, is not yet supported by TTN (LoRaWAN spec v1.0.3) -#define LMIC_ENABLE_DeviceTimeReq 1 +//#define LMIC_ENABLE_DeviceTimeReq 1 // 16 μs per tick // LMIC requires ticks to be 15.5μs - 100 μs long diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 21fe100b..48781d8c 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -462,6 +462,7 @@ void lora_housekeeping(void) { // uxTaskGetStackHighWaterMark(LoraTask)); } +#if (TIME_SYNC_LORAWAN) void IRAM_ATTR user_request_network_time_callback(void *pVoidUserUTCTime, int flagSuccess) { // Explicit conversion from void* to uint32_t* to avoid compiler errors @@ -504,11 +505,12 @@ void IRAM_ATTR user_request_network_time_callback(void *pVoidUserUTCTime, time_t requestDelaySec = osticks2ms(ticksNow - ticksRequestSent) / 1000; // Update system time with time read from the network - adjustTime(*pUserUTCTime + requestDelaySec, 0); + setMyTime(*pUserUTCTime + requestDelaySec, 0); // end of time critical section: release I2C bus I2C_MUTEX_UNLOCK(); } // user_request_network_time_callback +#endif // TIME_SYNC_LORAWAN #endif // HAS_LORA diff --git a/src/main.cpp b/src/main.cpp index 1d0b82f0..4029cd7f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -411,6 +411,11 @@ void setup() { #endif // HAS_BUTTON #if (TIME_SYNC_INTERVAL) +#if (!defined(TIME_SYNC_LORAWAN) && !defined(TIME_SYNC_TIMESERVER) && \ + !defined HAS_GPS && !defined HAS_RTC) +#warning you did not specify a time source, time will not be synched +#endif +#else // start pps timepulse ESP_LOGI(TAG, "Starting Timekeeper..."); assert(timepulse_init()); // setup timepulse diff --git a/src/timesync.cpp b/src/timesync.cpp index bf141814..b38f8c34 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -130,7 +130,7 @@ void process_timesync_req(void *taskparameter) { // calculate fraction milliseconds time_to_set_fraction_msec = (uint16_t)(time_offset_ms.count() % 1000); - adjustTime(time_to_set, time_to_set_fraction_msec); + setMyTime(time_to_set, time_to_set_fraction_msec); // end of time critical section: release I2C bus I2C_MUTEX_UNLOCK(); @@ -213,7 +213,7 @@ int recv_timesync_ans(uint8_t buf[], uint8_t buf_len) { } // adjust system time, calibrate RTC and RTC_INT pps -int IRAM_ATTR adjustTime(uint32_t t_sec, uint16_t t_msec) { +void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec) { time_t time_to_set = (time_t)t_sec;