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:
-
URL to Logfile-Path on Device: "http://ESP32-IP-Address/fileserver/log/message/"
-
Download Logfiles to: enter a valid directory, e.g. "D:\Gaszaehler\Auswertung\Log-Downloads\"
+
URL to Logfile-Path on Device: "http://ESP32-IP-Address/fileserver/log/"
+
Download datafiles to: enter a valid directory, e.g. "D:\Gaszaehler\Auswertung\Log-Downloads\"
Output CSV-File: enter a valid directory, e.g. "D:\Gaszaehler\Auswertung\DailyValues.csv"
-
Download Logfiles from past # days: enter the max. number of logfiles you want to download (<= your logfile retention value in your device configuration)
+
Download past # days: enter the max. number of days you want to download (<= your datafiles retention value in your device configuration)
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);