Rolling 20210506v2

This commit is contained in:
jomjol
2021-05-06 21:50:14 +02:00
parent 016f4088d4
commit d36cbde7aa
16 changed files with 104 additions and 14 deletions

View File

@@ -11,6 +11,8 @@ void ClassFlowMQTT::SetInitialParameter(void)
uri = "";
topic = "";
topicError = "";
topicRate = "";
topicTimeStamp = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
@@ -94,6 +96,15 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->topicError = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "TOPICRATE") && (zerlegt.size() > 1))
{
this->topicRate = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "TOPICTIMESTAMP") && (zerlegt.size() > 1))
{
this->topicTimeStamp = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
this->clientname = zerlegt[1];
@@ -114,12 +125,16 @@ bool ClassFlowMQTT::doFlow(string zwtime)
{
std::string result;
std::string resulterror = "";
std::string resultrate = "";
std::string resulttimestamp = "";
string zw = "";
if (flowpostprocessing)
{
result = flowpostprocessing->getReadoutParam(false, true);
resulterror = flowpostprocessing->getReadoutError();
resultrate = flowpostprocessing->getReadoutRate();
resulttimestamp = flowpostprocessing->getReadoutTimeStamp();
}
else
{
@@ -142,6 +157,14 @@ bool ClassFlowMQTT::doFlow(string zwtime)
MQTTPublish(topicError, resulterror);
}
if (topicRate.length() > 0) {
MQTTPublish(topicRate, resultrate);
}
if (topicRate.length() > 0) {
MQTTPublish(topicTimeStamp, resulttimestamp);
}
OldValue = result;
return true;

View File

@@ -9,7 +9,7 @@ class ClassFlowMQTT :
public ClassFlow
{
protected:
std::string uri, topic, topicError, clientname;
std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;

View File

@@ -74,10 +74,9 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
tStart = mktime(&whenStart);
time_t now;
time(&now);
localtime(&now);
double difference = difftime(now, tStart);
time(&lastvalue);
localtime(&lastvalue);
double difference = difftime(lastvalue, tStart);
difference /= 60;
if (difference > PreValueAgeStartup)
return false;
@@ -123,12 +122,16 @@ void ClassFlowPostProcessing::SavePreValue(float value, string zwtime)
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%Y-%m-%d_%H-%M-%S", timeinfo);
zwtime = std::string(buffer);
timeStamp = std::string(buffer);
}
else
{
timeStamp = zwtime;
}
PreValue = value;
fputs(zwtime.c_str(), pFile);
fputs(timeStamp.c_str(), pFile);
fputs("\n", pFile);
fputs(to_string(value).c_str(), pFile);
fputs("\n", pFile);
@@ -139,6 +142,7 @@ void ClassFlowPostProcessing::SavePreValue(float value, string zwtime)
ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
{
FlowRateAct = 0;
PreValueUse = false;
PreValueAgeStartup = 30;
AllowNegativeRates = false;
@@ -150,6 +154,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
checkDigitIncreaseConsistency = false;
DecimalShift = 0;
ErrorMessageText = "";
timeStamp = "";
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
ListFlowControll = lfc;
}
@@ -343,12 +348,15 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
PreValueOkay = true;
PreValue = Value;
time(&lastvalue);
localtime(&lastvalue);
SavePreValue(Value, zwtime);
}
return true;
}
zw = ErsetzteN(ReturnRawValue);
Value = std::stof(zw);
@@ -359,6 +367,14 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
time_t currenttime;
time(&currenttime);
localtime(&currenttime);
double difference = difftime(currenttime, lastvalue); // in Sekunden
difference /= 60; // in Minuten
FlowRateAct = (Value - PreValue) / difference;
if ((!AllowNegativeRates) && (Value < PreValue))
{
ErrorMessageText = ErrorMessageText + "Negative Rate - Returned old value - read value: " + zwvalue + " - raw value: " + ReturnRawValue + " - checked value: " + std::to_string(Value) + " ";
@@ -506,6 +522,16 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
return input;
}
string ClassFlowPostProcessing::getReadoutRate()
{
return std::to_string(FlowRateAct);
}
string ClassFlowPostProcessing::getReadoutTimeStamp()
{
return timeStamp;
}
string ClassFlowPostProcessing::getReadoutError()
{

View File

@@ -17,6 +17,9 @@ protected:
bool PreValueOkay;
bool checkDigitIncreaseConsistency;
int DecimalShift;
time_t lastvalue;
float FlowRateAct; // m3 / min
string FilePreValue;
float PreValue; // letzter Wert, der gut ausgelesen wurde
@@ -25,6 +28,7 @@ protected:
string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung
string ErrorMessageText; // Fehlermeldung bei Consistency Check
string timeStamp;
bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);
@@ -40,6 +44,8 @@ public:
string getReadout();
string getReadoutParam(bool _rawValue, bool _noerror);
string getReadoutError();
string getReadoutRate();
string getReadoutTimeStamp();
void SavePreValue(float value, string time = "");
string GetPreValue();