+* New housing published for external LEDs and small clearing: https://www.thingiverse.com/thing:5028229
+
##### 8.5.0 - Multi Meter Support (2021-10-07)
diff --git a/README.md b/README.md
index 0ad9125c..bd6e2fdc 100644
--- a/README.md
+++ b/README.md
@@ -33,173 +33,35 @@ If you have any technical topics, you can file a issue in this repository.
In other cases you can contact the developer via email:
-* New housing published for external LEDs and small clearing: https://www.thingiverse.com/thing:5028229
-
-
+## Tools
+* Logfile downloader and combiner (Thx to [reserve85](https://github.com/reserve85))
+ * Files see ['/tools/logfile-tool'](tbd), How-to see [wiki](https://github.com/jomjol/AI-on-the-edge-device/wiki/Gasmeter-Log-Downloader)
@@ -213,6 +75,10 @@ There are some ideas and feature requests which are not followed currently - mai
## History
+##### 10.6.2 - Stability Increase (2022-07-24)
+
+##### 9.2.0 - External Illumination (2021-12-02)
+
##### 8.5.0 Multi Meter Support (2021-10-07)
##### 7.1.2 MQTT-Update - (2021-06-17)
diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
index 2e25b02f..6417f8d1 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
@@ -760,7 +760,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
_fit = _val + _valminus;
}
- if (result >= 10)
+ if (result > 10)
result = result - 10;
if (result < 0)
result = result + 10;
@@ -872,11 +872,14 @@ std::vectorThis small tool downloads the logfiles from your ESP32 and stores the last value of the day in an *.csv file.
+To use this tool you need to activate the debug logfile in your configuration (Configuration / Debug / Logfile). I go with 30 days of retention in days.
+It downloads only the past logfiles (yesterday and older).
+You can define the max. number of Logfiles to download (beginning from newest [yesterday]).
+I wrote this tool to get a chart of the daily gas consumption to optimize my gas powered heating.
+Variables to define by yourself:
+Feel free to optimize and modify it.
\ No newline at end of file diff --git a/tools/logfile-tool/uMain.dfm b/tools/logfile-tool/uMain.dfm new file mode 100644 index 00000000..09d47a6d --- /dev/null +++ b/tools/logfile-tool/uMain.dfm @@ -0,0 +1,111 @@ +object Form1: TForm1 + Left = 0 + Top = 0 + Caption = 'Gasmeter Log-Downloader' + ClientHeight = 521 + ClientWidth = 513 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + OnCreate = FormCreate + OnDestroy = FormDestroy + PixelsPerInch = 96 + TextHeight = 13 + object lblImpressum: TLabel + Left = 376 + Top = 468 + Width = 68 + Height = 13 + Caption = 'reserve, 2022' + end + object lbledtURL: TLabeledEdit + Left = 28 + Top = 36 + Width = 273 + Height = 21 + EditLabel.Width = 146 + EditLabel.Height = 13 + EditLabel.Caption = 'URL to Logfile-Path on Device:' + TabOrder = 0 + Text = 'http://192.168.10.65/fileserver/log/message/' + end + object btnDownloadLogfiles: TButton + Left = 28 + Top = 174 + Width = 273 + Height = 25 + Caption = 'Download Logfiles and generate CSV' + TabOrder = 1 + OnClick = btnDownloadLogfilesClick + end + object lbledtMaxLogfilesOnServer: TLabeledEdit + Left = 323 + Top = 36 + Width = 121 + Height = 21 + EditLabel.Width = 173 + EditLabel.Height = 13 + EditLabel.Caption = 'Download logfiles from past # days:' + TabOrder = 2 + Text = '30' + end + object lbledtTargetDirectory: TLabeledEdit + Left = 28 + Top = 84 + Width = 273 + Height = 21 + EditLabel.Width = 103 + EditLabel.Height = 13 + EditLabel.Caption = 'Download Logfiles to:' + TabOrder = 3 + Text = 'C:\Temp\Gas\' + end + object lbledtCsvFile: TLabeledEdit + Left = 28 + Top = 131 + Width = 273 + Height = 21 + EditLabel.Width = 80 + EditLabel.Height = 13 + EditLabel.Caption = 'Output CSV-File:' + TabOrder = 4 + Text = 'C:\Temp\Gas\Values.csv' + end + object redtLog: TRichEdit + Left = 28 + Top = 220 + Width = 273 + Height = 277 + Font.Charset = ANSI_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + Lines.Strings = ( + 'redtLog') + ParentFont = False + TabOrder = 5 + Zoom = 100 + end + object idhtp1: TIdHTTP + AllowCookies = True + ProxyParams.BasicAuthentication = False + ProxyParams.ProxyPort = 0 + Request.ContentLength = -1 + Request.ContentRangeEnd = -1 + Request.ContentRangeStart = -1 + Request.ContentRangeInstanceLength = -1 + Request.Accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' + Request.BasicAuthentication = False + Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' + Request.Ranges.Units = 'bytes' + Request.Ranges = <> + HTTPOptions = [hoForceEncodeParams] + Left = 572 + Top = 464 + end +end diff --git a/tools/logfile-tool/uMain.pas b/tools/logfile-tool/uMain.pas new file mode 100644 index 00000000..1d13470c --- /dev/null +++ b/tools/logfile-tool/uMain.pas @@ -0,0 +1,174 @@ +unit uMain; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, System.IOUtils, System.IniFiles, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, IdStream, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, + IdHTTP, System.DateUtils, Generics.Collections, Generics.Defaults, Vcl.ComCtrls; + +type + TForm1 = class(TForm) + lbledtURL: TLabeledEdit; + btnDownloadLogfiles: TButton; + lbledtMaxLogfilesOnServer: TLabeledEdit; + lbledtTargetDirectory: TLabeledEdit; + idhtp1: TIdHTTP; + lbledtCsvFile: TLabeledEdit; + redtLog: TRichEdit; + lblImpressum: TLabel; + procedure btnDownloadLogfilesClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + private + { Private declarations } + mINI: TINIFile; + function DownloadFile(pURL: string; pDestFileName: string): boolean; + function LoadValue(const pFileName: string): Extended; + procedure LoadCSV(const pFileName: string); + procedure SaveCSV(const pFileName: string); + procedure LoadINI; + procedure WriteINI; + public + { Public declarations } + end; + +var + Form1: TForm1; + +implementation + +{$R *.dfm} + +procedure TForm1.btnDownloadLogfilesClick(Sender: TObject); +var + lclDateString: string; + lclFilename: string; + i: Integer; + lclValue: Extended; +begin + redtLog.Clear; + LoadCSV(lbledtCsvFile.Text); + for i := StrToInt(lbledtMaxLogfilesOnServer.Text) downto 1 do + begin + DateTimeToString(lclDateString, 'yyyy-mm-dd', incDay(Now, -i)); + lclFilename := 'log_' + lclDateString + '.txt'; + if (redtLog.FindText(lclDateString, 0, Length(redtLog.Lines.Text), [stWholeWord]) = -1) then + begin + if DownloadFile(lbledtURL.Text + lclFilename, lbledtTargetDirectory.Text + lclFilename) then + begin + lclValue := LoadValue(lbledtTargetDirectory.Text + lclFilename); + redtLog.Lines.Add(lclDateString + ';' + FloatToStrF(lclValue, ffFixed, 8, 2)); + end; + end; + end; + SaveCSV(lbledtCsvFile.Text); +end; + +procedure TForm1.LoadCSV(const pFileName: string); +var + Txt: TextFile; + s: string; +begin + if FileExists(pFileName) then + begin + AssignFile(Txt, pFileName); + Reset(Txt); + while not Eof(Txt) do + begin + Readln(Txt, s); + redtLog.Lines.Add(s); + end; + CloseFile(Txt); + end + else + begin + redtLog.Lines.Add('Date;Value'); + end; +end; + +procedure TForm1.LoadINI; +begin + lbledtURL.Text := mINI.ReadString('MAIN', 'URL', 'http://192.168.10.65/fileserver/log/message/'); + lbledtMaxLogfilesOnServer.Text := mINI.ReadString('MAIN', 'CountLogfiles', '30'); + lbledtTargetDirectory.Text := mINI.ReadString('MAIN', 'Log', 'C:\Temp\Gas\'); + lbledtCsvFile.Text := mINI.ReadString('MAIN', 'CsvFile', 'C:\Temp\Gas\Values.csv'); +end; + +function TForm1.LoadValue(const pFileName: string): Extended; +var + Txt: TextFile; + s: string; + lclStartPos: Integer; + lclEndPos: Integer; +begin + Result := 0; + AssignFile(Txt, pFileName); + Reset(Txt); + while not Eof(Txt) do + begin + Readln(Txt, s); + if (AnsiPos('Value: ', s) <> 0) and (AnsiPos(' Error: no error', s) <> 0) then + begin + lclStartPos := AnsiPos('Value: ', s) + 7; + lclEndPos := AnsiPos(' Error: no error', s) - lclStartPos; + s := StringReplace(s, '.', ',', [rfReplaceAll, rfIgnoreCase]); + Result := StrToFloat(Copy(s, lclStartPos, lclEndPos)); + end; + end; + CloseFile(Txt); +end; + +procedure TForm1.SaveCSV(const pFileName: string); +begin + TFile.WriteAllText(pFileName, redtLog.Lines.Text); +end; + +procedure TForm1.WriteINI; +begin + mINI.WriteString('MAIN', 'URL', lbledtURL.Text); + mINI.WriteString('MAIN', 'CountLogfiles', lbledtMaxLogfilesOnServer.Text); + mINI.WriteString('MAIN', 'Log', lbledtTargetDirectory.Text); + mINI.WriteString('MAIN', 'CsvFile', lbledtCsvFile.Text); +end; + +function TForm1.DownloadFile(pURL: string; pDestFileName: string): boolean; +var + Http: TIdHTTP; + FS: TFileStream; +begin + Result := true; + ForceDirectories(ExtractFileDir(pDestFileName)); + FS := TFileStream.Create(pDestFileName, fmCreate); + try + try + Http := TIdHTTP.Create(nil); + try + Http.Get(pURL, FS); + finally + Http.Free; + end; + finally + FS.Free; + end; + except + DeleteFile(pDestFileName); + Exit(false); + end; +end; + +procedure TForm1.FormCreate(Sender: TObject); +begin + mINI := TINIFile.Create(ExtractFilePath(ParamStr(0)) + 'config.ini'); + LoadINI; + redtLog.Clear; + lblImpressum.Caption := 'reserve, 2022' + #13#10 + 'free to copy and modify' +end; + +procedure TForm1.FormDestroy(Sender: TObject); +begin + WriteINI; + FreeAndNil(mINI); +end; + +end.