diff --git a/Changelog.md b/Changelog.md index 1f93ea41..2df8f836 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,22 @@ ## [Unreleased] +### Added + +- n.a. + +### Changed + +- Update Tool "Logfile downloader and combiner" to handle the new csv file format. + +### Fixed + +- n.a. + +### Removed + +- n.a. + ## [13.0.1] - 2022-11-28 **Home Assistant MQTT Discovery Support** diff --git a/tools/logfile-tool/Gasmeter_Logdownloader.dproj b/tools/logfile-tool/Gasmeter_Logdownloader.dproj deleted file mode 100644 index 670d668d..00000000 --- a/tools/logfile-tool/Gasmeter_Logdownloader.dproj +++ /dev/null @@ -1,546 +0,0 @@ - - - True - Application - Debug - VCL - Gasmeter_Logdownloader.dpr - Win32 - {EF2C2455-2FD5-4992-8408-A473425308BD} - 18.7 - 1 - - - true - - - true - Base - true - - - true - Base - true - - - true - Cfg_1 - true - true - - - true - Base - true - - - true - Cfg_2 - true - true - - - Gasmeter_Logdownloader - .\$(Platform)\$(Config) - .\$(Platform)\$(Config) - System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) - $(BDS)\bin\delphi_PROJECTICON.ico - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png - - - Debug - Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) - DBXSqliteDriver;RESTComponents;WclBluetoothFrameworkR;DBXInterBaseDriver;vclactnband;vclFireDAC;dacfmx260;RSVML;tethering;svnui;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;svn;IcsFmxD103Run;inetdb;IcsVclD103Run;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;frxTee26;RSCommon;dacvcl260;fs26;IndyCore;dbexpress;vclx;frxIntIO26;dsnap;FireDACCommon;RSVclCommon;RESTBackendComponents;VCLRESTComponents;TMSVCLUIPackPkgWizDXE12;soapserver;fsTee26;TMSVCLUIPackPkgDXE12;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACMySQLDriver;frx26;FireDACCommonODBC;FireDACCommonDriver;frxIntIOIndy26;inet;S0586_TRVclComponents;bindcompdbx;IndyIPCommon;vcl;IndyIPServer;frxDB26;IndySystem;fsADO26;frxDBX26;dsnapcon;sdac260;FireDACMSAccDriver;fsDB26;fmxFireDAC;vclimg;S0606_BMVclComponents;S0628_EWVclComponents;FireDAC;TeeDB;dOPCP;frxe26;FireDACSqliteDriver;FireDACPgDriver;tdstream260;sdacvcl260;crcontrols260;TMSVCLUIPackPkgXlsDXE12;FMXTee;soaprtl;DbxCommonDriver;Tee;xmlrtl;soapmidas;dac260;vclwinx;fmxobj;rtl;frxADO26;DbxClientDriver;CustomIPTransport;vcldsnap;SynEditDR;bindcomp;appanalytics;TMSVCLUIPackPkgExDXE12;RSFMXSVG;IndyIPClient;IcsCommonD103Run;sdacfmx260;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;sbridge260;dsnapxml;dbrtl;IndyProtocols;inetdbxpress;RSVclSVG;fmxase;$(DCC_UsePackage) - $(BDS)\bin\default_app.manifest - true - CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= - 1033 - - - true - true - DEBUG;$(DCC_Define) - true - false - true - - - PerMonitorV2 - true - false - - - 0 - RELEASE;$(DCC_Define) - false - 0 - - - PerMonitorV2 - true - - - - MainSource - - -
Form1
- dfm -
- - Cfg_2 - Base - - - Base - - - Cfg_1 - Base - -
- - Delphi.Personality.12 - Application - - - - Gasmeter_Logdownloader.dpr - - - - - - Gasmeter_Logdownloader.exe - true - - - - - 1 - - - Contents\MacOS - 1 - - - Contents\MacOS - 0 - - - - - classes - 1 - - - - - library\lib\armeabi-v7a - 1 - - - - - library\lib\armeabi - 1 - - - - - library\lib\mips - 1 - - - - - library\lib\armeabi-v7a - 1 - - - - - res\drawable - 1 - - - - - res\values - 1 - - - - - res\drawable - 1 - - - - - res\drawable-xxhdpi - 1 - - - - - res\drawable-ldpi - 1 - - - - - res\drawable-mdpi - 1 - - - - - res\drawable-hdpi - 1 - - - - - res\drawable-xhdpi - 1 - - - - - res\drawable-small - 1 - - - - - res\drawable-normal - 1 - - - - - res\drawable-large - 1 - - - - - res\drawable-xlarge - 1 - - - - - 1 - - - Contents\MacOS - 1 - - - 0 - - - - - Contents\MacOS - 1 - .framework - - - 0 - - - - - 1 - .dylib - - - 1 - .dylib - - - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - 0 - .dll;.bpl - - - - - 1 - .dylib - - - 1 - .dylib - - - 1 - .dylib - - - Contents\MacOS - 1 - .dylib - - - 0 - .bpl - - - - - 0 - - - 0 - - - 0 - - - 0 - - - Contents\Resources\StartUp\ - 0 - - - 0 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - - - 1 - - - 1 - - - - - ..\ - 1 - - - ..\ - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\ - 1 - - - - - Contents - 1 - - - - - Contents\Resources - 1 - - - - - library\lib\armeabi-v7a - 1 - - - 1 - - - 1 - - - 1 - - - 1 - - - Contents\MacOS - 1 - - - 0 - - - - - 1 - - - 1 - - - - - Assets - 1 - - - Assets - 1 - - - - - Assets - 1 - - - Assets - 1 - - - - - - - - - - - - - True - False - - - 12 - - - - -
diff --git a/tools/logfile-tool/Gasmeter_Logdownloader.dpr b/tools/logfile-tool/Gasmeter_Value_History.dpr similarity index 85% rename from tools/logfile-tool/Gasmeter_Logdownloader.dpr rename to tools/logfile-tool/Gasmeter_Value_History.dpr index c6b60d53..2cda5520 100644 --- a/tools/logfile-tool/Gasmeter_Logdownloader.dpr +++ b/tools/logfile-tool/Gasmeter_Value_History.dpr @@ -1,4 +1,4 @@ -program Gasmeter_Logdownloader; +program Gasmeter_Value_History; uses Vcl.Forms, diff --git a/tools/logfile-tool/Gasmeter_Value_History.dproj b/tools/logfile-tool/Gasmeter_Value_History.dproj new file mode 100644 index 00000000..2347cc19 --- /dev/null +++ b/tools/logfile-tool/Gasmeter_Value_History.dproj @@ -0,0 +1,186 @@ + + + True + Application + Debug + VCL + Gasmeter_Value_History.dpr + Win32 + {EF2C2455-2FD5-4992-8408-A473425308BD} + 18.7 + 1 + + + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + Gasmeter_Value_History + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + + + Debug + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + DBXSqliteDriver;RESTComponents;WclBluetoothFrameworkR;DBXInterBaseDriver;vclactnband;vclFireDAC;dacfmx260;RSVML;tethering;svnui;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;svn;IcsFmxD103Run;inetdb;IcsVclD103Run;FmxTeeUI;fmx;FireDACIBDriver;fmxdae;frxTee26;RSCommon;dacvcl260;fs26;IndyCore;dbexpress;vclx;frxIntIO26;dsnap;FireDACCommon;RSVclCommon;RESTBackendComponents;VCLRESTComponents;TMSVCLUIPackPkgWizDXE12;soapserver;fsTee26;TMSVCLUIPackPkgDXE12;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACMySQLDriver;frx26;FireDACCommonODBC;FireDACCommonDriver;frxIntIOIndy26;inet;S0586_TRVclComponents;bindcompdbx;IndyIPCommon;vcl;IndyIPServer;frxDB26;IndySystem;fsADO26;frxDBX26;dsnapcon;sdac260;FireDACMSAccDriver;fsDB26;fmxFireDAC;vclimg;S0606_BMVclComponents;S0628_EWVclComponents;FireDAC;TeeDB;dOPCP;frxe26;FireDACSqliteDriver;FireDACPgDriver;tdstream260;sdacvcl260;crcontrols260;TMSVCLUIPackPkgXlsDXE12;FMXTee;soaprtl;DbxCommonDriver;Tee;xmlrtl;soapmidas;dac260;vclwinx;fmxobj;rtl;frxADO26;DbxClientDriver;CustomIPTransport;vcldsnap;SynEditDR;bindcomp;appanalytics;TMSVCLUIPackPkgExDXE12;RSFMXSVG;IndyIPClient;IcsCommonD103Run;sdacfmx260;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;sbridge260;dsnapxml;dbrtl;IndyProtocols;inetdbxpress;RSVclSVG;fmxase;$(DCC_UsePackage) + $(BDS)\bin\default_app.manifest + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + + + true + true + DEBUG;$(DCC_Define) + true + false + true + + + PerMonitorV2 + true + false + + + 0 + RELEASE;$(DCC_Define) + false + 0 + + + PerMonitorV2 + true + + + + MainSource + + +
Form1
+ dfm +
+ + Base + + + Cfg_1 + Base + + + Cfg_2 + Base + +
+ + Delphi.Personality.12 + Application + + + + Gasmeter_Value_History.dpr + + + + + + Gasmeter_Value_History.exe + true + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + .dll;.bpl + + + + + 0 + .bpl + + + + + 0 + + + + + 0 + + + + + 1 + + + + + Assets + 1 + + + + + Assets + 1 + + + + + + True + False + + + 12 + + + + +
diff --git a/tools/logfile-tool/Gasmeter_Logdownloader.exe b/tools/logfile-tool/Gasmeter_Value_History.exe similarity index 69% rename from tools/logfile-tool/Gasmeter_Logdownloader.exe rename to tools/logfile-tool/Gasmeter_Value_History.exe index 408786ab..780089ef 100644 Binary files a/tools/logfile-tool/Gasmeter_Logdownloader.exe and b/tools/logfile-tool/Gasmeter_Value_History.exe differ diff --git a/tools/logfile-tool/config.ini b/tools/logfile-tool/config.ini index df394c42..bb176f83 100644 --- a/tools/logfile-tool/config.ini +++ b/tools/logfile-tool/config.ini @@ -1,5 +1,5 @@ [MAIN] -URL=http://192.168.178.62/fileserver/log/message/ -CountLogfiles=3 -Log=C:\Users\Muell\Downloads -CsvFile=C:\Users\Muell\Downloads\values.csv +URL=http://192.168.10.65/fileserver/log/ +CountLogfiles=30 +Log=D:\Daten\Dropbox\Eigene Dateien\Elektronik\Gaszähler\Auswertung\Log-Downloads\ +CsvFile=D:\Daten\Dropbox\Eigene Dateien\Elektronik\Gaszähler\Auswertung\Tagesstand.csv diff --git a/tools/logfile-tool/readme.md b/tools/logfile-tool/readme.md index f22ba24f..6a72b284 100644 --- a/tools/logfile-tool/readme.md +++ b/tools/logfile-tool/readme.md @@ -1,14 +1,14 @@ -

Gasmeter Log-Downloader

-

This 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]).

+

Gasmeter Value History Downloader

+

This small tool downloads the datafiles (*.txt, before V13.0.1) or valuefiles (*.csv, since V13.0.1) from your ESP32 and stores the last value of the day in a *.csv file.

+

To use this tool you need to activate the DataLogging in your configuration (Configuration / Data Logging / DataLogActive). I go with 30 days of retention in days.

+

It downloads only the past datafiles (yesterday and older, not the actual day).

+

You can define the max. number of datafiles 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 index 09d47a6d..a99bdb53 100644 --- a/tools/logfile-tool/uMain.dfm +++ b/tools/logfile-tool/uMain.dfm @@ -1,9 +1,9 @@ object Form1: TForm1 Left = 0 Top = 0 - Caption = 'Gasmeter Log-Downloader' - ClientHeight = 521 - ClientWidth = 513 + Caption = 'Gasmeter Value-History' + ClientHeight = 523 + ClientWidth = 453 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText @@ -16,7 +16,7 @@ object Form1: TForm1 PixelsPerInch = 96 TextHeight = 13 object lblImpressum: TLabel - Left = 376 + Left = 316 Top = 468 Width = 68 Height = 13 @@ -31,25 +31,25 @@ object Form1: TForm1 EditLabel.Height = 13 EditLabel.Caption = 'URL to Logfile-Path on Device:' TabOrder = 0 - Text = 'http://192.168.10.65/fileserver/log/message/' + Text = 'http://192.168.10.65/fileserver/log/' end object btnDownloadLogfiles: TButton Left = 28 Top = 174 Width = 273 Height = 25 - Caption = 'Download Logfiles and generate CSV' + Caption = 'Download datafiles and generate CSV' TabOrder = 1 OnClick = btnDownloadLogfilesClick end object lbledtMaxLogfilesOnServer: TLabeledEdit Left = 323 Top = 36 - Width = 121 + Width = 114 Height = 21 - EditLabel.Width = 173 + EditLabel.Width = 112 EditLabel.Height = 13 - EditLabel.Caption = 'Download logfiles from past # days:' + EditLabel.Caption = 'Download past # days:' TabOrder = 2 Text = '30' end @@ -58,11 +58,11 @@ object Form1: TForm1 Top = 84 Width = 273 Height = 21 - EditLabel.Width = 103 + EditLabel.Width = 108 EditLabel.Height = 13 - EditLabel.Caption = 'Download Logfiles to:' + EditLabel.Caption = 'Download datafiles to:' TabOrder = 3 - Text = 'C:\Temp\Gas\' + Text = 'C:\Temp\Gas\Log\' end object lbledtCsvFile: TLabeledEdit Left = 28 diff --git a/tools/logfile-tool/uMain.pas b/tools/logfile-tool/uMain.pas index 1d13470c..b1d0f224 100644 --- a/tools/logfile-tool/uMain.pas +++ b/tools/logfile-tool/uMain.pas @@ -43,7 +43,8 @@ implementation procedure TForm1.btnDownloadLogfilesClick(Sender: TObject); var lclDateString: string; - lclFilename: string; + lclFilenameCsv: string; + lclFilenameTxtOld: string; i: Integer; lclValue: Extended; begin @@ -51,13 +52,19 @@ begin LoadCSV(lbledtCsvFile.Text); for i := StrToInt(lbledtMaxLogfilesOnServer.Text) downto 1 do begin - DateTimeToString(lclDateString, 'yyyy-mm-dd', incDay(Now, -i)); - lclFilename := 'log_' + lclDateString + '.txt'; + DateTimeToString(lclDateString, 'yyyy-mm-dd', incDay(Now, - i)); + lclFilenameCsv := 'data_' + lclDateString + '.csv'; // http://192.168.10.65/fileserver/log/data/data_2022-11-28.csv + lclFilenameTxtOld := 'log_' + lclDateString + '.txt'; // http://192.168.10.65/fileserver/log/message/log_2022-11-10.txt if (redtLog.FindText(lclDateString, 0, Length(redtLog.Lines.Text), [stWholeWord]) = -1) then begin - if DownloadFile(lbledtURL.Text + lclFilename, lbledtTargetDirectory.Text + lclFilename) then + if DownloadFile(lbledtURL.Text + 'data/' + lclFilenameCsv, lbledtTargetDirectory.Text + lclFilenameCsv) then begin - lclValue := LoadValue(lbledtTargetDirectory.Text + lclFilename); + lclValue := LoadValue(lbledtTargetDirectory.Text + lclFilenameCsv); + redtLog.Lines.Add(lclDateString + ';' + FloatToStrF(lclValue, ffFixed, 8, 2)); + end + else if DownloadFile(lbledtURL.Text + 'message/' + lclFilenameTxtOld, lbledtTargetDirectory.Text + lclFilenameTxtOld) then + begin + lclValue := LoadValue(lbledtTargetDirectory.Text + lclFilenameTxtOld); redtLog.Lines.Add(lclDateString + ';' + FloatToStrF(lclValue, ffFixed, 8, 2)); end; end; @@ -99,24 +106,45 @@ function TForm1.LoadValue(const pFileName: string): Extended; var Txt: TextFile; s: string; + lclStringList: TStringList; 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 + lclStringList := TStringList.Create; + try + AssignFile(Txt, pFileName); + Reset(Txt); + while not Eof(Txt) do begin - lclStartPos := AnsiPos('Value: ', s) + 7; - lclEndPos := AnsiPos(' Error: no error', s) - lclStartPos; - s := StringReplace(s, '.', ',', [rfReplaceAll, rfIgnoreCase]); - Result := StrToFloat(Copy(s, lclStartPos, lclEndPos)); + Readln(Txt, s); + if ExtractFileExt(pFileName) = '.csv' then + begin + if (AnsiPos('no error', s) <> 0) then + begin + lclStringList.Clear; + lclStringList.Delimiter := ';'; + s := StringReplace(s, ',', ';', [rfReplaceAll, rfIgnoreCase]); + s := StringReplace(s, '.', ',', [rfReplaceAll, rfIgnoreCase]); + lclStringList.DelimitedText := s; + Result := lclStringList[2].ToExtended; + end; + end + else + begin + 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; end; + finally + CloseFile(Txt); + FreeAndNil(lclStringList); end; - CloseFile(Txt); end; procedure TForm1.SaveCSV(const pFileName: string);