From bf787db299e74e5979b235991f2f0be61dabd759 Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Thu, 17 Oct 2024 09:32:26 +0100 Subject: [PATCH 1/6] Fix web tag rc=y performing truncate --- CumulusMX/webtags.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CumulusMX/webtags.cs b/CumulusMX/webtags.cs index 3fc7090d..fdb491d4 100644 --- a/CumulusMX/webtags.cs +++ b/CumulusMX/webtags.cs @@ -53,12 +53,11 @@ private static string CheckRc(string val, Dictionary tagParams) private static string CheckRcDp(double val, Dictionary tagParams, int decimals, string format = null) { string ret; - var rc = tagParams.Get("rc") == "y"; try { - var numFormat = rc ? CultureInfo.InvariantCulture.NumberFormat : CultureInfo.CurrentCulture.NumberFormat; + var numFormat = tagParams.Get("rc") == "y" ? CultureInfo.InvariantCulture.NumberFormat : CultureInfo.CurrentCulture.NumberFormat; - if (rc) + if (tagParams.Get("tc") == "y") { val = Math.Truncate(val); tagParams["dp"] = "0"; @@ -84,12 +83,11 @@ private static string CheckRcDp(double val, Dictionary tagParams private static string CheckRcDp(decimal val, Dictionary tagParams, int decimals) { string ret; - var rc = tagParams.Get("rc") == "y"; try { - var numFormat = rc ? CultureInfo.InvariantCulture.NumberFormat : CultureInfo.CurrentCulture.NumberFormat; + var numFormat = tagParams.Get("rc") == "y" ? CultureInfo.InvariantCulture.NumberFormat : CultureInfo.CurrentCulture.NumberFormat; - if (rc) + if (tagParams.Get("tc") == "y") { val = Math.Truncate(val); tagParams["dp"] = "0"; From 4b4d36e0451efb89b0e92d5f792de053b61f72dd Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Fri, 18 Oct 2024 16:21:28 +0100 Subject: [PATCH 2/6] More SFTP logging fixes --- CumulusMX/Cumulus.cs | 135 ++++++++++++++++++++---------------- CumulusMX/WeatherStation.cs | 3 +- 2 files changed, 78 insertions(+), 60 deletions(-) diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index 2faf2b9a..102e0d83 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -1526,6 +1526,17 @@ public void Initialise(int HTTPport, bool DebugEnabled, string startParms) Api.httpFiles = httpFiles; + if (FtpOptions.FtpMode != Cumulus.FtpProtocols.PHP && RealtimeIntervalEnabled && FtpOptions.RealtimeEnabled) + { + if (FtpOptions.FtpMode == Cumulus.FtpProtocols.SFTP) + { + RealtimeSSHLogin(); + } + else + { + RealtimeFTPLogin(); + } + } RealtimeTimer.Interval = RealtimeInterval; RealtimeTimer.Elapsed += RealtimeTimerTick; RealtimeTimer.AutoReset = true; @@ -2897,8 +2908,15 @@ private async Task RealtimeUpload(byte cycle) var remotefile = GetRemoteFileName(item.remote, DateTime.Now); // all checks OK, file needs to be uploaded - LogFtpMessage(""); - LogFtpDebugMessage($"Realtime[{cycle}]: Uploading extra web {uploadfile} to {remotefile}"); + if (FtpOptions.FtpMode == FtpProtocols.SFTP) + { + LogDebugMessage($"Realtime[{cycle}]: Uploading extra web {uploadfile} to {remotefile}"); + } + else + { + LogFtpMessage(""); + LogFtpDebugMessage($"Realtime[{cycle}]: Uploading extra web {uploadfile} to {remotefile}"); + } // Is this an incremental log file upload? @@ -9356,28 +9374,29 @@ public async Task DoIntervalUpload() if (FtpOptions.FtpMode == FtpProtocols.SFTP) { + LogDebugMessage("SFTP[Int]: Process starting"); // BUILD 3092 - added alternate SFTP authentication options ConnectionInfo connectionInfo; if (FtpOptions.SshAuthen == "password") { connectionInfo = new ConnectionInfo(FtpOptions.Hostname, FtpOptions.Port, FtpOptions.Username, new PasswordAuthenticationMethod(FtpOptions.Username, FtpOptions.Password)); - LogFtpDebugMessage("SFTP[Int]: Connecting using password authentication"); + LogDebugMessage("SFTP[Int]: Connecting using password authentication"); } else if (FtpOptions.SshAuthen == "psk") { PrivateKeyFile pskFile = new PrivateKeyFile(FtpOptions.SshPskFile); connectionInfo = new ConnectionInfo(FtpOptions.Hostname, FtpOptions.Port, FtpOptions.Username, new PrivateKeyAuthenticationMethod(FtpOptions.Username, pskFile)); - LogFtpDebugMessage("SFTP[Int]: Connecting using PSK authentication"); + LogDebugMessage("SFTP[Int]: Connecting using PSK authentication"); } else if (FtpOptions.SshAuthen == "password_psk") { PrivateKeyFile pskFile = new PrivateKeyFile(FtpOptions.SshPskFile); connectionInfo = new ConnectionInfo(FtpOptions.Hostname, FtpOptions.Port, FtpOptions.Username, new PasswordAuthenticationMethod(FtpOptions.Username, FtpOptions.Password), new PrivateKeyAuthenticationMethod(FtpOptions.Username, pskFile)); - LogFtpDebugMessage("SFTP[Int]: Connecting using password or PSK authentication"); + LogDebugMessage("SFTP[Int]: Connecting using password or PSK authentication"); } else { - LogFtpMessage($"SFTP[Int]: Invalid SshftpAuthentication specified [{FtpOptions.SshAuthen}]"); + LogErrorMessage($"SFTP[Int]: Invalid SshftpAuthentication specified [{FtpOptions.SshAuthen}]"); return; } @@ -9386,7 +9405,7 @@ public async Task DoIntervalUpload() using SftpClient conn = new SftpClient(connectionInfo); try { - LogFtpDebugMessage($"SFTP[Int]: CumulusMX Connecting to {FtpOptions.Hostname} on port {FtpOptions.Port}"); + LogDebugMessage($"SFTP[Int]: CumulusMX Connecting to {FtpOptions.Hostname} on port {FtpOptions.Port}"); conn.Connect(); if (ServicePointManager.DnsRefreshTimeout == 0) { @@ -9395,7 +9414,7 @@ public async Task DoIntervalUpload() } catch (Exception ex) { - LogFtpMessage($"SFTP[Int]: Error connecting SFTP - {ex.Message}"); + LogErrorMessage($"SFTP[Int]: Error connecting SFTP - {ex.Message}"); FtpAlarm.LastMessage = "Error connecting SFTP - " + ex.Message; FtpAlarm.Triggered = true; @@ -9410,14 +9429,14 @@ public async Task DoIntervalUpload() if (conn.IsConnected) { - LogFtpDebugMessage($"SFTP[Int]: CumulusMX Connected to {FtpOptions.Hostname} OK"); + LogDebugMessage($"SFTP[Int]: CumulusMX Connected to {FtpOptions.Hostname} OK"); if (NOAAconf.NeedFtp) { try { // upload NOAA reports - LogFtpDebugMessage("SFTP[Int]: Uploading NOAA reports"); + LogDebugMessage("SFTP[Int]: Uploading NOAA reports"); var uploadfile = ReportPath + NOAAconf.LatestMonthReport; var remotefile = NOAAconf.FtpFolder + '/' + NOAAconf.LatestMonthReport; @@ -9429,11 +9448,11 @@ public async Task DoIntervalUpload() UploadFile(conn, uploadfile, remotefile, -1); - LogFtpDebugMessage("SFTP[Int]: Done uploading NOAA reports"); + LogDebugMessage("SFTP[Int]: Done uploading NOAA reports"); } catch (Exception e) { - LogFtpMessage($"SFTP[Int]: Error uploading file - {e.Message}"); + LogErrorMessage($"SFTP[Int]: Error uploading file - {e.Message}"); FtpAlarm.LastMessage = "Error uploading NOAA report file - " + e.Message; FtpAlarm.Triggered = true; } @@ -9456,7 +9475,7 @@ public async Task DoIntervalUpload() if (!File.Exists(uploadfile)) { - LogFtpMessage($"SFTP[Int]: Extra web file [{uploadfile}] not found!"); + LogWarningMessage($"SFTP[Int]: Extra web file [{uploadfile}] not found!"); FtpAlarm.LastMessage = $"Error Extra web file [{uploadfile} not found"; FtpAlarm.Triggered = true; continue; @@ -9464,7 +9483,7 @@ public async Task DoIntervalUpload() var remotefile = GetRemoteFileName(item.remote, logDay); - LogFtpDebugMessage("SFTP[Int]: Uploading Extra web file: " + uploadfile); + LogDebugMessage("SFTP[Int]: Uploading Extra web file: " + uploadfile); // all checks OK, file needs to be uploaded try @@ -9506,7 +9525,7 @@ public async Task DoIntervalUpload() } else if (item.process) { - LogFtpDebugMessage("SFTP[Int]: Processing Extra web file: " + uploadfile); + LogDebugMessage("SFTP[Int]: Processing Extra web file: " + uploadfile); var data = await ProcessTemplateFile2StringAsync(uploadfile, false, item.UTF8); using var strm = GenerateStreamFromString(data); UploadStream(conn, remotefile, strm, -1); @@ -9518,8 +9537,8 @@ public async Task DoIntervalUpload() } catch (Exception e) { - LogFtpMessage($"SFTP[Int]: Error uploading Extra web file [{uploadfile}]"); - LogFtpMessage($"SFTP[Int]: Error = {e.Message}"); + LogErrorMessage($"SFTP[Int]: Error uploading Extra web file [{uploadfile}]"); + LogMessage($"SFTP[Int]: Error = {e.Message}"); FtpAlarm.LastMessage = $"Error uploading Extra web file [{uploadfile}"; FtpAlarm.Triggered = true; } @@ -9539,7 +9558,7 @@ public async Task DoIntervalUpload() { var localFile = StdWebFiles[i].LocalPath + StdWebFiles[i].LocalFileName; var remotefile = remotePath + StdWebFiles[i].RemoteFileName; - LogFtpDebugMessage("SFTP[Int]: Uploading standard Data file: " + localFile); + LogDebugMessage("SFTP[Int]: Uploading standard Data file: " + localFile); string data; @@ -9557,8 +9576,8 @@ public async Task DoIntervalUpload() } catch (Exception e) { - LogFtpMessage($"SFTP[Int]: Error uploading standard data file [{StdWebFiles[i].RemoteFileName}]"); - LogFtpMessage($"SFTP[Int]: Error = {e}"); + LogErrorMessage($"SFTP[Int]: Error uploading standard data file [{StdWebFiles[i].RemoteFileName}]"); + LogMessage($"SFTP[Int]: Error = {e}"); FtpAlarm.LastMessage = $"Error uploading standard web file {StdWebFiles[i].RemoteFileName} - {e.Message}"; FtpAlarm.Triggered = true; } @@ -9574,7 +9593,7 @@ public async Task DoIntervalUpload() try { - LogFtpDebugMessage("SFTP[Int]: Uploading graph data file: " + uploadfile); + LogDebugMessage("SFTP[Int]: Uploading graph data file: " + uploadfile); var json = station.CreateGraphDataJson(GraphDataFiles[i].LocalFileName, false); @@ -9591,8 +9610,8 @@ public async Task DoIntervalUpload() } catch (Exception e) { - LogFtpMessage($"SFTP[Int]: Error uploading graph data file [{uploadfile}]"); - LogFtpMessage($"SFTP[Int]: Error = {e}"); + LogErrorMessage($"SFTP[Int]: Error uploading graph data file [{uploadfile}]"); + LogMessage($"SFTP[Int]: Error = {e}"); FtpAlarm.LastMessage = $"Error uploading graph data file [{uploadfile}] - {e.Message}"; FtpAlarm.Triggered = true; } @@ -9607,7 +9626,7 @@ public async Task DoIntervalUpload() var remotefile = remotePath + GraphDataEodFiles[i].RemoteFileName; try { - LogFtpMessage("SFTP[Int]: Uploading daily graph data file: " + uploadfile); + LogDebugMessage("SFTP[Int]: Uploading daily graph data file: " + uploadfile); var json = station.CreateEodGraphDataJson(GraphDataEodFiles[i].LocalFileName); @@ -9620,8 +9639,8 @@ public async Task DoIntervalUpload() } catch (Exception e) { - LogFtpMessage($"SFTP[Int]: Error uploading daily graph data file [{uploadfile}]"); - LogFtpMessage($"SFTP[Int]: Error = {e}"); + LogErrorMessage($"SFTP[Int]: Error uploading daily graph data file [{uploadfile}]"); + LogMessage($"SFTP[Int]: Error = {e}"); FtpAlarm.LastMessage = $"Error uploading daily graph data file [{uploadfile}] - {e.Message}"; FtpAlarm.Triggered = true; } @@ -9632,9 +9651,9 @@ public async Task DoIntervalUpload() { try { - LogFtpMessage("SFTP[Int]: Uploading Moon image file"); + LogDebugMessage("SFTP[Int]: Uploading Moon image file"); UploadFile(conn, "web" + DirectorySeparator + "moon.png", remotePath + MoonImage.FtpDest, -1); - LogFtpMessage("SFTP[Int]: Done uploading Moon image file"); + LogDebugMessage("SFTP[Int]: Done uploading Moon image file"); // clear the image ready for FTP flag, only upload once an hour MoonImage.ReadyToFtp = false; } @@ -9659,9 +9678,9 @@ public async Task DoIntervalUpload() } catch (Exception ex) { - LogFtpMessage($"SFTP[Int]: Error using SFTP connection - {ex.Message}"); + LogErrorMessage($"SFTP[Int]: Error using SFTP connection - {ex.Message}"); } - LogFtpDebugMessage("SFTP[Int]: Connection process complete"); + LogDebugMessage("SFTP[Int]: Process complete"); } else if (FtpOptions.FtpMode == FtpProtocols.FTP || (FtpOptions.FtpMode == FtpProtocols.FTPS)) { @@ -10627,7 +10646,7 @@ private bool UploadFile(SftpClient conn, string localfile, string remotefile, in { if (conn == null || !conn.IsConnected) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {localfile}"); + LogMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {localfile}"); if (cycle >= 0) _ = RealtimeFTPReconnect(); @@ -10637,7 +10656,7 @@ private bool UploadFile(SftpClient conn, string localfile, string remotefile, in } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {localfile}"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {localfile}"); FtpAlarm.LastMessage = $"The SFTP object is disposed - skipping upload of {localfile}"; FtpAlarm.Triggered = true; @@ -10654,7 +10673,7 @@ private bool UploadFile(SftpClient conn, string localfile, string remotefile, in } catch (Exception ex) { - LogFtpMessage($"SFTP[{cycleStr}]: Error reading {localfile} - {ex.Message}"); + LogWarningMessage($"SFTP[{cycleStr}]: Error reading {localfile} - {ex.Message}"); FtpAlarm.LastMessage = $"Error reading {localfile} - {ex.Message}"; FtpAlarm.Triggered = true; @@ -10662,7 +10681,7 @@ private bool UploadFile(SftpClient conn, string localfile, string remotefile, in if (ex.InnerException != null) { ex = Utils.GetOriginalException(ex); - LogFtpMessage($"SFTP[{cycleStr}]: Base exception - {ex.Message}"); + LogDebugMessage($"SFTP[{cycleStr}]: Base exception - {ex.Message}"); } } @@ -10835,7 +10854,7 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, if (dataStream.Length == 0) { - LogFtpMessage($"SFTP[{cycleStr}]: The data is empty - skipping upload of {remotefile}"); + LogWarningMessage($"SFTP[{cycleStr}]: The data is empty - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The data is empty - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; return false; @@ -10845,7 +10864,7 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, { if (conn == null || !conn.IsConnected) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {remotefile}"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The SFTP object is null or not connected - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; @@ -10857,7 +10876,7 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {remotefile}"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The SFTP object is disposed - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; @@ -10873,24 +10892,24 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, // No delete before upload required for SFTP as we use the overwrite flag try { - LogFtpDebugMessage($"SFTP[{cycleStr}]: Uploading {remotefilename}"); + LogDebugMessage($"SFTP[{cycleStr}]: Uploading {remotefilename}"); conn.OperationTimeout = TimeSpan.FromSeconds(15); conn.UploadFile(dataStream, remotefilename); // defaults to CreateNewOrOpen dataStream.Close(); - LogFtpDebugMessage($"SFTP[{cycleStr}]: Uploaded {remotefilename}"); + LogDebugMessage($"SFTP[{cycleStr}]: Uploaded {remotefilename}"); } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); FtpAlarm.LastMessage = $"The SFTP object is disposed - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; return false; } catch (Exception ex) { - LogFtpMessage($"SFTP[{cycleStr}]: Error uploading {remotefilename} : {ex.Message}"); + LogErrorMessage($"SFTP[{cycleStr}]: Error uploading {remotefilename} : {ex.Message}"); FtpAlarm.LastMessage = $"Error uploading {remotefilename} : {ex.Message}"; FtpAlarm.Triggered = true; @@ -10914,20 +10933,20 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, // rename the file try { - LogFtpDebugMessage($"SFTP[{cycleStr}]: Renaming {remotefilename} to {remotefile}"); + LogDebugMessage($"SFTP[{cycleStr}]: Renaming {remotefilename} to {remotefile}"); conn.RenameFile(remotefilename, remotefile, true); - LogFtpDebugMessage($"SFTP[{cycleStr}]: Renamed {remotefilename}"); + LogDebugMessage($"SFTP[{cycleStr}]: Renamed {remotefilename}"); } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); FtpAlarm.LastMessage = $"The SFTP object is disposed during renaming of {remotefile}"; FtpAlarm.Triggered = true; return false; } catch (Exception ex) { - LogFtpMessage($"SFTP[{cycleStr}]: Error renaming {remotefilename} to {remotefile} : {ex.Message}"); + LogErrorMessage($"SFTP[{cycleStr}]: Error renaming {remotefilename} to {remotefile} : {ex.Message}"); FtpAlarm.LastMessage = $"Error renaming {remotefilename} to {remotefile} : {ex.Message}"; FtpAlarm.Triggered = true; @@ -10941,18 +10960,18 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, return true; } } - LogFtpDebugMessage($"SFTP[{cycleStr}]: Completed uploading {remotefile}"); + LogDebugMessage($"SFTP[{cycleStr}]: Completed uploading {remotefile}"); } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); FtpAlarm.LastMessage = "The SFTP object is disposed"; FtpAlarm.Triggered = true; return false; } catch (Exception ex) { - LogFtpMessage($"SFTP[{cycleStr}]: Error uploading {remotefile} - {ex.Message}"); + LogErrorMessage($"SFTP[{cycleStr}]: Error uploading {remotefile} - {ex.Message}"); FtpAlarm.LastMessage = $"Error uploading {remotefile} - {ex.Message}"; FtpAlarm.Triggered = true; @@ -10960,7 +10979,7 @@ private bool UploadStream(SftpClient conn, string remotefile, Stream dataStream, if (ex.InnerException != null) { ex = Utils.GetOriginalException(ex); - LogFtpMessage($"SFTP[{cycleStr}]: Base exception - {ex.Message}"); + LogDebugMessage($"SFTP[{cycleStr}]: Base exception - {ex.Message}"); } } @@ -10983,7 +11002,7 @@ private bool AppendText(SftpClient conn, string remotefile, string text, int cyc if (text.Length == 0) { - LogFtpMessage($"SFTP[{cycleStr}]: The data is empty - skipping upload of {remotefile}"); + LogWarningMessage($"SFTP[{cycleStr}]: The data is empty - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The data is empty - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; return false; @@ -10993,7 +11012,7 @@ private bool AppendText(SftpClient conn, string remotefile, string text, int cyc { if (conn == null || !conn.IsConnected) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {remotefile}"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is null or not connected - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The SFTP object is null or not connected - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; @@ -11005,7 +11024,7 @@ private bool AppendText(SftpClient conn, string remotefile, string text, int cyc } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {remotefile}"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed - skipping upload of {remotefile}"); FtpAlarm.LastMessage = $"The SFTP object is disposed - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; @@ -11018,23 +11037,23 @@ private bool AppendText(SftpClient conn, string remotefile, string text, int cyc try { - LogFtpDebugMessage($"SFTP[{cycleStr}]: Uploading {remotefile} [adding {linesadded} lines]"); + LogDebugMessage($"SFTP[{cycleStr}]: Uploading {remotefile} [adding {linesadded} lines]"); conn.OperationTimeout = TimeSpan.FromSeconds(15); conn.AppendAllText(remotefile, text); - LogFtpDebugMessage($"SFTP[{cycleStr}]: Uploaded {remotefile} [added {linesadded} lines]"); + LogDebugMessage($"SFTP[{cycleStr}]: Uploaded {remotefile} [added {linesadded} lines]"); } catch (ObjectDisposedException) { - LogFtpMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); + LogErrorMessage($"SFTP[{cycleStr}]: The SFTP object is disposed"); FtpAlarm.LastMessage = $"The SFTP object is disposed - skipping upload of {remotefile}"; FtpAlarm.Triggered = true; return false; } catch (Exception ex) { - LogFtpMessage($"SFTP[{cycleStr}]: Error uploading {remotefile} : {ex.Message}"); + LogErrorMessage($"SFTP[{cycleStr}]: Error uploading {remotefile} : {ex.Message}"); FtpAlarm.LastMessage = $"Error uploading {remotefile} : {ex.Message}"; FtpAlarm.Triggered = true; @@ -11045,7 +11064,7 @@ private bool AppendText(SftpClient conn, string remotefile, string text, int cyc if (ex.InnerException != null) { ex = Utils.GetOriginalException(ex); - LogFtpMessage($"FTP[{cycleStr}]: Base exception - {ex.Message}"); + LogDebugMessage($"FTP[{cycleStr}]: Base exception - {ex.Message}"); } // Lets start again anyway! Too hard to tell if the error is recoverable @@ -12616,7 +12635,7 @@ public void RealtimeFTPLogin() RealtimeFTP.Config.ValidateAnyCertificate = FtpOptions.IgnoreCertErrors; } - if (FtpOptions.Enabled) + if (FtpOptions.Enabled && FtpOptions.FtpMode != FtpProtocols.SFTP) { try { diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 83e273de..9f28e005 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -10,7 +10,6 @@ using System.Net.Sockets; using System.Reflection; using System.Runtime.InteropServices; -using System.Runtime.Intrinsics.X86; using System.Runtime.Serialization.Json; using System.Text; using System.Threading; @@ -9290,7 +9289,7 @@ public LogFileRec ParseLogFileRec(string data, bool minMax) { Date = Utils.ddmmyyhhmmStrToDate(st[0], st[1]), OutdoorTemperature = Convert.ToDouble(st[2], inv), - OutdoorHumidity = Convert.ToInt32(Convert.ToDouble(st[3])), + OutdoorHumidity = Convert.ToInt32(Convert.ToDouble(st[3], inv)), OutdoorDewpoint = Convert.ToDouble(st[4], inv), WindAverage = Convert.ToDouble(st[5], inv), RecentMaxGust = Convert.ToDouble(st[6], inv), From 35746f941c45f3356da73154de69a82d3ce0dd28 Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Sat, 19 Oct 2024 10:02:44 +0100 Subject: [PATCH 3/6] Fix Windy pressure uploads failing --- CHANGELOG.md | 2 ++ CumulusMX/WeatherStation.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cf7a1f..ffb6f5cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ but you also want to see the two minute values then you can use these new tags - Ecowitt TCP API Station, false detection of WS90 when a WH34 sensor was detected - Web tag `<#ErrorLight>` is now functional again. It is triggered if Latest Error has any text, and cleared when you clear the latest error list from the interface - Fix web tag `<#NewBuildNumber>` showing the latest build number as "0000" +- Error when logging enabled at start-up with SFTP uploads +- Windy pressure uploads failing ### Package Updates - SQLite diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 9f28e005..3db8ba8e 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -10712,8 +10712,8 @@ public static string PressINstr(double pressure) public static string PressPAstr(double pressure) { - // return value to 0.1 hPa - return (ConvertUnits.UserPressToMB(pressure) / 100).ToString("F4", CultureInfo.InvariantCulture); + // return value to 100 * hPa + return (ConvertUnits.UserPressToMB(pressure) * 100).ToString("F0", CultureInfo.InvariantCulture); } public string WindMPHStr(double wind) From 205cde5f7500259e3563fafe729d3b72997f03a9 Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Sat, 19 Oct 2024 10:04:35 +0100 Subject: [PATCH 4/6] Bump build number --- CHANGELOG.md | 2 +- CumulusMX/CumulusMX.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb6f5cb..bb476d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Alternatively view it [online on GitHub](https://github.com/cumulusmx/CumulusMX/ --- -## 4.2.1 \[b4042\] - 2024-10-16 +## 4.2.1 \[b4043\] - 2024-10-16 ### New - The web tag `<#DayFileQuery>` has been extended to allow "on this day" type queries. diff --git a/CumulusMX/CumulusMX.csproj b/CumulusMX/CumulusMX.csproj index bc5aaa49..6aa0e179 100644 --- a/CumulusMX/CumulusMX.csproj +++ b/CumulusMX/CumulusMX.csproj @@ -58,7 +58,7 @@ - 4.2.1.4042 + 4.2.1.4043 Copyright © 2015-$([System.DateTime]::Now.ToString('yyyy')) Cumulus MX $(AssemblyName) From 7d48d6c5949c238f3f72a30980896a560c82c7b9 Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Sat, 19 Oct 2024 10:13:45 +0100 Subject: [PATCH 5/6] ChHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb476d22..376c7983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Alternatively view it [online on GitHub](https://github.com/cumulusmx/CumulusMX/ --- -## 4.2.1 \[b4043\] - 2024-10-16 +## 4.2.1 \[b4043\] - 2024-10-19 ### New - The web tag `<#DayFileQuery>` has been extended to allow "on this day" type queries. From 25c6e118945fc89173210fa7c49928c1629e637b Mon Sep 17 00:00:00 2001 From: Mark Crossley Date: Sat, 19 Oct 2024 12:49:57 +0100 Subject: [PATCH 6/6] Fix WS69 battery state decode --- CHANGELOG.md | 1 + CumulusMX/GW1000Station.cs | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376c7983..49231d6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ but you also want to see the two minute values then you can use these new tags - Fix web tag `<#NewBuildNumber>` showing the latest build number as "0000" - Error when logging enabled at start-up with SFTP uploads - Windy pressure uploads failing +- Fix Ecowitt WS69 battery state decode in TCP API station ### Package Updates - SQLite diff --git a/CumulusMX/GW1000Station.cs b/CumulusMX/GW1000Station.cs index b5d34e6b..6d17e713 100644 --- a/CumulusMX/GW1000Station.cs +++ b/CumulusMX/GW1000Station.cs @@ -789,12 +789,10 @@ private bool PrintSensorInfoNew(byte[] data, int idx) break; - case "WH24": - case "WH24/WH65": case "WH25": case "WH26": case string wh31 when wh31.StartsWith("WH31"): // ch 1-8 - case "WH65": + case "WS69": batt = TestBattery1(data[battPos], 1); // 0 or 1 break; @@ -819,17 +817,15 @@ private bool PrintSensorInfoNew(byte[] data, int idx) case string wh34 when wh34.StartsWith("WH34"): // ch 1-8 case string wh35 when wh35.StartsWith("WH35"): // ch 1-8 case "WH68": - case "WS69": battV = data[battPos] * 0.02; batt = $"{battV:f2}V ({(battV > 1.2 ? "OK" : "Low")})"; break; - case string wh51 when wh51.StartsWith("WH51"): // ch 1-8 + case string wh51 when wh51.StartsWith("WH51"): // ch 1-16 battV = data[battPos] * 0.1; batt = $"{battV:f2}V ({TestBattery10(data[battPos])})"; // volts/10, low = 1.2V break; - case "WH80": case "WS80": // if a WS80 is connected, it has a 4.75 second update rate, so reduce the MX update rate from the default 10 seconds if (updateRate > 4000 && updateRate != 4000)