Compare commits

...

19 Commits

Author SHA1 Message Date
jomjol
8f518954aa Update to v3.0.0 2020-10-14 18:46:46 +02:00
jomjol
26144815d2 Merge pull request #35 from jomjol/rolling
Rolling
2020-10-14 18:27:49 +02:00
jomjol
21d07be7df Update 20201013 2020-10-13 20:13:28 +02:00
jomjol
04f69f0853 Update README.md 2020-10-04 08:23:26 +02:00
jomjol
0678c81959 Update config.ini 2020-10-04 08:22:23 +02:00
jomjol
70a88088f2 Rolling 2020-10-04
Initial MQTT
2020-10-04 08:09:59 +02:00
jomjol
f8e8c756ab nightly 20200929 2020-09-29 19:13:16 +02:00
jomjol
6e26fa6e3c Merge pull request #33 from phlupp/rolling
Add HTML Version / modify Sysinfo / move Sysinfo to server_main
2020-09-29 18:36:22 +02:00
Philipp Harsch
b54d6e785d modify Sysinfo 2020-09-29 02:54:18 +02:00
Philipp Harsch
5d2e22cd86 Add HTML Version 2020-09-29 02:25:49 +02:00
Philipp Harsch
ccd1d3f460 Add HTML Version 2020-09-29 02:08:59 +02:00
Philipp Harsch
964486a819 add html version 2020-09-29 00:15:12 +02:00
phlupp
9080f1d2f0 Merge pull request #3 from jomjol/rolling
Pull Rolling
2020-09-28 22:21:07 +02:00
jomjol
aab8dfcde5 Merge pull request #32 from jomjol/master
Update Rolling
2020-09-28 20:04:23 +02:00
jomjol
1633b74ab2 Update to v21.1 2020-09-28 20:03:38 +02:00
jomjol
bafd67be36 Merge pull request #31 from jomjol/rolling
Update README.md
2020-09-28 19:55:46 +02:00
jomjol
8f1d7d081d Update README.md 2020-09-28 19:55:17 +02:00
jomjol
66bfcd1d45 Merge branch 'rolling' into master 2020-09-28 19:53:49 +02:00
jomjol
d89438a15f Update to v2.1.1 2020-09-28 19:37:20 +02:00
30 changed files with 425 additions and 410 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -27,14 +27,28 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
##### Rolling - (2020-09-27) ##### Rolling - (2020-10-14)
* based on v2.2.0 (2020-09-27) * based on v3.0.0 (2020-10-14)
##### 3.0.0 MQTT-Client (2020-10-14)
* Implementation of MQTT Client
* Improved Version Control
* bug-fixing
##### 2.2.1 Version Control (2020-09-27)
* Bug-Fixing (hostname in wlan.ini and error handling inside flow)
##### 2.2.0 Version Controll (2020-09-27) ##### 2.2.0 Version Control (2020-09-27)
* Integrated automated versioning system (menu: SYSTEM --> INFO) * Integrated automated versioning system (menu: SYSTEM --> INFO)
* Update Build-System to PlatformIO - Espressif 32 v2.0.0 (ESP-IDF 4.1) * Update Build-System to PlatformIO - Espressif 32 v2.0.0 (ESP-IDF 4.1)

BIN
code/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -143,7 +143,6 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
char zw[1024]; char zw[1024];
fgets(zw, 1024, pFile); fgets(zw, 1024, pFile);
// printf("%s", zw);
line = std::string(zw); line = std::string(zw);
while ((line.size() > 0) || !(feof(pFile))) while ((line.size() > 0) || !(feof(pFile)))
@@ -151,21 +150,16 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
// printf("%s", line.c_str()); // printf("%s", line.c_str());
zerlegt = ZerlegeZeile(line, "="); zerlegt = ZerlegeZeile(line, "=");
zerlegt[0] = trim(zerlegt[0], " "); zerlegt[0] = trim(zerlegt[0], " ");
zerlegt[1] = trim(zerlegt[1], " ");
if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){ if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){
_hostname = zerlegt[1]; _hostname = trim(zerlegt[1]);
if ((_hostname[0] == '"') && (_hostname[_hostname.length()-1] == '"')){ if ((_hostname[0] == '"') && (_hostname[_hostname.length()-1] == '"')){
_hostname = _hostname.substr(1, _hostname.length()-2); _hostname = _hostname.substr(1, _hostname.length()-2);
} }
// Check if Hostname was empty in .ini if yes set to std_hostname
if(_hostname.length() <= 0){
_hostname = std_hostname;
}
} }
if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){ if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "SSID")){
_ssid = zerlegt[1]; _ssid = trim(zerlegt[1]);
if ((_ssid[0] == '"') && (_ssid[_ssid.length()-1] == '"')){ if ((_ssid[0] == '"') && (_ssid[_ssid.length()-1] == '"')){
_ssid = _ssid.substr(1, _ssid.length()-2); _ssid = _ssid.substr(1, _ssid.length()-2);
} }
@@ -189,6 +183,11 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
} }
fclose(pFile); fclose(pFile);
// Check if Hostname was empty in .ini if yes set to std_hostname
if(_hostname.length() <= 0){
_hostname = std_hostname;
}
} }

View File

@@ -12,6 +12,8 @@
#include "ClassLogFile.h" #include "ClassLogFile.h"
bool debugdetailanalog = false;
ClassFlowAnalog::ClassFlowAnalog() ClassFlowAnalog::ClassFlowAnalog()
{ {
isLogImage = false; isLogImage = false;
@@ -108,6 +110,7 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->posy = std::stoi(zerlegt[2]); neuroi->posy = std::stoi(zerlegt[2]);
neuroi->deltax = std::stoi(zerlegt[3]); neuroi->deltax = std::stoi(zerlegt[3]);
neuroi->deltay = std::stoi(zerlegt[4]); neuroi->deltay = std::stoi(zerlegt[4]);
neuroi->result = -1;
ROI.push_back(neuroi); ROI.push_back(neuroi);
} }
} }
@@ -146,6 +149,8 @@ bool ClassFlowAnalog::doFlow(string time)
return false; return false;
}; };
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doFlow nach Alignment");
doNeuralNetwork(time); doNeuralNetwork(time);
return true; return true;
@@ -166,7 +171,7 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
CAlignAndCutImage *caic = new CAlignAndCutImage(input); CAlignAndCutImage *caic = new CAlignAndCutImage(input);
if (!caic->ImageOkay()){ if (!caic->ImageOkay()){
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!"); if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
delete caic; delete caic;
return false; return false;
} }
@@ -174,7 +179,8 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
if (input_roi.length() > 0){ if (input_roi.length() > 0){
img_roi = new CImageBasis(input_roi); img_roi = new CImageBasis(input_roi);
if (!img_roi->ImageOkay()){ if (!img_roi->ImageOkay()){
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!"); if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
delete caic;
delete img_roi; delete img_roi;
return false; return false;
} }
@@ -188,6 +194,13 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
caic->CutAndSave(output, ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay); caic->CutAndSave(output, ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay);
rs = new CResizeImage(output); rs = new CResizeImage(output);
if (!rs->ImageOkay()){
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut CResizeImage(output);!");
delete caic;
delete rs;
return false;
}
rs->Resize(modelxsize, modelysize); rs->Resize(modelxsize, modelysize);
ioresize = "/sdcard/img_tmp/ra" + std::to_string(i) + ".bmp"; ioresize = "/sdcard/img_tmp/ra" + std::to_string(i) + ".bmp";
ioresize = FormatFileName(ioresize); ioresize = FormatFileName(ioresize);
@@ -246,8 +259,11 @@ bool ClassFlowAnalog::doNeuralNetwork(string time)
f1 = 0; f2 = 0; f1 = 0; f2 = 0;
#ifndef OHNETFLITE #ifndef OHNETFLITE
// LogFile.WriteToFile("ClassFlowAnalog::doNeuralNetwork vor CNN tflite->LoadInputImage(ioresize)");
tflite->LoadInputImage(ioresize); tflite->LoadInputImage(ioresize);
tflite->Invoke(); tflite->Invoke();
if (debugdetailanalog) LogFile.WriteToFile("Nach Invoke");
f1 = tflite->GetOutputValue(0); f1 = tflite->GetOutputValue(0);
f2 = tflite->GetOutputValue(1); f2 = tflite->GetOutputValue(1);

View File

@@ -1,294 +0,0 @@
#include "ClassFlowControll.h"
#include "ClassLogFile.h"
#include "time_sntp.h"
#include "Helper.h"
#include "server_ota.h"
std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
bool found = false;
std::string _classname = "";
std::string result = "";
if (_stepname.compare("[MakeImage]") == 0){
_classname = "ClassFlowMakeImage";
}
if (_stepname.compare("[Alignment]") == 0){
_classname = "ClassFlowAlignment";
}
if (_stepname.compare("[Digits]") == 0){
_classname = "ClassFlowDigit";
}
if (_stepname.compare("[Analog]") == 0){
_classname = "ClassFlowAnalog";
}
// std::string zw = "Classname: " + _classname + "\n";
// printf(zw.c_str());
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare(_classname) == 0){
// printf(FlowControll[i]->name().c_str()); printf("\n");
FlowControll[i]->doFlow("");
result = FlowControll[i]->getHTMLSingleStep(_host);
found = true;
}
return result;
}
std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
{
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare("ClassFlowDigit") == 0)
return ((ClassFlowDigit*) (FlowControll[i]))->GetHTMLInfo();
std::vector<HTMLInfo*> empty;
return empty;
}
std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
{
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare("ClassFlowAnalog") == 0)
return ((ClassFlowAnalog*) (FlowControll[i]))->GetHTMLInfo();
std::vector<HTMLInfo*> empty;
return empty;
}
void ClassFlowControll::SetInitialParameter(void)
{
AutoStart = false;
AutoIntervall = 10;
}
bool ClassFlowControll::isAutoStart(long &_intervall)
{
_intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
return AutoStart;
}
ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
{
ClassFlow* cfc = NULL;
_type = trim(_type);
if (_type.compare("[MakeImage]") == 0)
cfc = new ClassFlowMakeImage(&FlowControll);
if (_type.compare("[Alignment]") == 0)
cfc = new ClassFlowAlignment(&FlowControll);
if (_type.compare("[Analog]") == 0)
cfc = new ClassFlowAnalog(&FlowControll);
if (_type.compare("[Digits]") == 0)
cfc = new ClassFlowDigit(&FlowControll);
if (_type.compare("[PostProcessing]") == 0)
{
cfc = new ClassFlowPostProcessing(&FlowControll);
flowpostprocessing = (ClassFlowPostProcessing*) cfc;
}
if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
FlowControll.push_back(cfc);
if (_type.compare("[AutoTimer]") == 0)
cfc = this;
if (_type.compare("[Debug]") == 0)
cfc = this;
return cfc;
}
void ClassFlowControll::InitFlow(std::string config)
{
string line;
flowpostprocessing = NULL;
ClassFlow* cfc;
FILE* pFile;
config = FormatFileName(config);
pFile = fopen(config.c_str(), "r");
line = "";
char zw[1024];
if (pFile != NULL)
{
fgets(zw, 1024, pFile);
printf("%s", zw);
line = std::string(zw);
}
while ((line.size() > 0) && !(feof(pFile)))
{
cfc = CreateClassFlow(line);
if (cfc)
{
cfc->ReadParameter(pFile, line);
}
else
{
fgets(zw, 1024, pFile);
printf("%s", zw);
line = std::string(zw);
}
}
fclose(pFile);
}
std::string ClassFlowControll::getActStatus(){
return aktstatus;
}
bool ClassFlowControll::doFlow(string time)
{
bool result = true;
std::string zw_time;
int repeat = 0;
for (int i = 0; i < FlowControll.size(); ++i)
{
zw_time = gettimestring("%Y%m%d-%H%M%S");
aktstatus = zw_time + ": " + FlowControll[i]->name();
string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
LogFile.WriteToFile(zw);
if (!FlowControll[i]->doFlow(time)){
repeat++;
LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
i = -1; // Soll wieder bei i = 0 anfangen ==> komplett von vorne !!!
result = false;
if (repeat > 5) {
LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot");
doReboot();
// Schritt wurde 5x wiederholt --> reboot
}
}
else
{
result = true;
}
}
zw_time = gettimestring("%Y%m%d-%H%M%S");
aktstatus = zw_time + ": Flow is done";
return result;
}
string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
{
if (flowpostprocessing)
return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
string zw = "";
string result = "";
for (int i = 0; i < FlowControll.size(); ++i)
{
zw = FlowControll[i]->getReadout();
if (zw.length() > 0)
{
if (result.length() == 0)
result = zw;
else
result = result + "\t" + zw;
}
}
return result;
}
string ClassFlowControll::GetPrevalue()
{
if (flowpostprocessing)
{
return flowpostprocessing->GetPreValue();
}
return std::string();
}
std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
{
float zw;
char* p;
_newvalue = trim(_newvalue);
// printf("Input UpdatePreValue: %s\n", _newvalue.c_str());
if (_newvalue.compare("0.0") == 0)
{
zw = 0;
}
else
{
zw = strtof(_newvalue.c_str(), &p);
if (zw == 0)
return "- Error in String to Value Conversion!!! Must be of format value=123.456";
}
if (flowpostprocessing)
{
flowpostprocessing->SavePreValue(zw);
return to_string(zw);
}
return std::string();
}
bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph)){
return false;
}
// if ((aktparamgraph.compare("[Autotimer]") != 0) && (aktparamgraph.compare("[Debug]") != 0)) // Paragraph passt nich zu MakeImage
if (aktparamgraph.compare("[Autotimer]") != 0) // Paragraph passt nich zu MakeImage
return false;
// if ((toUpper(aktparamgraph) != "[AUTOTIMER]") && (toUpper(aktparamgraph) != ("[DEBUG]"))) // Paragraph passt nich zu MakeImage
// return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = this->ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
AutoStart = true;
}
}
if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
{
AutoIntervall = std::stof(zerlegt[1]);
}
/*
if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
LogFile.SwitchOnOff(true);
printf("TurnLogFile On\n");
}
if (toUpper(zerlegt[1]) == "FALSE")
{
LogFile.SwitchOnOff(false);
printf("TurnLogFile Off\n");
}
}
*/
}
return true;
}

View File

@@ -20,6 +20,9 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _
if (_stepname.compare("[Analog]") == 0){ if (_stepname.compare("[Analog]") == 0){
_classname = "ClassFlowAnalog"; _classname = "ClassFlowAnalog";
} }
if (_stepname.compare("[MQTT]") == 0){
_classname = "ClassFlowMQTT";
}
// std::string zw = "Classname: " + _classname + "\n"; // std::string zw = "Classname: " + _classname + "\n";
// printf(zw.c_str()); // printf(zw.c_str());
@@ -80,6 +83,8 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
cfc = new ClassFlowAnalog(&FlowControll); cfc = new ClassFlowAnalog(&FlowControll);
if (toUpper(_type).compare("[DIGITS]") == 0) if (toUpper(_type).compare("[DIGITS]") == 0)
cfc = new ClassFlowDigit(&FlowControll); cfc = new ClassFlowDigit(&FlowControll);
if (toUpper(_type).compare("[MQTT]") == 0)
cfc = new ClassFlowMQTT(&FlowControll);
if (toUpper(_type).compare("[POSTPROCESSING]") == 0) if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
{ {
cfc = new ClassFlowPostProcessing(&FlowControll); cfc = new ClassFlowPostProcessing(&FlowControll);
@@ -157,7 +162,7 @@ bool ClassFlowControll::doFlow(string time)
if (!FlowControll[i]->doFlow(time)){ if (!FlowControll[i]->doFlow(time)){
repeat++; repeat++;
LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt"); LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
i = i-2; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen) i = -1; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
result = false; result = false;
if (repeat > 5) { if (repeat > 5) {
LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot"); LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot");

View File

@@ -8,6 +8,7 @@
#include "ClassFlowDigit.h" #include "ClassFlowDigit.h"
#include "ClassFlowAnalog.h" #include "ClassFlowAnalog.h"
#include "ClassFlowPostProcessing.h" #include "ClassFlowPostProcessing.h"
#include "ClassFlowMQTT.h"
class ClassFlowControll : class ClassFlowControll :

View File

@@ -86,6 +86,7 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->posy = std::stoi(zerlegt[2]); neuroi->posy = std::stoi(zerlegt[2]);
neuroi->deltax = std::stoi(zerlegt[3]); neuroi->deltax = std::stoi(zerlegt[3]);
neuroi->deltay = std::stoi(zerlegt[4]); neuroi->deltay = std::stoi(zerlegt[4]);
neuroi->resultklasse = -1;
ROI.push_back(neuroi); ROI.push_back(neuroi);
} }
} }
@@ -152,7 +153,8 @@ bool ClassFlowDigit::doAlignAndCut(string time)
if (input_roi.length() > 0){ if (input_roi.length() > 0){
img_roi = new CImageBasis(input_roi); img_roi = new CImageBasis(input_roi);
if (!img_roi->ImageOkay()){ if (!img_roi->ImageOkay()){
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!"); LogFile.WriteToFile("ClassFlowDigit::doAlignAndCut ImageRoi not okay!");
delete caic;
delete img_roi; delete img_roi;
return false; return false;
} }

View File

@@ -0,0 +1,122 @@
#include "ClassFlowMQTT.h"
#include "Helper.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
#include <time.h>
static const char* TAG2 = "example";
ClassFlowMQTT::ClassFlowMQTT()
{
uri = "";
topic = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
user = "";
password = "";
}
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
{
uri = "";
topic = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
user = "";
password = "";
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = this->ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
{
this->user = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "PASSWORD") && (zerlegt.size() > 1))
{
this->password = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
{
this->uri = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "TOPIC") && (zerlegt.size() > 1))
{
this->topic = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
this->clientname = zerlegt[1];
}
}
if ((uri.length() > 0) && (topic.length() > 0))
{
MQTTInit(uri, clientname, user, password);
}
return true;
}
bool ClassFlowMQTT::doFlow(string zwtime)
{
std::string result;
string zw = "";
if (flowpostprocessing)
{
result = flowpostprocessing->getReadoutParam(false, true);
}
else
{
for (int i = 0; i < ListFlowControll->size(); ++i)
{
zw = (*ListFlowControll)[i]->getReadout();
if (zw.length() > 0)
{
if (result.length() == 0)
result = zw;
else
result = result + "\t" + zw;
}
}
}
MQTTPublish(topic, result);
OldValue = result;
return true;
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowPostProcessing.h"
#include <string>
class ClassFlowMQTT :
public ClassFlow
{
protected:
std::string uri, topic, clientname;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;
public:
ClassFlowMQTT();
ClassFlowMQTT(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string name(){return "ClassFlowMQTT";};
};

View File

@@ -391,11 +391,11 @@ CImageBasis::CImageBasis(std::string _image)
channels = 3; channels = 3;
externalImage = false; externalImage = false;
filename = _image; filename = _image;
long freebefore = esp_get_free_heap_size(); // long freebefore = esp_get_free_heap_size();
rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels); rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels);
if (rgb_image == NULL) // if (rgb_image == NULL)
LogFile.WriteToFile("Image Load failed:" + _image + " FreeHeapSize before: " + to_string(freebefore) + " after: " + to_string(esp_get_free_heap_size())); // LogFile.WriteToFile("Image Load failed:" + _image + " FreeHeapSize before: " + to_string(freebefore) + " after: " + to_string(esp_get_free_heap_size()));
// printf("CImageBasis after load\n"); // printf("CImageBasis after load\n");
// printf("w %d, h %d, b %d, c %d", this->width, this->height, this->bpp, this->channels); // printf("w %d, h %d, b %d, c %d", this->width, this->height, this->bpp, this->channels);
} }

View File

@@ -0,0 +1,82 @@
#include "interface_mqtt.h"
#include "esp_log.h"
#include "mqtt_client.h"
#include "ClassLogFile.h"
static const char *TAG = "interface_mqtt";
bool debugdetail = true;
// #define CONFIG_BROKER_URL "mqtt://192.168.178.43:1883"
esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
bool mqtt_connected = false;
esp_mqtt_client_handle_t client = NULL;
void MQTTPublish(std::string _key, std::string _content){
if (client && mqtt_connected) {
int msg_id;
std::string zw;
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, 0);
zw = "sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
if (debugdetail) LogFile.WriteToFile(zw);
ESP_LOGI(TAG, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
}
else {
ESP_LOGI(TAG, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
}
}
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
{
switch (event->event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
mqtt_connected = true;
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
break;
default:
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
}
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password){
esp_mqtt_client_config_t mqtt_cfg = {
.uri = _mqttURI.c_str(),
.client_id = _clientid.c_str(),
};
if (_user.length() && _password.length()){
mqtt_cfg.username = _user.c_str();
mqtt_cfg.password = _password.c_str();
printf("Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
};
client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
esp_mqtt_client_start(client);
}

View File

@@ -0,0 +1,4 @@
#include <string>
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = "");
void MQTTPublish(std::string _key, std::string _content);

View File

@@ -2,8 +2,12 @@
#include "bitmap_image.hpp" #include "bitmap_image.hpp"
#include "ClassLogFile.h"
#include <sys/stat.h> #include <sys/stat.h>
bool debugdetailtflite = false;
float CTfLiteClass::GetOutputValue(int nr) float CTfLiteClass::GetOutputValue(int nr)
{ {
TfLiteTensor* output2 = this->interpreter->output(0); TfLiteTensor* output2 = this->interpreter->output(0);
@@ -109,7 +113,11 @@ void CTfLiteClass::Invoke()
bool CTfLiteClass::LoadInputImage(std::string _fn) bool CTfLiteClass::LoadInputImage(std::string _fn)
{ {
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach Load Image: " + _fn;
// LogFile.WriteToFile(zw);
bitmap_image image(_fn); bitmap_image image(_fn);
if (debugdetailtflite) LogFile.WriteToFile(zw);
unsigned int w = image.width(); unsigned int w = image.width();
unsigned int h = image.height(); unsigned int h = image.height();
unsigned char red, green, blue; unsigned char red, green, blue;
@@ -135,6 +143,9 @@ bool CTfLiteClass::LoadInputImage(std::string _fn)
// printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue); // printf("BMP: %f %f %f\n", (float) red, (float) green, (float) blue);
} }
if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
return true; return true;
} }

View File

@@ -23,7 +23,7 @@ board_build.embed_files =
;board_build.partitions = partitions_singleapp.csv ;board_build.partitions = partitions_singleapp.csv
board_build.partitions = partition.csv board_build.partitions = partition.csv
lib_deps = jomjol_helper, connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile lib_deps = jomjol_helper, connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile, jomjol_mqtt
monitor_speed = 115200 monitor_speed = 115200
debug_tool = esp-prog debug_tool = esp-prog

View File

@@ -5,63 +5,26 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "sdkconfig.h" #include "sdkconfig.h"
//#include "version.h"
// SD-Card ////////////////////
#include "nvs_flash.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include "driver/sdmmc_defs.h"
///////////////////////////////
#include "ClassLogFile.h" #include "ClassLogFile.h"
//#include "esp_wifi.h"
//#include "protocol_examples_common.h"
#include "connect_wlan.h" #include "connect_wlan.h"
#include <esp_http_server.h>
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_log.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "esp_err.h"
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
#include "server_main.h"
#include "server_camera.h"
#include "server_tflite.h" #include "server_tflite.h"
#include "server_file.h" #include "server_file.h"
#include "server_ota.h" #include "server_ota.h"
#include "time_sntp.h" #include "time_sntp.h"
#include "ClassControllCamera.h" #include "ClassControllCamera.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "freertos/FreeRTOS.h"
// SD-Card
#include "nvs_flash.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "server_main.h" #include "server_main.h"
#include "server_camera.h" #include "server_camera.h"
#include "ClassControllCamera.h"
#include "connect_wlan.h"
#include "time_sntp.h"
static const char *TAGMAIN = "connect_wlan_main"; static const char *TAGMAIN = "connect_wlan_main";
@@ -130,7 +93,7 @@ extern "C" void app_main()
vTaskDelay( xDelay ); vTaskDelay( xDelay );
// LogFile.WriteToFile("Startsequence 07"); // LogFile.WriteToFile("Startsequence 07");
setup_time(); setup_time();
LogFile.WriteToFile("======================== Main Started ================================"); LogFile.WriteToFile("============================== Main Started =======================================");
LogFile.SwitchOnOff(false); LogFile.SwitchOnOff(false);
std::string zw = gettimestring("%Y%m%d-%H%M%S"); std::string zw = gettimestring("%Y%m%d-%H%M%S");

View File

@@ -9,6 +9,8 @@
#include "version.h" #include "version.h"
#include "esp_wifi.h"
httpd_handle_t server = NULL; httpd_handle_t server = NULL;
@@ -83,6 +85,14 @@ esp_err_t info_get_handler(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
if (_task.compare("HTMLVersion") == 0)
{
std::string zw;
zw = std::string(getHTMLversion());
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
}
return ESP_OK; return ESP_OK;
} }
@@ -155,8 +165,6 @@ esp_err_t hello_main_handler(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
esp_err_t img_tmp_handler(httpd_req_t *req) esp_err_t img_tmp_handler(httpd_req_t *req)
{ {
char filepath[50]; char filepath[50];
@@ -197,7 +205,45 @@ esp_err_t img_tmp_handler(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
esp_err_t sysinfo_handler(httpd_req_t *req)
{
const char* resp_str;
std::string zw;
std::string cputemp = std::to_string(temperatureRead());
std::string gitversion = libfive_git_version();
std::string buildtime = build_time();
std::string gitbranch = libfive_git_branch();
std::string gitbasebranch = git_base_branch();
std::string htmlversion = getHTMLversion();
tcpip_adapter_ip_info_t ip_info;
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
const char *hostname;
ESP_ERROR_CHECK(tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname));
zw = "[\
{\
\"firmware\" : \"" + gitversion + "\",\
\"buildtime\" : \"" + buildtime + "\",\
\"gitbranch\" : \"" + gitbranch + "\",\
\"gitbasebranch\" : \"" + gitbasebranch + "\",\
\"html\" : \"" + htmlversion + "\",\
\"cputemp\" : \"" + cputemp + "\",\
\"hostname\" : \"" + hostname + "\",\
\"IPv4\" : \"" + ip4addr_ntoa(&ip_info.ip) + "\"\
}\
]";
resp_str = zw.c_str();
httpd_resp_set_type(req, "application/json");
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
void register_server_main_uri(httpd_handle_t server, const char *base_path) void register_server_main_uri(httpd_handle_t server, const char *base_path)
{ {
@@ -209,6 +255,13 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
}; };
httpd_register_uri_handler(server, &info_get_handle); httpd_register_uri_handler(server, &info_get_handle);
httpd_uri_t sysinfo_handle = {
.uri = "/sysinfo", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = sysinfo_handler,
.user_ctx = (void*) base_path // Pass server data as context
};
httpd_register_uri_handler(server, &sysinfo_handle);
httpd_uri_t starttime_tmp_handle = { httpd_uri_t starttime_tmp_handle = {
.uri = "/starttime", // Match all URIs of type /path/to/file .uri = "/starttime", // Match all URIs of type /path/to/file
@@ -235,6 +288,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
.user_ctx = (void*) base_path // Pass server data as context .user_ctx = (void*) base_path // Pass server data as context
}; };
httpd_register_uri_handler(server, &main_rest_handle); httpd_register_uri_handler(server, &main_rest_handle);
} }

View File

@@ -410,36 +410,6 @@ esp_err_t handler_prevalue(httpd_req_t *req)
return ESP_OK; return ESP_OK;
}; };
esp_err_t handler_sysinfo(httpd_req_t *req)
{
LogFile.WriteToFile("handler_sysinfo");
const char* resp_str;
string zw;
string cputemp = std::to_string(temperatureRead());
zw = "[\
{\
\"firmware\" : \"2.0.0\",\
\"html\" : \"1.0.1\",\
\"cputemp\" : \"" + cputemp + "\",\
\"hostname\" : \"host\",\
\"IPv4\" : \"IP\"\
}\
]";
resp_str = zw.c_str();
httpd_resp_set_type(req, "application/json");
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
};
void task_autodoFlow(void *pvParameter) void task_autodoFlow(void *pvParameter)
{ {
int64_t fr_start, fr_delta_ms; int64_t fr_start, fr_delta_ms;
@@ -468,7 +438,10 @@ void task_autodoFlow(void *pvParameter)
LogFile.WriteToFile("task_autodoFlow - round done"); LogFile.WriteToFile("task_autodoFlow - round done");
//CPU Temp //CPU Temp
float cputmp = temperatureRead(); float cputmp = temperatureRead();
LogFile.WriteToFile("CPU Temperature: %.2f", cputmp); std::stringstream stream;
stream << std::fixed << std::setprecision(1) << cputmp;
string zwtemp = "CPU Temperature: " + stream.str();
LogFile.WriteToFile(zwtemp);
printf("CPU Temperature: %.2f\n", cputmp); printf("CPU Temperature: %.2f\n", cputmp);
fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000; fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS; const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS;
@@ -519,8 +492,4 @@ void register_server_tflite_uri(httpd_handle_t server)
camuri.user_ctx = (void*) "Wasserzaehler"; camuri.user_ctx = (void*) "Wasserzaehler";
httpd_register_uri_handler(server, &camuri); httpd_register_uri_handler(server, &camuri);
camuri.uri = "/sysinfo";
camuri.handler = handler_sysinfo;
camuri.user_ctx = (void*) "Sysinfo";
httpd_register_uri_handler(server, &camuri);
} }

View File

@@ -1,4 +1,4 @@
const char* GIT_REV="67115dd"; const char* GIT_REV="2614481";
const char* GIT_TAG=""; const char* GIT_TAG="";
const char* GIT_BRANCH="master"; const char* GIT_BRANCH="master";
const char* BUILD_TIME="2020-09-27 08:24"; const char* BUILD_TIME="2020-10-14 18:40";

View File

@@ -8,7 +8,12 @@ extern "C"
extern const char* BUILD_TIME; extern const char* BUILD_TIME;
} }
const char* GIT_BASE_BRANCH = "master - v2.1.0 - 2020-09-25"; #include <string>
#include <string.h>
#include "Helper.h"
#include <fstream>
const char* GIT_BASE_BRANCH = "master - v3.0.0 - 2020-10-14";
const char* git_base_branch(void) const char* git_base_branch(void)
@@ -36,3 +41,22 @@ const char* libfive_git_branch(void)
{ {
return GIT_BRANCH; return GIT_BRANCH;
} }
std::string getHTMLversion(void){
string line = "";
FILE* pFile;
string fn = FormatFileName("/sdcard/html/version.txt");
pFile = fopen(fn.c_str(), "r");
if (pFile == NULL)
return std::string("NAN");
char zw[1024];
fgets(zw, 1024, pFile);
line = std::string(trim(zw));
fclose(pFile);
return line;
}

View File

@@ -1,4 +1,4 @@
const char* GIT_REV="67115dd"; const char* GIT_REV="2614481";
const char* GIT_TAG=""; const char* GIT_TAG="";
const char* GIT_BRANCH="master"; const char* GIT_BRANCH="master";
const char* BUILD_TIME="2020-09-27 08:24"; const char* BUILD_TIME="2020-10-14 18:40";

BIN
firmware/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
sd-card/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -38,6 +38,12 @@ MaxRateValue = 0.1
ErrorMessage = True ErrorMessage = True
CheckDigitIncreaseConsistency = False CheckDigitIncreaseConsistency = False
;[MQTT]
;Uri = mqtt://IP-MQTT-SERVER:1883
;Topic = watermeter/readout
;ClientID = wasser
;user = USERNAME
;password = PASSWORD
[AutoTimer] [AutoTimer]
AutoStart= True AutoStart= True

View File

@@ -71,6 +71,17 @@ div {
<object data="/version?type=BuildTime"></object> <object data="/version?type=BuildTime"></object>
</div> </div>
</td> </td>
</tr>
<tr>
<td>
HTML Version:
</td>
<td>
<div>
<object data="/version?type=HTMLVersion"></object>
</div>
</td>
</tr> </tr>
</table> </table>

1
sd-card/html/version.txt Normal file
View File

@@ -0,0 +1 @@
1.0.0