Skip to content
Snippets Groups Projects
Commit dc57643f authored by Jens Nolte's avatar Jens Nolte
Browse files

Fix ntp default parameter, add logging and remove polling for network

parent 515d4caa
No related branches found
No related tags found
1 merge request!8Updating bme280-qthing
......@@ -11,6 +11,7 @@
#include <stdlib.h>
#include "esp_log.h"
#define TAG "NTP"
typedef struct {
bool started;
......@@ -24,18 +25,19 @@ void ntp_task(void *ignored) {
time_t now = 0;
struct tm timeinfo = { 0 };
while (get_wlan_connection_status() != connected) vTaskDelay(100 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "Configuring ntp");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, (char *)parameter.address.c_str());
sntp_init();
ESP_LOGI(TAG, "Waiting for time synchronization");
do {
vTaskDelay(100 / portTICK_PERIOD_MS);
time(&now);
localtime_r(&now, &timeinfo);
} while(timeinfo.tm_year < 100);
ESP_LOGI(TAG, "Time synchronized");
if (parameter.callback != NULL) parameter.callback();
vTaskDelete(NULL);
......@@ -45,9 +47,10 @@ namespace qthing {
void enable_ntp(std::string address, std::string timezone, qthing::ntp_callback_t callback) {
if (parameter.started) {
ESP_LOGE("NTP", "service already enabled");
ESP_LOGE(TAG, "service already enabled");
return;
}
ESP_LOGI(TAG, "Starting ntp");
parameter = {true, address, callback};
......
......@@ -98,7 +98,7 @@ namespace qthing {
void set_led_strip_fps(uint8_t fps);
typedef std::function<void()> ntp_callback_t;
void enable_ntp(std::string address = NULL, std::string timezone = "CET-1CEST,M3.5.0,M10.5.0/3", qthing::ntp_callback_t callback = NULL);
void enable_ntp(std::string address = "pool.ntp.org", std::string timezone = "CET-1CEST,M3.5.0,M10.5.0/3", qthing::ntp_callback_t callback = NULL);
}
// utility
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment