106 lines
2.6 KiB
C++
106 lines
2.6 KiB
C++
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_event.h"
|
|
#include "esp_log.h"
|
|
#include "esp_sntp.h"
|
|
#include "esp_wifi.h"
|
|
|
|
#include "nvs_flash.h"
|
|
|
|
#include "driver/gpio.h"
|
|
#include "inc/gpio.h"
|
|
#include "driver/uart_select.h"
|
|
#include "inc/wifi.h"
|
|
|
|
#include "inc/logger.h"
|
|
|
|
static const uart_port_t uartPort = UART_NUM_0;
|
|
static TaskHandle_t devTaskHandle = NULL;
|
|
static void devTask(void* parameters);
|
|
static GPIO gpio0(4, GPIO_DIRECTION_OUTPUT);
|
|
static GPIO gpio1(18, GPIO_DIRECTION_OUTPUT);
|
|
static time_t currentTime;
|
|
|
|
|
|
extern "C" void app_main(void)
|
|
{
|
|
esp_log_level_set("*", ESP_LOG_WARN);
|
|
|
|
esp_err_t ret = nvs_flash_init();
|
|
|
|
if(ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
|
{
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
|
|
//--------------------------------------------
|
|
// UART
|
|
//
|
|
const uart_config_t uartConfig =
|
|
{
|
|
.baud_rate = 115200,
|
|
.data_bits = UART_DATA_8_BITS,
|
|
.parity = UART_PARITY_DISABLE,
|
|
.stop_bits = UART_STOP_BITS_1,
|
|
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
|
.rx_flow_ctrl_thresh = 0,
|
|
.source_clk = UART_SCLK_DEFAULT
|
|
};
|
|
ESP_ERROR_CHECK(uart_param_config(uartPort, &uartConfig));
|
|
ESP_ERROR_CHECK(uart_set_pin(uartPort, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
|
ESP_ERROR_CHECK(uart_driver_install(uartPort, 1024, 1024, 0, NULL, 0));
|
|
|
|
uart_write_bytes(uartPort, "helloWorld", sizeof("helloworld"));
|
|
|
|
Logger logger(10, uartPort);
|
|
logger.Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_DEBUG, "Hello World from the Logger himself");
|
|
|
|
LOGGER_DEBUG("YEAHAAA");
|
|
|
|
// Create the development task
|
|
if(xTaskCreate(devTask, "DevTask", 2048, NULL, 3, &devTaskHandle) != pdPASS)
|
|
{
|
|
printf("Task not created");
|
|
}
|
|
|
|
Wifi wifi;
|
|
wifi.start_client();
|
|
|
|
// Start NTP
|
|
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
|
tzset();
|
|
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
|
sntp_setservername(0, "pool.ntp.org");
|
|
sntp_init();
|
|
|
|
while (true)
|
|
{
|
|
|
|
struct tm tm;
|
|
time(¤tTime);
|
|
localtime_r(¤tTime, &tm);
|
|
|
|
printf("%lld\n\r", currentTime);
|
|
printf("%i:%i:%i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
vTaskDelay(1000);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void devTask(void* parameters)
|
|
{
|
|
uint32_t counter = 0;
|
|
|
|
printf("DevTask created");
|
|
while (true)
|
|
{
|
|
(void)gpio0.SetOutput((GPIO_Value_t)(counter % 2));
|
|
(void)gpio1.SetOutput((GPIO_Value_t)(counter % 7));
|
|
counter++;
|
|
vTaskDelay(100);
|
|
}
|
|
}
|