send time via uart

This commit is contained in:
Marius Gripp 2019-08-27 17:27:57 +02:00
parent cab44588c7
commit 4a573bc638
4 changed files with 39 additions and 1 deletions

View File

@ -16,6 +16,7 @@
#include "irqhandler.h"
#include "led.h"
#include "spislave.h"
#include "uart.h"
#if(HAS_LORA)
#include "lorawan.h"
#endif

View File

@ -444,6 +444,8 @@ void setup() {
// show compiled features
ESP_LOGI(TAG, "Features:%s", features);
uart_setup();
} // setup()
void loop() {

View File

@ -1,13 +1,30 @@
#include "rtctime.h"
#include <Arduino.h>
#include <sys/time.h>
#include <lmic/oslmic.h>
#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);

View File

@ -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