some idea
This commit is contained in:
parent
1fb4b4b0e4
commit
d1cb50cf98
56
main/main.c
56
main/main.c
@ -11,6 +11,9 @@
|
||||
#include <freertos/task.h>
|
||||
#include "freertos/timers.h"
|
||||
#include "nvs_flash.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <esp_sntp.h>
|
||||
|
||||
#include "safety.h"
|
||||
#include "metrics.h"
|
||||
@ -23,6 +26,39 @@
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system";
|
||||
|
||||
// Function to wait for time synchronization
|
||||
void obtain_time()
|
||||
{
|
||||
time_t now = 0;
|
||||
struct tm timeinfo = {0};
|
||||
|
||||
// Wait for the time to be set
|
||||
// while (timeinfo.tm_year < (2020 - 1900))
|
||||
{
|
||||
ESP_LOGI(TAG, "Waiting for system time to be set...");
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "System time is set.");
|
||||
}
|
||||
|
||||
// Function to print the current time
|
||||
void print_current_time()
|
||||
{
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
|
||||
char strftime_buf[64];
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
|
||||
ESP_LOGI(TAG, "Current time: %s", strftime_buf);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "starting ...");
|
||||
@ -37,14 +73,24 @@ void app_main(void)
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
// TODO: Error handling!
|
||||
initOutputs();
|
||||
initInputs();
|
||||
initSafety();
|
||||
initControl();
|
||||
//initOutputs();
|
||||
//initInputs();
|
||||
//initSafety();
|
||||
//initControl();
|
||||
initMetrics();
|
||||
|
||||
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
esp_sntp_setservername(0, "10.1.0.1"); // Set NTP server
|
||||
esp_sntp_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(2048));
|
||||
vTaskDelay(pdMS_TO_TICKS(10000U));
|
||||
|
||||
// Obtain the current time
|
||||
obtain_time();
|
||||
|
||||
// Print the current time
|
||||
print_current_time();
|
||||
}
|
||||
}
|
@ -38,6 +38,8 @@ esp_err_t get_metrics_handler(httpd_req_t *req);
|
||||
void initMetrics(void)
|
||||
{
|
||||
connect_wifi();
|
||||
return;
|
||||
|
||||
setup_server();
|
||||
|
||||
BaseType_t taskCreated = xTaskCreate(
|
||||
|
Loading…
Reference in New Issue
Block a user