sntp module

This commit is contained in:
2024-12-19 20:33:51 +01:00
parent 0b9f5e2997
commit e5bb620a37
8 changed files with 94 additions and 67 deletions

View File

@ -1,19 +1,6 @@
#include <stdio.h>
#include "esp_log.h"
#include "driver/i2c.h"
#include <esp_system.h>
#include <bmp280.h>
#include <dht.h>
#include <aht.h>
#include <veml7700.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#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"
@ -21,34 +8,10 @@
#include "inputs.h"
#include "control.h"
#include "wifi.h"
#define I2C_MASTER_SCL 19
#define I2C_MASTER_SDA 18
#include "sntp.h"
static const char *TAG = "smart-oil-heater-control-system";
// 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);
}
// SNTP Callback function
void time_sync_notification_cb(struct timeval *tv)
{
ESP_LOGI(TAG, "SNTP synchronization completed! Unix Time: %lld", tv->tv_sec);
ESP_LOGI(TAG, "Time synchronization callback called.");
}
void app_main(void)
{
ESP_LOGI(TAG, "starting ...");
@ -63,25 +26,17 @@ void app_main(void)
ESP_ERROR_CHECK(ret);
// TODO: Error handling!
// initOutputs();
// initInputs();
// initSafety();
initOutputs();
initInputs();
initSafety();
initWifi();
// initControl();
// initMetrics();
// esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
// esp_sntp_setservername(0, "10.1.0.1"); // Set first NTP server local router
// sntp_set_time_sync_notification_cb(time_sync_notification_cb); // Register the SNTP time sync callback
// esp_sntp_init();
initSntp();
initControl();
initMetrics();
while (1)
{
vTaskDelay(pdMS_TO_TICKS(1000));
// Print the current time
// print_current_time();
// ESP_LOGI(TAG, "SNTP Server 0 reachability: %i", esp_sntp_getreachability(0));
// Do nothing ;-)
}
}