error handling and cleanup
This commit is contained in:
26
main/sntp.c
26
main/sntp.c
@ -1,3 +1,8 @@
|
||||
/**
|
||||
* @file sntp.c
|
||||
* @brief Implementation of SNTP client module.
|
||||
*/
|
||||
|
||||
#include "sntp.h"
|
||||
|
||||
#include "esp_sntp.h"
|
||||
@ -6,17 +11,22 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-sntp";
|
||||
static volatile eSntpState sntpState = SYNC_NOT_STARTED;
|
||||
void time_sync_notification_cb(struct timeval *tv);
|
||||
static const char *TAG = "sntp";
|
||||
|
||||
void initSntp(void)
|
||||
static volatile eSntpState sntpState = SYNC_NOT_STARTED;
|
||||
|
||||
static void time_sync_notification_cb(struct timeval *tv);
|
||||
|
||||
esp_err_t initSntp(void)
|
||||
{
|
||||
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
esp_sntp_setservername(0, CONFIG_SNTP_SERVER_IP_ADDR);
|
||||
|
||||
sntp_set_time_sync_notification_cb(time_sync_notification_cb);
|
||||
esp_sntp_init();
|
||||
|
||||
ESP_LOGI(TAG, "Initialized successfully, server: %s", CONFIG_SNTP_SERVER_IP_ADDR);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
eSntpState getSntpState(void)
|
||||
@ -24,8 +34,12 @@ eSntpState getSntpState(void)
|
||||
return sntpState;
|
||||
}
|
||||
|
||||
void time_sync_notification_cb(struct timeval *tv)
|
||||
/**
|
||||
* @brief SNTP time sync callback.
|
||||
* @param tv Synchronized time value.
|
||||
*/
|
||||
static void time_sync_notification_cb(struct timeval *tv)
|
||||
{
|
||||
ESP_LOGI(TAG, "SNTP synchronization! Unix Time: %lld", tv->tv_sec);
|
||||
ESP_LOGI(TAG, "Time synchronized! Unix Time: %lld", tv->tv_sec);
|
||||
sntpState = SYNC_SUCCESSFUL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user