set server and cleanup
This commit is contained in:
parent
d1cb50cf98
commit
15b74c91f4
27
.vscode/c_cpp_properties.json
vendored
Normal file
27
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ESP-IDF",
|
||||
"compilerPath": "${default}",
|
||||
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
|
||||
"includePath": [
|
||||
"${config:idf.espIdfPath}/components/**",
|
||||
"${config:idf.espIdfPathWin}/components/**",
|
||||
"${config:idf.espAdfPath}/components/**",
|
||||
"${config:idf.espAdfPathWin}/components/**",
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"browse": {
|
||||
"path": [
|
||||
"${config:idf.espIdfPath}/components",
|
||||
"${config:idf.espIdfPathWin}/components",
|
||||
"${config:idf.espAdfPath}/components/**",
|
||||
"${config:idf.espAdfPathWin}/components/**",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
45
main/main.c
45
main/main.c
@ -26,24 +26,6 @@
|
||||
|
||||
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()
|
||||
{
|
||||
@ -59,6 +41,13 @@ void print_current_time()
|
||||
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 ...");
|
||||
@ -73,24 +62,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_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();
|
||||
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(10000U));
|
||||
|
||||
// Obtain the current time
|
||||
obtain_time();
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// Print the current time
|
||||
print_current_time();
|
||||
|
||||
ESP_LOGI(TAG, "SNTP Server 0 reachability: %i", esp_sntp_getreachability(0));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user