mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 04:26:58 +03:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05a0f6fa62 | ||
|
|
2ab2f070b4 | ||
|
|
103de2011b | ||
|
|
3cec93e2f1 | ||
|
|
a23d7ee6e2 | ||
|
|
42afbcf655 | ||
|
|
c61167bdfa | ||
|
|
642cefb84f | ||
|
|
1223aa7c70 | ||
|
|
0d90977917 | ||
|
|
7e57e85e75 | ||
|
|
8f518954aa | ||
|
|
26144815d2 | ||
|
|
21d07be7df | ||
|
|
04f69f0853 | ||
|
|
0678c81959 | ||
|
|
70a88088f2 | ||
|
|
f8e8c756ab | ||
|
|
6e26fa6e3c | ||
|
|
b54d6e785d | ||
|
|
5d2e22cd86 | ||
|
|
ccd1d3f460 | ||
|
|
964486a819 | ||
|
|
9080f1d2f0 | ||
|
|
aab8dfcde5 | ||
|
|
1633b74ab2 | ||
|
|
bafd67be36 | ||
|
|
8f1d7d081d | ||
|
|
66bfcd1d45 | ||
|
|
d89438a15f |
29
README.md
29
README.md
@@ -25,16 +25,37 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
|
||||
|
||||
**General remark:** Beside the `firmware.bin`, typically also the content of `/html` needs to be updated!
|
||||
|
||||
##### Rolling - (2020-11-03)
|
||||
|
||||
* Bug-Fix in time sync on warm reboot
|
||||
|
||||
##### Rolling - (2020-09-27)
|
||||
|
||||
* based on v2.2.0 (2020-09-27)
|
||||
* based on v3.1.0 (2020-10-26)
|
||||
|
||||
|
||||
|
||||
##### 3.1.0 MQTT-Client - (2020-10-26)
|
||||
|
||||
##### 2.2.0 Version Controll (2020-09-27)
|
||||
* Update digital CNN to v6.5.0 and HTML (Info to hostname, IP, ssid)
|
||||
|
||||
* New implementation of "checkDigitConsistency" also for digits
|
||||
* MQTT-Adapter: user and password for sign in MQTT-Broker
|
||||
|
||||
##### 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 Control (2020-09-27)
|
||||
|
||||
* Integrated automated versioning system (menu: SYSTEM --> INFO)
|
||||
* Update Build-System to PlatformIO - Espressif 32 v2.0.0 (ESP-IDF 4.1)
|
||||
|
||||
BIN
code/.DS_Store
vendored
Normal file
BIN
code/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string FormatFileName(std::string input);
|
||||
void FindReplace(std::string& line, std::string& oldString, std::string& newString);
|
||||
|
||||
void CopyFile(string input, string output);
|
||||
|
||||
size_t findDelimiterPos(string input, string delimiter);
|
||||
//string trim(string istring);
|
||||
string trim(string istring, string adddelimiter = "");
|
||||
bool ctype_space(const char c, string adddelimiter);
|
||||
|
||||
string getFileType(string filename);
|
||||
|
||||
string toUpper(string in);
|
||||
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
//#pragma warning(disable : 4996)
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
//#define ISWINDOWS_TRUE
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string FormatFileName(std::string input)
|
||||
{
|
||||
#ifdef ISWINDOWS_TRUE
|
||||
input.erase(0, 1);
|
||||
std::string os = "/";
|
||||
std::string ns = "\\";
|
||||
FindReplace(input, os, ns);
|
||||
#endif
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FindReplace(std::string& line, std::string& oldString, std::string& newString) {
|
||||
const size_t oldSize = oldString.length();
|
||||
|
||||
// do nothing if line is shorter than the string to find
|
||||
if (oldSize > line.length()) return;
|
||||
|
||||
const size_t newSize = newString.length();
|
||||
for (size_t pos = 0; ; pos += newSize) {
|
||||
// Locate the substring to replace
|
||||
pos = line.find(oldString, pos);
|
||||
if (pos == std::string::npos) return;
|
||||
if (oldSize == newSize) {
|
||||
// if they're same size, use std::string::replace
|
||||
line.replace(pos, oldSize, newString);
|
||||
}
|
||||
else {
|
||||
// if not same size, replace by erasing and inserting
|
||||
line.erase(pos, oldSize);
|
||||
line.insert(pos, newString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ctype_space(const char c, string adddelimiter)
|
||||
{
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 11)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (adddelimiter.find(c) != string::npos)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
string trim(string istring, string adddelimiter)
|
||||
{
|
||||
bool trimmed = false;
|
||||
|
||||
if (ctype_space(istring[istring.length() - 1], adddelimiter))
|
||||
{
|
||||
istring.erase(istring.length() - 1);
|
||||
trimmed = true;
|
||||
}
|
||||
|
||||
if (ctype_space(istring[0], adddelimiter))
|
||||
{
|
||||
istring.erase(0, 1);
|
||||
trimmed = true;
|
||||
}
|
||||
|
||||
if ((trimmed == false) || (istring.size() == 0))
|
||||
{
|
||||
return istring;
|
||||
}
|
||||
else
|
||||
{
|
||||
return trim(istring, adddelimiter);
|
||||
}
|
||||
}
|
||||
|
||||
size_t findDelimiterPos(string input, string delimiter)
|
||||
{
|
||||
size_t pos = std::string::npos;
|
||||
size_t zw;
|
||||
string akt_del;
|
||||
|
||||
for (int anz = 0; anz < delimiter.length(); ++anz)
|
||||
{
|
||||
akt_del = delimiter[anz];
|
||||
if ((zw = input.find(akt_del)) != std::string::npos)
|
||||
{
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
if (zw < pos)
|
||||
pos = zw;
|
||||
}
|
||||
else
|
||||
pos = zw;
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
void CopyFile(string input, string output)
|
||||
{
|
||||
input = FormatFileName(input);
|
||||
output = FormatFileName(output);
|
||||
|
||||
char cTemp;
|
||||
FILE* fpSourceFile = fopen(input.c_str(), "rb");
|
||||
FILE* fpTargetFile = fopen(output.c_str(), "wb");
|
||||
|
||||
// Code Section
|
||||
|
||||
// Read From The Source File - "Copy"
|
||||
while (fread(&cTemp, 1, 1, fpSourceFile) == 1)
|
||||
{
|
||||
// Write To The Target File - "Paste"
|
||||
fwrite(&cTemp, 1, 1, fpTargetFile);
|
||||
}
|
||||
|
||||
// Close The Files
|
||||
fclose(fpSourceFile);
|
||||
fclose(fpTargetFile);
|
||||
}
|
||||
|
||||
|
||||
string getFileType(string filename)
|
||||
{
|
||||
int lastpos = filename.find(".", 0);
|
||||
int neu_pos;
|
||||
while ((neu_pos = filename.find(".", lastpos + 1)) > -1)
|
||||
{
|
||||
lastpos = neu_pos;
|
||||
}
|
||||
|
||||
string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
|
||||
|
||||
return zw;
|
||||
}
|
||||
|
||||
|
||||
string toUpper(string in)
|
||||
{
|
||||
for (int i = 0; i < in.length(); ++i)
|
||||
in[i] = toupper(in[i]);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ static const char *MAIN_TAG = "connect_wlan";
|
||||
std::string ssid;
|
||||
std::string passphrase;
|
||||
std::string hostname;
|
||||
std::string ipaddress;
|
||||
|
||||
std::string std_hostname = "watermeter";
|
||||
|
||||
@@ -123,6 +124,7 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho
|
||||
xEventGroupWaitBits(wifi_event_group,CONNECTED_BIT,true,true,portMAX_DELAY);
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
|
||||
ipaddress = std::string(ip4addr_ntoa(&ip_info.ip));
|
||||
printf("IPv4 : %s\n", ip4addr_ntoa(&ip_info.ip));
|
||||
printf("HostName : %s\n", hostname.c_str());
|
||||
}
|
||||
@@ -143,7 +145,6 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
|
||||
|
||||
char zw[1024];
|
||||
fgets(zw, 1024, pFile);
|
||||
// printf("%s", zw);
|
||||
line = std::string(zw);
|
||||
|
||||
while ((line.size() > 0) || !(feof(pFile)))
|
||||
@@ -151,21 +152,16 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
|
||||
// printf("%s", line.c_str());
|
||||
zerlegt = ZerlegeZeile(line, "=");
|
||||
zerlegt[0] = trim(zerlegt[0], " ");
|
||||
zerlegt[1] = trim(zerlegt[1], " ");
|
||||
|
||||
if ((zerlegt.size() > 1) && (toUpper(zerlegt[0]) == "HOSTNAME")){
|
||||
_hostname = zerlegt[1];
|
||||
_hostname = trim(zerlegt[1]);
|
||||
if ((_hostname[0] == '"') && (_hostname[_hostname.length()-1] == '"')){
|
||||
_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")){
|
||||
_ssid = zerlegt[1];
|
||||
_ssid = trim(zerlegt[1]);
|
||||
if ((_ssid[0] == '"') && (_ssid[_ssid.length()-1] == '"')){
|
||||
_ssid = _ssid.substr(1, _ssid.length()-2);
|
||||
}
|
||||
@@ -189,6 +185,22 @@ void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphra
|
||||
}
|
||||
|
||||
fclose(pFile);
|
||||
|
||||
// Check if Hostname was empty in .ini if yes set to std_hostname
|
||||
if(_hostname.length() <= 0){
|
||||
_hostname = std_hostname;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string getHostname(){
|
||||
return hostname;
|
||||
}
|
||||
|
||||
std::string getIPAddress(){
|
||||
return ipaddress;
|
||||
}
|
||||
|
||||
std::string getSSID(){
|
||||
return ssid;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,8 @@ void initialise_wifi(std::string _ssid, std::string _passphrase, std::string _ho
|
||||
|
||||
void LoadWlanFromFile(std::string fn, std::string &_ssid, std::string &_passphrase, std::string &_hostname);
|
||||
|
||||
std::string getHostname();
|
||||
std::string getIPAddress();
|
||||
std::string getSSID();
|
||||
|
||||
#endif
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "camera_define.h"
|
||||
|
||||
#include "driver/ledc.h"
|
||||
|
||||
CCamera Camera;
|
||||
|
||||
|
||||
@@ -20,6 +22,42 @@ typedef struct {
|
||||
size_t len;
|
||||
} jpg_chunking_t;
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#define LEDC_LS_CH2_GPIO (4)
|
||||
#define LEDC_LS_CH2_CHANNEL LEDC_CHANNEL_2
|
||||
#define LEDC_LS_TIMER LEDC_TIMER_1
|
||||
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
|
||||
#define LEDC_TEST_DUTY (4000)
|
||||
|
||||
void test(){
|
||||
ledc_channel_config_t ledc_channel = { };
|
||||
|
||||
ledc_channel.channel = LEDC_LS_CH2_CHANNEL;
|
||||
ledc_channel.duty = 0;
|
||||
ledc_channel.gpio_num = FLASH_GPIO;
|
||||
ledc_channel.speed_mode = LEDC_LS_MODE;
|
||||
ledc_channel.hpoint = 0;
|
||||
ledc_channel.timer_sel = LEDC_LS_TIMER;
|
||||
|
||||
ledc_channel_config(&ledc_channel);
|
||||
|
||||
ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, LEDC_TEST_DUTY);
|
||||
ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size_t len){
|
||||
jpg_chunking_t *j = (jpg_chunking_t *)arg;
|
||||
if(!index){
|
||||
|
||||
@@ -404,6 +404,9 @@ void doReboot(){
|
||||
LogFile.WriteToFile("Reboot - now");
|
||||
KillTFliteTasks();
|
||||
xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
hard_restart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
bool debugdetailanalog = false;
|
||||
|
||||
ClassFlowAnalog::ClassFlowAnalog()
|
||||
{
|
||||
isLogImage = false;
|
||||
@@ -108,6 +110,7 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
neuroi->posy = std::stoi(zerlegt[2]);
|
||||
neuroi->deltax = std::stoi(zerlegt[3]);
|
||||
neuroi->deltay = std::stoi(zerlegt[4]);
|
||||
neuroi->result = -1;
|
||||
ROI.push_back(neuroi);
|
||||
}
|
||||
}
|
||||
@@ -146,6 +149,8 @@ bool ClassFlowAnalog::doFlow(string time)
|
||||
return false;
|
||||
};
|
||||
|
||||
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doFlow nach Alignment");
|
||||
|
||||
doNeuralNetwork(time);
|
||||
|
||||
return true;
|
||||
@@ -166,7 +171,7 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
|
||||
CAlignAndCutImage *caic = new CAlignAndCutImage(input);
|
||||
|
||||
if (!caic->ImageOkay()){
|
||||
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
|
||||
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
|
||||
delete caic;
|
||||
return false;
|
||||
}
|
||||
@@ -174,7 +179,8 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
|
||||
if (input_roi.length() > 0){
|
||||
img_roi = new CImageBasis(input_roi);
|
||||
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;
|
||||
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);
|
||||
|
||||
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);
|
||||
ioresize = "/sdcard/img_tmp/ra" + std::to_string(i) + ".bmp";
|
||||
ioresize = FormatFileName(ioresize);
|
||||
@@ -246,8 +259,11 @@ bool ClassFlowAnalog::doNeuralNetwork(string time)
|
||||
f1 = 0; f2 = 0;
|
||||
|
||||
#ifndef OHNETFLITE
|
||||
// LogFile.WriteToFile("ClassFlowAnalog::doNeuralNetwork vor CNN tflite->LoadInputImage(ioresize)");
|
||||
tflite->LoadInputImage(ioresize);
|
||||
tflite->Invoke();
|
||||
if (debugdetailanalog) LogFile.WriteToFile("Nach Invoke");
|
||||
|
||||
|
||||
f1 = tflite->GetOutputValue(0);
|
||||
f2 = tflite->GetOutputValue(1);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _
|
||||
if (_stepname.compare("[Analog]") == 0){
|
||||
_classname = "ClassFlowAnalog";
|
||||
}
|
||||
if (_stepname.compare("[MQTT]") == 0){
|
||||
_classname = "ClassFlowMQTT";
|
||||
}
|
||||
// std::string zw = "Classname: " + _classname + "\n";
|
||||
// printf(zw.c_str());
|
||||
|
||||
@@ -80,6 +83,8 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
|
||||
cfc = new ClassFlowAnalog(&FlowControll);
|
||||
if (toUpper(_type).compare("[DIGITS]") == 0)
|
||||
cfc = new ClassFlowDigit(&FlowControll);
|
||||
if (toUpper(_type).compare("[MQTT]") == 0)
|
||||
cfc = new ClassFlowMQTT(&FlowControll);
|
||||
if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
|
||||
{
|
||||
cfc = new ClassFlowPostProcessing(&FlowControll);
|
||||
@@ -157,7 +162,7 @@ bool ClassFlowControll::doFlow(string time)
|
||||
if (!FlowControll[i]->doFlow(time)){
|
||||
repeat++;
|
||||
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;
|
||||
if (repeat > 5) {
|
||||
LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot");
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "ClassFlowDigit.h"
|
||||
#include "ClassFlowAnalog.h"
|
||||
#include "ClassFlowPostProcessing.h"
|
||||
#include "ClassFlowMQTT.h"
|
||||
|
||||
|
||||
class ClassFlowControll :
|
||||
|
||||
@@ -86,6 +86,7 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
|
||||
neuroi->posy = std::stoi(zerlegt[2]);
|
||||
neuroi->deltax = std::stoi(zerlegt[3]);
|
||||
neuroi->deltay = std::stoi(zerlegt[4]);
|
||||
neuroi->resultklasse = -1;
|
||||
ROI.push_back(neuroi);
|
||||
}
|
||||
}
|
||||
@@ -152,7 +153,8 @@ bool ClassFlowDigit::doAlignAndCut(string time)
|
||||
if (input_roi.length() > 0){
|
||||
img_roi = new CImageBasis(input_roi);
|
||||
if (!img_roi->ImageOkay()){
|
||||
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
|
||||
LogFile.WriteToFile("ClassFlowDigit::doAlignAndCut ImageRoi not okay!");
|
||||
delete caic;
|
||||
delete img_roi;
|
||||
return false;
|
||||
}
|
||||
|
||||
122
code/lib/jomjol_flowcontroll/ClassFlowMQTT.cpp
Normal file
122
code/lib/jomjol_flowcontroll/ClassFlowMQTT.cpp
Normal 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;
|
||||
}
|
||||
25
code/lib/jomjol_flowcontroll/ClassFlowMQTT.h
Normal file
25
code/lib/jomjol_flowcontroll/ClassFlowMQTT.h
Normal 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";};
|
||||
};
|
||||
|
||||
@@ -335,25 +335,23 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
|
||||
Value = std::stof(zw);
|
||||
if (checkDigitIncreaseConsistency)
|
||||
{
|
||||
// Value = checkDigitConsistency(Value, DecimalShift, isanalog);
|
||||
Value = checkDigitConsistency(Value, DecimalShift, isanalog);
|
||||
}
|
||||
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
|
||||
if ((!AllowNegativeRates) && (Value < PreValue))
|
||||
{
|
||||
error = "Negative Rate - Returned old value - read value: " + zwvalue;
|
||||
error = error + "Negative Rate - Returned old value - read value: " + zwvalue + " ";
|
||||
Value = PreValue;
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
}
|
||||
else
|
||||
|
||||
if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue))
|
||||
{
|
||||
if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue))
|
||||
{
|
||||
error = "Rate too high - Returned old value - read value: " + zwvalue;
|
||||
Value = PreValue;
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
}
|
||||
error = error + "Rate too high - Returned old value - read value: " + zwvalue + " ";
|
||||
Value = PreValue;
|
||||
zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
|
||||
}
|
||||
|
||||
ReturnValueNoError = zwvalue;
|
||||
@@ -426,7 +424,7 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
|
||||
float zw;
|
||||
|
||||
pot = _decilamshift;
|
||||
if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewerte werden
|
||||
if (!_isanalog) // falls es keine analogwerte gibt, kann die letzte nicht bewertet werden
|
||||
{
|
||||
pot++;
|
||||
}
|
||||
|
||||
@@ -391,11 +391,11 @@ CImageBasis::CImageBasis(std::string _image)
|
||||
channels = 3;
|
||||
externalImage = false;
|
||||
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);
|
||||
if (rgb_image == NULL)
|
||||
LogFile.WriteToFile("Image Load failed:" + _image + " FreeHeapSize before: " + to_string(freebefore) + " after: " + to_string(esp_get_free_heap_size()));
|
||||
// if (rgb_image == NULL)
|
||||
// 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("w %d, h %d, b %d, c %d", this->width, this->height, this->bpp, this->channels);
|
||||
}
|
||||
|
||||
82
code/lib/jomjol_mqtt/interface_mqtt.cpp
Normal file
82
code/lib/jomjol_mqtt/interface_mqtt.cpp
Normal 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);
|
||||
}
|
||||
4
code/lib/jomjol_mqtt/interface_mqtt.h
Normal file
4
code/lib/jomjol_mqtt/interface_mqtt.h
Normal 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);
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
#include "bitmap_image.hpp"
|
||||
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
bool debugdetailtflite = false;
|
||||
|
||||
float CTfLiteClass::GetOutputValue(int nr)
|
||||
{
|
||||
TfLiteTensor* output2 = this->interpreter->output(0);
|
||||
@@ -109,7 +113,11 @@ void CTfLiteClass::Invoke()
|
||||
|
||||
bool CTfLiteClass::LoadInputImage(std::string _fn)
|
||||
{
|
||||
std::string zw = "ClassFlowAnalog::doNeuralNetwork nach Load Image: " + _fn;
|
||||
// LogFile.WriteToFile(zw);
|
||||
bitmap_image image(_fn);
|
||||
if (debugdetailtflite) LogFile.WriteToFile(zw);
|
||||
|
||||
unsigned int w = image.width();
|
||||
unsigned int h = image.height();
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
if (debugdetailtflite) LogFile.WriteToFile("Nach dem Laden in input");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,24 +75,18 @@ void setup_time(void)
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
// Is time set? If not, tm_year will be (1970 - 1900).
|
||||
if (timeinfo.tm_year < (2016 - 1900)) {
|
||||
if ((timeinfo.tm_year < (2016 - 1900)) || setTimeAlwaysOnReboot) {
|
||||
ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP.");
|
||||
initialize_sntp();
|
||||
obtain_time();
|
||||
// update 'now' variable with current time
|
||||
time(&now);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (setTimeAlwaysOnReboot)
|
||||
{
|
||||
obtain_time();
|
||||
}
|
||||
}
|
||||
char strftime_buf[64];
|
||||
|
||||
// Set timezone to Berlin Standard Time
|
||||
setenv("TZ", "UTC+9", 1);
|
||||
// setenv("TZ", "Europe/Berlin", 1);
|
||||
tzset();
|
||||
localtime_r(&now, &timeinfo);
|
||||
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
|
||||
|
||||
@@ -23,7 +23,7 @@ board_build.embed_files =
|
||||
;board_build.partitions = partitions_singleapp.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
|
||||
|
||||
debug_tool = esp-prog
|
||||
|
||||
@@ -5,63 +5,26 @@
|
||||
|
||||
#include "driver/gpio.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 "esp_wifi.h"
|
||||
//#include "protocol_examples_common.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_file.h"
|
||||
#include "server_ota.h"
|
||||
#include "time_sntp.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_camera.h"
|
||||
#include "ClassControllCamera.h"
|
||||
#include "connect_wlan.h"
|
||||
#include "time_sntp.h"
|
||||
|
||||
static const char *TAGMAIN = "connect_wlan_main";
|
||||
|
||||
@@ -130,7 +93,7 @@ extern "C" void app_main()
|
||||
vTaskDelay( xDelay );
|
||||
// LogFile.WriteToFile("Startsequence 07");
|
||||
setup_time();
|
||||
LogFile.WriteToFile("======================== Main Started ================================");
|
||||
LogFile.WriteToFile("============================== Main Started =======================================");
|
||||
LogFile.SwitchOnOff(false);
|
||||
|
||||
std::string zw = gettimestring("%Y%m%d-%H%M%S");
|
||||
|
||||
@@ -7,8 +7,12 @@
|
||||
|
||||
#include "time_sntp.h"
|
||||
|
||||
#include "connect_wlan.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include "esp_wifi.h"
|
||||
|
||||
|
||||
httpd_handle_t server = NULL;
|
||||
|
||||
@@ -83,6 +87,42 @@ esp_err_t info_get_handler(httpd_req_t *req)
|
||||
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;
|
||||
}
|
||||
|
||||
if (_task.compare("Hostname") == 0)
|
||||
{
|
||||
std::string zw;
|
||||
zw = std::string(getHostname());
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (_task.compare("IP") == 0)
|
||||
{
|
||||
std::string zw;
|
||||
zw = std::string(getIPAddress());
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (_task.compare("SSID") == 0)
|
||||
{
|
||||
std::string zw;
|
||||
zw = std::string(getSSID());
|
||||
httpd_resp_sendstr_chunk(req, zw.c_str());
|
||||
httpd_resp_sendstr_chunk(req, NULL);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -155,8 +195,6 @@ esp_err_t hello_main_handler(httpd_req_t *req)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
esp_err_t img_tmp_handler(httpd_req_t *req)
|
||||
{
|
||||
char filepath[50];
|
||||
@@ -197,7 +235,45 @@ esp_err_t img_tmp_handler(httpd_req_t *req)
|
||||
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)
|
||||
{
|
||||
@@ -209,6 +285,13 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
|
||||
};
|
||||
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 = {
|
||||
.uri = "/starttime", // Match all URIs of type /path/to/file
|
||||
@@ -235,6 +318,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
|
||||
.user_ctx = (void*) base_path // Pass server data as context
|
||||
};
|
||||
httpd_register_uri_handler(server, &main_rest_handle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -410,36 +410,6 @@ esp_err_t handler_prevalue(httpd_req_t *req)
|
||||
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)
|
||||
{
|
||||
int64_t fr_start, fr_delta_ms;
|
||||
@@ -468,7 +438,10 @@ void task_autodoFlow(void *pvParameter)
|
||||
LogFile.WriteToFile("task_autodoFlow - round done");
|
||||
//CPU Temp
|
||||
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);
|
||||
fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
|
||||
const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS;
|
||||
@@ -518,9 +491,5 @@ void register_server_tflite_uri(httpd_handle_t server)
|
||||
camuri.handler = handler_wasserzaehler;
|
||||
camuri.user_ctx = (void*) "Wasserzaehler";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
camuri.uri = "/sysinfo";
|
||||
camuri.handler = handler_sysinfo;
|
||||
camuri.user_ctx = (void*) "Sysinfo";
|
||||
httpd_register_uri_handler(server, &camuri);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const char* GIT_REV="67115dd";
|
||||
const char* GIT_REV="2ab2f07";
|
||||
const char* GIT_TAG="";
|
||||
const char* GIT_BRANCH="master";
|
||||
const char* BUILD_TIME="2020-09-27 08:24";
|
||||
const char* BUILD_TIME="2020-11-03 22:12";
|
||||
@@ -8,7 +8,12 @@ extern "C"
|
||||
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.1.0 - 2020-10-26";
|
||||
|
||||
|
||||
const char* git_base_branch(void)
|
||||
@@ -35,4 +40,23 @@ const char* libfive_git_revision(void)
|
||||
const char* libfive_git_branch(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
const char* GIT_REV="67115dd";
|
||||
const char* GIT_REV="2ab2f07";
|
||||
const char* GIT_TAG="";
|
||||
const char* GIT_BRANCH="master";
|
||||
const char* BUILD_TIME="2020-09-27 08:24";
|
||||
const char* BUILD_TIME="2020-11-03 22:12";
|
||||
BIN
firmware/.DS_Store
vendored
Normal file
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
BIN
sd-card/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -13,7 +13,7 @@ SearchFieldY = 20
|
||||
|
||||
|
||||
[Digits]
|
||||
Model=/config/dig0640s3.tflite
|
||||
Model=/config/dig0650s3.tflite
|
||||
LogImageLocation = /log/digit
|
||||
ModelInputSize 20, 32
|
||||
digit1, 306, 120, 37, 67
|
||||
@@ -38,6 +38,12 @@ MaxRateValue = 0.1
|
||||
ErrorMessage = True
|
||||
CheckDigitIncreaseConsistency = False
|
||||
|
||||
;[MQTT]
|
||||
;Uri = mqtt://IP-MQTT-SERVER:1883
|
||||
;Topic = watermeter/readout
|
||||
;ClientID = wasser
|
||||
;user = USERNAME
|
||||
;password = PASSWORD
|
||||
|
||||
[AutoTimer]
|
||||
AutoStart= True
|
||||
|
||||
Binary file not shown.
BIN
sd-card/config/dig0650s3.tflite
Normal file
BIN
sd-card/config/dig0650s3.tflite
Normal file
Binary file not shown.
@@ -73,8 +73,8 @@ li.dropdown {
|
||||
|
||||
<body style="font-family: arial">
|
||||
|
||||
<h1>Watermeter - AI on the edge</h1>
|
||||
<h2>An ESP32 all in neural network recognition system</h2>
|
||||
<h1>Digitizer - AI on the edge</h1>
|
||||
<h2>An ESP32 all inclusive neural network recognition system for meter digitalization</h2>
|
||||
|
||||
<ul>
|
||||
<li><a href="#"onclick="document.getElementById('maincontent').src = '/wasserzaehler_roi.html';">Overview</a></li>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<title>Set PreValue</title>
|
||||
<meta charset="utf-8">
|
||||
|
||||
|
||||
<style>
|
||||
h1 {font-size: 2em;}
|
||||
h2 {font-size: 1.5em;}
|
||||
@@ -16,16 +16,49 @@ div {
|
||||
border: 1px solid #ccc;
|
||||
font-family: arial;
|
||||
font-size: 16px;
|
||||
max-height: 35px;
|
||||
max-height: 35px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body style="font-family: arial; padding: 0px 10px;">
|
||||
<h3>Host Info</h3>
|
||||
|
||||
<table style="font-family: arial">
|
||||
<tr>
|
||||
<td>
|
||||
Hostname:
|
||||
</td>
|
||||
<td>
|
||||
<div id="gitbranch">
|
||||
<object data="/version?type=Hostname"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
IP-Address:
|
||||
</td>
|
||||
<td>
|
||||
<div id="gitbranch">
|
||||
<object data="/version?type=IP"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
WLan-SSID:
|
||||
</td>
|
||||
<td>
|
||||
<div id="gitbranch">
|
||||
<object data="/version?type=SSID"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Version Info</h3>
|
||||
|
||||
<table style="font-family: arial">
|
||||
@@ -38,7 +71,7 @@ div {
|
||||
<object data="/version?type=GitBranch"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
@@ -49,7 +82,7 @@ div {
|
||||
<object data="/version?type=GitBaseBranch"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
@@ -60,7 +93,7 @@ div {
|
||||
<object data="/version?type=GitVersion"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
@@ -71,9 +104,20 @@ div {
|
||||
<object data="/version?type=BuildTime"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
HTML Version:
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<object data="/version?type=HTMLVersion"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
1
sd-card/html/version.txt
Normal file
1
sd-card/html/version.txt
Normal file
@@ -0,0 +1 @@
|
||||
1.1.0
|
||||
Reference in New Issue
Block a user