TimeServer

This commit is contained in:
jomjol
2020-12-24 16:08:58 +01:00
parent 7e4f83c2f5
commit 584a73255a
5 changed files with 27 additions and 33 deletions

View File

@@ -361,6 +361,14 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
setTimeZone(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "TIMESERVER") && (zerlegt.size() > 1))
{
string zw = "Set TimeZone: " + zerlegt[1];
reset_servername(zerlegt[1]);
}
if ((toUpper(zerlegt[0]) == "SETUPMODE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")

View File

@@ -1,11 +1,5 @@
#include "time_sntp.h"
/* LwIP SNTP example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string>
#include <time.h>
#include <sys/time.h>
@@ -17,25 +11,19 @@
#include "esp_log.h"
#include "esp_attr.h"
#include "esp_sleep.h"
// #include "nvs_flash.h"
// #include "protocol_examples_common.h"
#include "esp_sntp.h"
#include "ClassLogFile.h"
static const char *TAG = "sntp";
RTC_DATA_ATTR int boot_count = 0;
bool setTimeAlwaysOnReboot = true;
static void obtain_time(void);
static void initialize_sntp(void);
void time_sync_notification_cb(struct timeval *tv)
{
// LogFile.WriteToFile("Notification of a time synchronization event");
ESP_LOGI(TAG, "Notification of a time synchronization event");
}
@@ -54,9 +42,6 @@ std::string gettimestring(const char * frm)
void setup_time()
{
++boot_count;
ESP_LOGI(TAG, "Boot count: %d", boot_count);
time_t now;
struct tm timeinfo;
time(&now);
@@ -72,8 +57,6 @@ void setup_time()
char strftime_buf[64];
setTimeZone("CET-1CEST,M3.5.0,M10.5.0/3");
// setTimeZone("Europe/Berlin");
// setTimeZone("Asia/Tokyo");
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
@@ -97,9 +80,6 @@ void setTimeZone(std::string _tzstring)
static void obtain_time(void)
{
// initialize_sntp();
// wait for time to be set
time_t now = 0;
struct tm timeinfo = {};
int retry = 0;
@@ -110,23 +90,28 @@ static void obtain_time(void)
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
if (retry == retry_count) {
// LogFile.WriteToFile("Time Synchzronisation nicht erfolgreich ...");
}
else
{
// LogFile.WriteToFile("Time erfolgreich ...");
}
time(&now);
localtime_r(&now, &timeinfo);
}
void reset_servername(std::string _servername)
{
printf("Set SNTP-Server: %s\n", _servername.c_str());
sntp_stop();
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, _servername.c_str());
sntp_init();
obtain_time();
std::string zw = gettimestring("%Y%m%d-%H%M%S");
printf("Time ist %s\n", zw.c_str());
}
static void initialize_sntp(void)
{
ESP_LOGI(TAG, "Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
sntp_setservername(0, "xx_pool.ntp.org");
// sntp_set_time_sync_notification_cb(time_sync_notification_cb);
sntp_init();
}

View File

@@ -16,3 +16,4 @@ void setup_time(void);
std::string gettimestring(const char * frm);
void setTimeZone(std::string _tzstring);
void reset_servername(std::string _servername);

View File

@@ -1,4 +1,4 @@
const char* GIT_REV="9971c82";
const char* GIT_REV="7e4f83c";
const char* GIT_TAG="";
const char* GIT_BRANCH="rolling-reduce-sd-use";
const char* BUILD_TIME="2020-12-23 10:06";
const char* BUILD_TIME="2020-12-24 15:56";

View File

@@ -1,4 +1,4 @@
const char* GIT_REV="9971c82";
const char* GIT_REV="7e4f83c";
const char* GIT_TAG="";
const char* GIT_BRANCH="rolling-reduce-sd-use";
const char* BUILD_TIME="2020-12-23 10:06";
const char* BUILD_TIME="2020-12-24 15:56";