esp32_alarm_clock_main.c 913 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Helmut Pozimski <helmut@pozimski.eu>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0-only
  5. */
  6. #include <time.h>
  7. #include <freertos/FreeRTOS.h>
  8. #include <freertos/event_groups.h>
  9. #include <nvs_flash.h>
  10. #include <esp_log.h>
  11. #include <esp_wifi.h>
  12. #include "wifi.h"
  13. #include "configuration.h"
  14. #include "ds3231.h"
  15. #include "tm1637.h"
  16. #include "time_sync.h"
  17. #include "time_display.h"
  18. void app_main(void) {
  19. struct tm current_time;
  20. ESP_ERROR_CHECK(nvs_flash_init());
  21. ESP_ERROR_CHECK(esp_netif_init());
  22. ESP_ERROR_CHECK(esp_event_loop_create_default());
  23. wifi_init();
  24. wifi_start();
  25. ds3231_init(DS3231_SDA_PIN, DS3231_SCL_PIN);
  26. tm1637_init(TM1637_CLK_PIN, TM1637_DIO_PIN, true, 1);
  27. ds3231_read_date_time(&current_time);
  28. sntp_start(21600);
  29. if (current_time.tm_year == 0) {
  30. await_sntp_sync();
  31. }
  32. xTaskCreate(display_update_task, "display_update_task", 2048, NULL, 7, NULL);
  33. }