mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 04:26:58 +03:00
Update 2020-11-30
This commit is contained in:
@@ -11,10 +11,12 @@ void ClassFlow::SetInitialParameter(void)
|
||||
ListFlowControll = NULL;
|
||||
}
|
||||
|
||||
std::vector<string> ClassFlow::ZerlegeZeile(std::string input)
|
||||
//std::vector<string> ClassFlow::ZerlegeZeile(std::string input, std::string delimiter);
|
||||
|
||||
std::vector<string> ClassFlow::ZerlegeZeile(std::string input, std::string delimiter)
|
||||
{
|
||||
std::vector<string> Output;
|
||||
std::string delimiter = " =,";
|
||||
// std::string delimiter = " =,";
|
||||
|
||||
input = trim(input, delimiter);
|
||||
size_t pos = findDelimiterPos(input, delimiter);
|
||||
|
||||
@@ -23,7 +23,8 @@ struct HTMLInfo
|
||||
class ClassFlow
|
||||
{
|
||||
protected:
|
||||
std::vector<string> ZerlegeZeile(string input);
|
||||
// std::vector<string> ZerlegeZeile(string input);
|
||||
std::vector<string> ZerlegeZeile(string input, string delimiter = " =, ");
|
||||
bool isNewParagraph(string input);
|
||||
bool GetNextParagraph(FILE* pfile, string& aktparamgraph);
|
||||
bool getNextLine(FILE* pfile, string* rt);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "ClassFlowControll.h"
|
||||
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include "ClassLogFile.h"
|
||||
@@ -104,6 +106,9 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
|
||||
if (toUpper(_type).compare("[DEBUG]") == 0)
|
||||
cfc = this;
|
||||
|
||||
if (toUpper(_type).compare("[SYSTEM]") == 0)
|
||||
cfc = this;
|
||||
|
||||
return cfc;
|
||||
}
|
||||
|
||||
@@ -259,12 +264,12 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
return false;
|
||||
|
||||
|
||||
if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0)) // Paragraph passt nicht zu MakeImage
|
||||
if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) && (toUpper(aktparamgraph).compare("[SYSTEM]") != 0)) // Paragraph passt nicht zu MakeImage
|
||||
return false;
|
||||
|
||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||
{
|
||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||
zerlegt = this->ZerlegeZeile(aktparamgraph, " =");
|
||||
if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
|
||||
{
|
||||
if (toUpper(zerlegt[1]) == "TRUE")
|
||||
@@ -291,6 +296,19 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
{
|
||||
LogFile.SetRetention(std::stoi(zerlegt[1]));
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "TIMEZONE") && (zerlegt.size() > 1))
|
||||
{
|
||||
string zw = "Set TimeZone: " + zerlegt[1];
|
||||
setTimeZone(zerlegt[1]);
|
||||
}
|
||||
|
||||
if ((toUpper(zerlegt[0]) == "TIMEUPDATEINTERVALL") && (zerlegt.size() > 1))
|
||||
{
|
||||
TimeUpdateIntervall = stof(zerlegt[1]);
|
||||
xTaskCreate(&task_doTimeSync, "update_time", configMINIMAL_STACK_SIZE * 16, &TimeUpdateIntervall, tskIDLE_PRIORITY, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ protected:
|
||||
float AutoIntervall;
|
||||
void SetInitialParameter(void);
|
||||
std::string aktstatus;
|
||||
int TimeUpdateIntervall;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@@ -10,6 +10,7 @@ ClassFlowMQTT::ClassFlowMQTT()
|
||||
{
|
||||
uri = "";
|
||||
topic = "";
|
||||
topicError = "";
|
||||
clientname = "watermeter";
|
||||
OldValue = "";
|
||||
flowpostprocessing = NULL;
|
||||
@@ -21,6 +22,7 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
|
||||
{
|
||||
uri = "";
|
||||
topic = "";
|
||||
topicError = "";
|
||||
clientname = "watermeter";
|
||||
OldValue = "";
|
||||
flowpostprocessing = NULL;
|
||||
@@ -71,6 +73,10 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
{
|
||||
this->topic = zerlegt[1];
|
||||
}
|
||||
if ((toUpper(zerlegt[0]) == "TOPICERROR") && (zerlegt.size() > 1))
|
||||
{
|
||||
this->topicError = zerlegt[1];
|
||||
}
|
||||
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
|
||||
{
|
||||
this->clientname = zerlegt[1];
|
||||
@@ -90,11 +96,13 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
{
|
||||
std::string result;
|
||||
std::string resulterror = "";
|
||||
string zw = "";
|
||||
|
||||
if (flowpostprocessing)
|
||||
{
|
||||
result = flowpostprocessing->getReadoutParam(false, true);
|
||||
resulterror = flowpostprocessing->getReadoutError();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,9 +118,13 @@ bool ClassFlowMQTT::doFlow(string zwtime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MQTTPublish(topic, result);
|
||||
|
||||
if (topicError.length() > 0) {
|
||||
MQTTPublish(topicError, resulterror);
|
||||
}
|
||||
|
||||
OldValue = result;
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class ClassFlowMQTT :
|
||||
public ClassFlow
|
||||
{
|
||||
protected:
|
||||
std::string uri, topic, clientname;
|
||||
std::string uri, topic, topicError, clientname;
|
||||
std::string OldValue;
|
||||
ClassFlowPostProcessing* flowpostprocessing;
|
||||
std::string user, password;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
string ClassFlowPostProcessing::GetPreValue()
|
||||
{
|
||||
std::string result;
|
||||
result = to_string(PreValue);
|
||||
result = RundeOutput(PreValue, -DecimalShift);
|
||||
|
||||
for (int i = 0; i < ListFlowControll->size(); ++i)
|
||||
{
|
||||
@@ -130,6 +130,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing()
|
||||
useMaxRateValue = false;
|
||||
checkDigitIncreaseConsistency = false;
|
||||
DecimalShift = 0;
|
||||
ErrorMessageText = "";
|
||||
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
||||
}
|
||||
|
||||
@@ -145,6 +146,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
|
||||
useMaxRateValue = false;
|
||||
checkDigitIncreaseConsistency = false;
|
||||
DecimalShift = 0;
|
||||
ErrorMessageText = "";
|
||||
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
|
||||
ListFlowControll = lfc;
|
||||
}
|
||||
@@ -263,9 +265,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
bool isanalog = false;
|
||||
int AnzahlAnalog = 0;
|
||||
string zw;
|
||||
string error = "";
|
||||
time_t imagetime = 0;
|
||||
|
||||
ErrorMessageText = "";
|
||||
|
||||
for (int i = 0; i < ListFlowControll->size(); ++i)
|
||||
{
|
||||
if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
|
||||
@@ -344,24 +347,24 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
|
||||
if ((!AllowNegativeRates) && (Value < PreValue))
|
||||
{
|
||||
error = error + "Negative Rate - Returned old value - read value: " + zwvalue + " ";
|
||||
ErrorMessageText = ErrorMessageText + "Negative Rate - Returned old value - read value: " + zwvalue + " ";
|
||||
Value = PreValue;
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
}
|
||||
|
||||
if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue))
|
||||
{
|
||||
error = error + "Rate too high - Returned old value - read value: " + zwvalue + " ";
|
||||
ErrorMessageText = ErrorMessageText + "Rate too high - Returned old value - read value: " + zwvalue + " ";
|
||||
Value = PreValue;
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
}
|
||||
|
||||
ReturnValueNoError = zwvalue;
|
||||
ReturnValue = zwvalue;
|
||||
if (ErrorMessage && (error.length() > 0))
|
||||
ReturnValue = ReturnValue + "\t" + error;
|
||||
if (ErrorMessage && (ErrorMessageText.length() > 0))
|
||||
ReturnValue = ReturnValue + "\t" + ErrorMessageText;
|
||||
|
||||
if (error.length() == 0)
|
||||
if (ErrorMessageText.length() == 0)
|
||||
{
|
||||
PreValue = Value;
|
||||
SavePreValue(Value, zwtime);
|
||||
@@ -471,3 +474,9 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
string ClassFlowPostProcessing::getReadoutError()
|
||||
{
|
||||
return ErrorMessageText;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ protected:
|
||||
string ReturnRawValue; // Rohwert (mit N & führenden 0)
|
||||
string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
|
||||
string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung
|
||||
string ErrorMessageText; // Fehlermeldung bei Consistency Check
|
||||
|
||||
bool LoadPreValue(void);
|
||||
string ShiftDecimal(string in, int _decShift);
|
||||
@@ -39,6 +40,7 @@ public:
|
||||
bool doFlow(string time);
|
||||
string getReadout();
|
||||
string getReadoutParam(bool _rawValue, bool _noerror);
|
||||
string getReadoutError();
|
||||
void SavePreValue(float value, string time = "");
|
||||
string GetPreValue();
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES tfmicro)
|
||||
REQUIRES tfmicro jomjol_logfile)
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
// #include "protocol_examples_common.h"
|
||||
#include "esp_sntp.h"
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
static const char *TAG = "sntp";
|
||||
|
||||
RTC_DATA_ATTR int boot_count = 0;
|
||||
@@ -56,8 +58,8 @@ std::string gettimestring(const char * frm)
|
||||
}
|
||||
char strftime_buf[64];
|
||||
|
||||
setenv("TZ", "UTC-2", 1);
|
||||
tzset();
|
||||
// setenv("TZ", "UTC-2", 1);
|
||||
// tzset();
|
||||
localtime_r(&now, &timeinfo);
|
||||
strftime(strftime_buf, sizeof(strftime_buf), frm, &timeinfo);
|
||||
|
||||
@@ -65,7 +67,7 @@ std::string gettimestring(const char * frm)
|
||||
return result;
|
||||
}
|
||||
|
||||
void setup_time(void)
|
||||
void setup_time()
|
||||
{
|
||||
++boot_count;
|
||||
ESP_LOGI(TAG, "Boot count: %d", boot_count);
|
||||
@@ -84,10 +86,10 @@ void setup_time(void)
|
||||
}
|
||||
char strftime_buf[64];
|
||||
|
||||
// Set timezone to Berlin Standard Time
|
||||
setenv("TZ", "UTC+9", 1);
|
||||
// setenv("TZ", "Europe/Berlin", 1);
|
||||
tzset();
|
||||
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);
|
||||
ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf);
|
||||
@@ -96,14 +98,22 @@ void setup_time(void)
|
||||
ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf);
|
||||
|
||||
std::string zw = gettimestring("%Y%m%d-%H%M%S");
|
||||
printf("time %s\n", zw.c_str());
|
||||
printf("timeist %s\n", zw.c_str());
|
||||
}
|
||||
|
||||
void setTimeZone(std::string _tzstring)
|
||||
{
|
||||
setenv("TZ", _tzstring.c_str(), 1);
|
||||
tzset();
|
||||
printf("TimeZone set to %s\n", _tzstring.c_str());
|
||||
_tzstring = "Time zone set to " + _tzstring;
|
||||
LogFile.WriteToFile(_tzstring);
|
||||
}
|
||||
|
||||
static void obtain_time(void)
|
||||
{
|
||||
// initialize_sntp();
|
||||
|
||||
|
||||
// wait for time to be set
|
||||
time_t now = 0;
|
||||
struct tm timeinfo = {};
|
||||
@@ -113,6 +123,14 @@ 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);
|
||||
}
|
||||
@@ -125,3 +143,32 @@ static void initialize_sntp(void)
|
||||
sntp_set_time_sync_notification_cb(time_sync_notification_cb);
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
|
||||
void task_doTimeSync(void *pvParameter)
|
||||
{
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
char strftime_buf[64];
|
||||
int *zw_int = (int*) pvParameter;
|
||||
|
||||
printf("Start Autoupdate Time every: %d Stunden\n", *zw_int );
|
||||
TickType_t xDelay = ((*zw_int) * 60 * 60 * 1000) / portTICK_PERIOD_MS;
|
||||
|
||||
while (1)
|
||||
{
|
||||
obtain_time();
|
||||
localtime_r(&now, &timeinfo);
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf);
|
||||
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d_%H:%M", &timeinfo);
|
||||
ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf);
|
||||
|
||||
std::string zw = gettimestring("%Y%m%d-%H%M%S");
|
||||
printf("time %s\n", zw.c_str());
|
||||
|
||||
vTaskDelay( xDelay );
|
||||
}
|
||||
vTaskDelete(NULL); //Delete this task if it exits from the loop above
|
||||
}
|
||||
@@ -17,4 +17,6 @@ extern int boot_count;
|
||||
|
||||
void setup_time(void);
|
||||
|
||||
std::string gettimestring(const char * frm);
|
||||
std::string gettimestring(const char * frm);
|
||||
void task_doTimeSync(void *pvParameter);
|
||||
void setTimeZone(std::string _tzstring);
|
||||
@@ -1,4 +1,4 @@
|
||||
const char* GIT_REV="891adf3";
|
||||
const char* GIT_REV="1b5f6b4";
|
||||
const char* GIT_TAG="";
|
||||
const char* GIT_BRANCH="rolling";
|
||||
const char* BUILD_TIME="2020-11-29 15:14";
|
||||
const char* BUILD_TIME="2020-11-30 12:06";
|
||||
@@ -1,4 +1,4 @@
|
||||
const char* GIT_REV="891adf3";
|
||||
const char* GIT_REV="1b5f6b4";
|
||||
const char* GIT_TAG="";
|
||||
const char* GIT_BRANCH="rolling";
|
||||
const char* BUILD_TIME="2020-11-29 15:14";
|
||||
const char* BUILD_TIME="2020-11-30 12:06";
|
||||
Reference in New Issue
Block a user