From 4a573bc638a747b4838d0ab486786f680c33558a Mon Sep 17 00:00:00 2001 From: Marius Gripp Date: Tue, 27 Aug 2019 17:27:57 +0200 Subject: [PATCH] send time via uart --- include/main.h | 1 + src/main.cpp | 2 ++ src/uart.cpp | 24 +++++++++++++++++++++++- src/uart.h | 13 +++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/main.h b/include/main.h index bce12e51..215aa47e 100644 --- a/include/main.h +++ b/include/main.h @@ -16,6 +16,7 @@ #include "irqhandler.h" #include "led.h" #include "spislave.h" +#include "uart.h" #if(HAS_LORA) #include "lorawan.h" #endif diff --git a/src/main.cpp b/src/main.cpp index c6dae99e..2a7aab1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -444,6 +444,8 @@ void setup() { // show compiled features ESP_LOGI(TAG, "Features:%s", features); + uart_setup(); + } // setup() void loop() { diff --git a/src/uart.cpp b/src/uart.cpp index 1303cbf5..b71b3e28 100644 --- a/src/uart.cpp +++ b/src/uart.cpp @@ -1,13 +1,30 @@ +#include "rtctime.h" + #include #include #include #include "globals.h" +#include "uart.h" #include "driver/uart.h" static const char TAG[] = __FILE__; TaskHandle_t UartTask = NULL; +void uart_setup() { + // setup UART connection + uart_config_t uart_config = { + .baud_rate = 9600, + .data_bits = UART_DATA_7_BITS, + .parity = UART_PARITY_EVEN, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE + }; + uart_param_config(UART_NUM_1, &uart_config); + uart_set_pin(UART_NUM_1, CLOCK_DCF_TXD, CLOCK_DCF_RXD, CLOCK_DCF_RTS, CLOCK_DCF_CTS); + uart_driver_install(UART_NUM_1, CLOCK_BUF_SIZE * 2, 0, 0, NULL, 0); +} + void time_uart_send(void * pvParameters) { struct timeval curTime; @@ -16,7 +33,12 @@ void time_uart_send(void * pvParameters) { TickType_t xLastWakeTime = xTaskGetTickCount(); for(;;) { - time_t nowTime = now(); + struct timeval tv; + struct timezone tz; + if(gettimeofday(&tv, &tz) != 0) { + ESP_LOGI(TAG, "ERROR gettimeofday"); + } + time_t nowTime = tv.tv_sec; strftime(timestamp, sizeof(timestamp), format, localtime(&nowTime)); ESP_LOGI(TAG, "Current Time: %s", timestamp); diff --git a/src/uart.h b/src/uart.h index 612aabbe..f12acbaf 100644 --- a/src/uart.h +++ b/src/uart.h @@ -1,2 +1,15 @@ +#ifndef UART_H +#define UART_H + +// UART for Clock DCF +#define CLOCK_DCF_TXD (GPIO_NUM_4) +#define CLOCK_DCF_RXD (GPIO_NUM_15) +#define CLOCK_DCF_RTS (UART_PIN_NO_CHANGE) +#define CLOCK_DCF_CTS (UART_PIN_NO_CHANGE) +#define CLOCK_BUF_SIZE (1024) + void time_uart_send(void * pvParameters); void time_uart_send_start(); +void uart_setup(); + +#endif