82 lines
1.8 KiB
C++
82 lines
1.8 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 "inc/wifi.h"
|
|
|
|
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;
|
|
//
|
|
//static void wifi_init(void);
|
|
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
|
void wifi_init_sta(void);
|
|
|
|
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();
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|