mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 12:36:52 +03:00
TimeServer
This commit is contained in:
@@ -361,6 +361,14 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|||||||
setTimeZone(zerlegt[1]);
|
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[0]) == "SETUPMODE") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
if (toUpper(zerlegt[1]) == "TRUE")
|
if (toUpper(zerlegt[1]) == "TRUE")
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
#include "time_sntp.h"
|
#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 <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@@ -17,25 +11,19 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_sleep.h"
|
#include "esp_sleep.h"
|
||||||
// #include "nvs_flash.h"
|
|
||||||
// #include "protocol_examples_common.h"
|
|
||||||
#include "esp_sntp.h"
|
#include "esp_sntp.h"
|
||||||
|
|
||||||
#include "ClassLogFile.h"
|
#include "ClassLogFile.h"
|
||||||
|
|
||||||
static const char *TAG = "sntp";
|
static const char *TAG = "sntp";
|
||||||
|
|
||||||
RTC_DATA_ATTR int boot_count = 0;
|
|
||||||
|
|
||||||
bool setTimeAlwaysOnReboot = true;
|
bool setTimeAlwaysOnReboot = true;
|
||||||
|
|
||||||
static void obtain_time(void);
|
static void obtain_time(void);
|
||||||
static void initialize_sntp(void);
|
static void initialize_sntp(void);
|
||||||
|
|
||||||
|
|
||||||
void time_sync_notification_cb(struct timeval *tv)
|
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");
|
ESP_LOGI(TAG, "Notification of a time synchronization event");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +42,6 @@ std::string gettimestring(const char * frm)
|
|||||||
|
|
||||||
void setup_time()
|
void setup_time()
|
||||||
{
|
{
|
||||||
++boot_count;
|
|
||||||
ESP_LOGI(TAG, "Boot count: %d", boot_count);
|
|
||||||
|
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time(&now);
|
time(&now);
|
||||||
@@ -72,8 +57,6 @@ void setup_time()
|
|||||||
char strftime_buf[64];
|
char strftime_buf[64];
|
||||||
|
|
||||||
setTimeZone("CET-1CEST,M3.5.0,M10.5.0/3");
|
setTimeZone("CET-1CEST,M3.5.0,M10.5.0/3");
|
||||||
// setTimeZone("Europe/Berlin");
|
|
||||||
// setTimeZone("Asia/Tokyo");
|
|
||||||
|
|
||||||
localtime_r(&now, &timeinfo);
|
localtime_r(&now, &timeinfo);
|
||||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||||
@@ -97,9 +80,6 @@ void setTimeZone(std::string _tzstring)
|
|||||||
|
|
||||||
static void obtain_time(void)
|
static void obtain_time(void)
|
||||||
{
|
{
|
||||||
// initialize_sntp();
|
|
||||||
|
|
||||||
// wait for time to be set
|
|
||||||
time_t now = 0;
|
time_t now = 0;
|
||||||
struct tm timeinfo = {};
|
struct tm timeinfo = {};
|
||||||
int retry = 0;
|
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);
|
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
|
||||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
if (retry == retry_count) {
|
|
||||||
// LogFile.WriteToFile("Time Synchzronisation nicht erfolgreich ...");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// LogFile.WriteToFile("Time erfolgreich ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
localtime_r(&now, &timeinfo);
|
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)
|
static void initialize_sntp(void)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Initializing SNTP");
|
ESP_LOGI(TAG, "Initializing SNTP");
|
||||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
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_set_time_sync_notification_cb(time_sync_notification_cb);
|
||||||
sntp_init();
|
sntp_init();
|
||||||
}
|
}
|
||||||
@@ -15,4 +15,5 @@
|
|||||||
void setup_time(void);
|
void setup_time(void);
|
||||||
|
|
||||||
std::string gettimestring(const char * frm);
|
std::string gettimestring(const char * frm);
|
||||||
void setTimeZone(std::string _tzstring);
|
void setTimeZone(std::string _tzstring);
|
||||||
|
void reset_servername(std::string _servername);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="9971c82";
|
const char* GIT_REV="7e4f83c";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
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";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="9971c82";
|
const char* GIT_REV="7e4f83c";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling-reduce-sd-use";
|
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";
|
||||||
Reference in New Issue
Block a user