From a6504fe00ae578c0c8a8345d68eaa02b633f355d Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 14 Jun 2022 11:50:05 +0100 Subject: [PATCH 01/21] Package updates --- CumulusMX/App.config | 6 +++++- CumulusMX/CumulusMX.csproj | 22 +++++++++++----------- CumulusMX/packages.config | 12 ++++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CumulusMX/App.config b/CumulusMX/App.config index 6996fdc6..024653f4 100644 --- a/CumulusMX/App.config +++ b/CumulusMX/App.config @@ -25,6 +25,10 @@ - + + + + + diff --git a/CumulusMX/CumulusMX.csproj b/CumulusMX/CumulusMX.csproj index 9efb51fb..2490252d 100644 --- a/CumulusMX/CumulusMX.csproj +++ b/CumulusMX/CumulusMX.csproj @@ -110,20 +110,20 @@ False ..\packages\linqtotwitter.3.1.1\lib\net45\LinqToTwitterPcl.dll - - ..\packages\MailKit.3.2.0\lib\net48\MailKit.dll + + ..\packages\MailKit.3.3.0\lib\net48\MailKit.dll - - ..\packages\MimeKit.3.2.0\lib\net48\MimeKit.dll + + ..\packages\MimeKit.3.3.0\lib\net48\MimeKit.dll - - ..\packages\MQTTnet.3.1.2\lib\net461\MQTTnet.dll + + ..\packages\MQTTnet.4.0.0.167\lib\net461\MQTTnet.dll - ..\packages\MySqlConnector.2.1.9\lib\net471\MySqlConnector.dll + ..\packages\MySqlConnector.2.1.10\lib\net471\MySqlConnector.dll - - ..\packages\SSH.NET.2020.0.1\lib\net40\Renci.SshNet.dll + + ..\packages\SSH.NET.2020.0.2\lib\net40\Renci.SshNet.dll ..\packages\ServiceStack.Text.6.1.0\lib\net472\ServiceStack.Text.dll @@ -143,8 +143,8 @@ - - ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll diff --git a/CumulusMX/packages.config b/CumulusMX/packages.config index 64c4137e..b5898cc3 100644 --- a/CumulusMX/packages.config +++ b/CumulusMX/packages.config @@ -3,15 +3,15 @@ - + - - - + + + @@ -19,10 +19,10 @@ - + - + From a792c8b788ae7f28f937f31dcb87555a57bc317a Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 14 Jun 2022 13:02:43 +0100 Subject: [PATCH 02/21] Version number uplift --- CumulusMX/Properties/AssemblyInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CumulusMX/Properties/AssemblyInfo.cs b/CumulusMX/Properties/AssemblyInfo.cs index 4a38d019..6beb8c1a 100644 --- a/CumulusMX/Properties/AssemblyInfo.cs +++ b/CumulusMX/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Cumulus MX")] -[assembly: AssemblyDescription("Version 3.18.0 - Build 3189")] +[assembly: AssemblyDescription("Version 3.18.1 - Build 3190")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Cumulus MX")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.18.0.3189")] -[assembly: AssemblyFileVersion("3.18.0.3189")] +[assembly: AssemblyVersion("3.18.1.3190")] +[assembly: AssemblyFileVersion("3.18.1.3190")] From ffe0163b47e4011fc9de42fa1f23254bd92f80f0 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 14 Jun 2022 13:19:46 +0100 Subject: [PATCH 03/21] Remove redundant call to CurrentSolarMax in DoSolar() - it is already updated once a minute --- CumulusMX/WeatherStation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 2ff245b1..5b274f55 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -4307,7 +4307,7 @@ public void DoSolarRad(int value, DateTime timestamp) HiLoToday.HighSolar = SolarRad; HiLoToday.HighSolarTime = timestamp; } - CurrentSolarMax = AstroLib.SolarMax(timestamp, cumulus.Longitude, cumulus.Latitude, AltitudeM(cumulus.Altitude), out SolarElevation, cumulus.SolarOptions); + //CurrentSolarMax = AstroLib.SolarMax(timestamp, cumulus.Longitude, cumulus.Latitude, AltitudeM(cumulus.Altitude), out SolarElevation, cumulus.SolarOptions); if (!cumulus.SolarOptions.UseBlakeLarsen) { From 1e9ee36cfef55b5cf93094e5dce78bdf360cf2dd Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 14 Jun 2022 13:19:46 +0100 Subject: [PATCH 04/21] Remove redundant call to CurrentSolarMax in DoSolar() - it is already updated once a minute --- CumulusMX/WeatherStation.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 2ff245b1..8e0dbc61 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -4300,14 +4300,12 @@ public void DoUV(double value, DateTime timestamp) public void DoSolarRad(int value, DateTime timestamp) { SolarRad = (value * cumulus.Calib.Solar.Mult) + cumulus.Calib.Solar.Offset; - // Update display if (SolarRad > HiLoToday.HighSolar) { HiLoToday.HighSolar = SolarRad; HiLoToday.HighSolarTime = timestamp; } - CurrentSolarMax = AstroLib.SolarMax(timestamp, cumulus.Longitude, cumulus.Latitude, AltitudeM(cumulus.Altitude), out SolarElevation, cumulus.SolarOptions); if (!cumulus.SolarOptions.UseBlakeLarsen) { From 6f5fa813a9b96aa3bff39473775ab75e9ff1aa8b Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Tue, 14 Jun 2022 13:37:30 +0100 Subject: [PATCH 05/21] MQTTnet updates to support ver 4 --- CumulusMX/MqttPublisher.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/CumulusMX/MqttPublisher.cs b/CumulusMX/MqttPublisher.cs index 1201b7f8..8dcd8206 100644 --- a/CumulusMX/MqttPublisher.cs +++ b/CumulusMX/MqttPublisher.cs @@ -25,11 +25,11 @@ public static void Setup(Cumulus cumulus) var clientId = Guid.NewGuid().ToString(); - var mqttTcpOptions = new MQTTnet.Client.Options.MqttClientTcpOptions + var mqttTcpOptions = new MQTTnet.Client.MqttClientTcpOptions { Server = cumulus.MQTT.Server, Port = cumulus.MQTT.Port, - TlsOptions = new MQTTnet.Client.Options.MqttClientTlsOptions { UseTls = cumulus.MQTT.UseTLS } + TlsOptions = new MQTTnet.Client.MqttClientTlsOptions { UseTls = cumulus.MQTT.UseTLS } }; switch (cumulus.MQTT.IpVersion) @@ -45,23 +45,19 @@ public static void Setup(Cumulus cumulus) break; } - var mqttOptions = new MQTTnet.Client.Options.MqttClientOptions + var mqttOptions = new MQTTnet.Client.MqttClientOptions { ChannelOptions = mqttTcpOptions, ClientId = clientId, Credentials = string.IsNullOrEmpty(cumulus.MQTT.Password) ? null - : new MQTTnet.Client.Options.MqttClientCredentials - { - Username = cumulus.MQTT.Username, - Password = System.Text.Encoding.UTF8.GetBytes(cumulus.MQTT.Password) - }, + : new MQTTnet.Client.MqttClientCredentials(cumulus.MQTT.Username, System.Text.Encoding.UTF8.GetBytes(cumulus.MQTT.Password)), CleanSession = true }; Connect(mqttOptions); - mqttClient.UseDisconnectedHandler(async e => + mqttClient.DisconnectedAsync += (async e => { cumulus.LogMessage("Error: MQTT disconnected from the server"); await Task.Delay(TimeSpan.FromSeconds(5)); @@ -101,7 +97,7 @@ private static async Task SendMessageAsync(string topic, string message, bool re } } - private static async void Connect(MQTTnet.Client.Options.IMqttClientOptions options) + private static async void Connect(MQTTnet.Client.MqttClientOptions options) { try { From 62afe66cbdc22c766d6d299be60fa48fd354dc2a Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:36:02 +0100 Subject: [PATCH 06/21] Version uplift --- CumulusMX/Properties/AssemblyInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CumulusMX/Properties/AssemblyInfo.cs b/CumulusMX/Properties/AssemblyInfo.cs index 6beb8c1a..c4d94696 100644 --- a/CumulusMX/Properties/AssemblyInfo.cs +++ b/CumulusMX/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Cumulus MX")] -[assembly: AssemblyDescription("Version 3.18.1 - Build 3190")] +[assembly: AssemblyDescription("Version 3.18.1 - Build 3191")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Cumulus MX")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.18.1.3190")] -[assembly: AssemblyFileVersion("3.18.1.3190")] +[assembly: AssemblyVersion("3.18.1.3191")] +[assembly: AssemblyFileVersion("3.18.1.3191")] From 34f203d6aac3cce54a17477e956872fa762e3ea6 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:04:19 +0100 Subject: [PATCH 07/21] Code tidying --- CumulusMX/Cumulus.cs | 27 ++-- CumulusMX/WeatherStation.cs | 315 ++++++++++++++++-------------------- 2 files changed, 153 insertions(+), 189 deletions(-) diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index 2aa1c65e..399aa071 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -8333,8 +8333,6 @@ public void DoFTPLogin() } // Extra files - LogFtpDebugMessage("SFTP[Int]: Uploading extra files"); - var cnt = 0; for (int i = 0; i < numextrafiles; i++) { var uploadfile = ExtraFiles[i].local; @@ -8353,7 +8351,8 @@ public void DoFTPLogin() if (File.Exists(uploadfile)) { - cnt++; + LogFtpDebugMessage("FTP[Int]: Uploading Extra file: " + uploadfile); + remotefile = GetRemoteFileName(remotefile, logDay); // all checks OK, file needs to be uploaded @@ -8383,20 +8382,18 @@ public void DoFTPLogin() { EODfilesNeedFTP = false; } - LogFtpDebugMessage($"SFTP[Int]: Done uploading {cnt} extra files"); // standard files - LogFtpDebugMessage("SFTP[Int]: Uploading standard web files"); - cnt = 0; for (var i = 0; i < StdWebFiles.Length; i++) { if (StdWebFiles[i].FTP && StdWebFiles[i].FtpRequired) { try { - cnt++; var localFile = StdWebFiles[i].LocalPath + StdWebFiles[i].LocalFileName; var remotefile = remotePath + StdWebFiles[i].RemoteFileName; + LogFtpDebugMessage("FTP[Int]: Uploading standard Data file: " + localFile); + UploadFile(conn, localFile, remotefile, -1); } catch (Exception e) @@ -8406,9 +8403,6 @@ public void DoFTPLogin() } } } - LogFtpDebugMessage($"SFTP[Int]: Done uploading {0} standard web files"); - - LogFtpDebugMessage("SFTP[Int]: Uploading graph data files"); for (int i = 0; i < GraphDataFiles.Length; i++) { @@ -8419,6 +8413,8 @@ public void DoFTPLogin() try { + LogFtpDebugMessage("FTP[Int]: Uploading graph data file: " + uploadfile); + UploadFile(conn, uploadfile, remotefile, -1); // The config files only need uploading once per change if (GraphDataFiles[i].LocalFileName == "availabledata.json" || @@ -8434,19 +8430,17 @@ public void DoFTPLogin() } } } - LogFtpDebugMessage("SFTP[Int]: Done uploading graph data files"); - LogFtpMessage("SFTP[Int]: Uploading daily graph data files"); - cnt = 0; for (int i = 0; i < GraphDataEodFiles.Length; i++) { if (GraphDataEodFiles[i].FTP && GraphDataEodFiles[i].FtpRequired) { - cnt++; var uploadfile = GraphDataEodFiles[i].LocalPath + GraphDataEodFiles[i].LocalFileName; var remotefile = remotePath + GraphDataEodFiles[i].RemoteFileName; try { + LogFtpMessage("FTP[Int]: Uploading daily graph data file: " + uploadfile); + UploadFile(conn, uploadfile, remotefile, -1); // Uploaded OK, reset the upload required flag GraphDataEodFiles[i].FtpRequired = false; @@ -8458,7 +8452,6 @@ public void DoFTPLogin() } } } - LogFtpMessage($"SFTP[Int]: Done uploading {cnt} daily graph data files"); if (MoonImage.Ftp && MoonImage.ReadyToFtp) { @@ -9657,6 +9650,10 @@ private void RealtimeFTPLogin() RealtimeFTP.DataConnectionType = FtpDataConnectionType.PASV; LogDebugMessage("RealtimeFTPLogin: Disabling EPSV mode"); } + else + { + RealtimeFTP.DataConnectionType = FtpDataConnectionType.EPSV; + } if (FtpOptions.Enabled) { diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 8e0dbc61..a8a369f8 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -10892,11 +10892,13 @@ public string GetDailyRainGraphData() var data = DayFile.Where(rec => rec.Date >= datefrom).ToList(); for (var i = 0; i < data.Count; i++) { - sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].TotalRain.ToString(cumulus.RainFormat, InvC)}]"); - - if (i < data.Count - 1) - sb.Append(","); + sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].TotalRain.ToString(cumulus.RainFormat, InvC)}],"); } + + // remove trailing comma + if (sb[sb.Length - 1] == ',') + sb.Length--; + sb.Append("]}"); return sb.ToString(); } @@ -10914,13 +10916,15 @@ public string GetSunHoursGraphData() for (var i = 0; i < data.Count; i++) { var sunhrs = data[i].SunShineHours >= 0 ? data[i].SunShineHours : 0; - sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{sunhrs.ToString(cumulus.SunFormat, InvC)}]"); - - if (i < data.Count - 1) - sb.Append(","); + sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{sunhrs.ToString(cumulus.SunFormat, InvC)}],"); } sb.Append("]"); } + + // remove trailing comma + if (sb[sb.Length - 1] == ',') + sb.Length--; + sb.Append("}"); return sb.ToString(); } @@ -10939,11 +10943,13 @@ public string GetDailyTempGraphData() for (var i = 0; i < data.Count; i++) { - sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].LowTemp.ToString(cumulus.TempFormat, InvC)}]"); - if (i < data.Count - 1) - sb.Append(","); + sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].LowTemp.ToString(cumulus.TempFormat, InvC)}],"); } + // remove trailing comma + if (sb[sb.Length - 1] == ',') + sb.Length--; + sb.Append("]"); append = true; } @@ -10957,11 +10963,13 @@ public string GetDailyTempGraphData() for (var i = 0; i < data.Count; i++) { - sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].HighTemp.ToString(cumulus.TempFormat, InvC)}]"); - if (i < data.Count - 1) - sb.Append(","); + sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].HighTemp.ToString(cumulus.TempFormat, InvC)}],"); } + // remove trailing comma + if (sb[sb.Length - 1] == ',') + sb.Length--; + sb.Append("]"); append = true; } @@ -10974,11 +10982,13 @@ public string GetDailyTempGraphData() sb.Append("\"avgtemp\":["); for (var i = 0; i < data.Count; i++) { - sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].AvgTemp.ToString(cumulus.TempFormat, InvC)}]"); - if (i < data.Count - 1) - sb.Append(","); + sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{data[i].AvgTemp.ToString(cumulus.TempFormat, InvC)}],"); } + // remove trailing comma + if (sb[sb.Length - 1] == ',') + sb.Length--; + sb.Append("]"); } @@ -11021,119 +11031,92 @@ public string GetAllDailyTempGraphData() var recDate = DateTimeToUnix(DayFile[i].Date) * 1000; // lo temp if (cumulus.GraphOptions.DailyMinTempVisible) - minTemp.Append($"[{recDate},{DayFile[i].LowTemp.ToString(cumulus.TempFormat, InvC)}]"); + minTemp.Append($"[{recDate},{DayFile[i].LowTemp.ToString(cumulus.TempFormat, InvC)}],"); // hi temp if (cumulus.GraphOptions.DailyMaxTempVisible) - maxTemp.Append($"[{recDate},{DayFile[i].HighTemp.ToString(cumulus.TempFormat, InvC)}]"); + maxTemp.Append($"[{recDate},{DayFile[i].HighTemp.ToString(cumulus.TempFormat, InvC)}],"); // avg temp if (cumulus.GraphOptions.DailyAvgTempVisible) - avgTemp.Append($"[{recDate},{DayFile[i].AvgTemp.ToString(cumulus.TempFormat, InvC)}]"); - - if (i < len) - { - minTemp.Append(","); - maxTemp.Append(","); - avgTemp.Append(","); - } + avgTemp.Append($"[{recDate},{DayFile[i].AvgTemp.ToString(cumulus.TempFormat, InvC)}],"); if (cumulus.GraphOptions.HIVisible) { // hi heat index if (DayFile[i].HighHeatIndex > -999) - heatIdx.Append($"[{recDate},{DayFile[i].HighHeatIndex.ToString(cumulus.TempFormat, InvC)}]"); + heatIdx.Append($"[{recDate},{DayFile[i].HighHeatIndex.ToString(cumulus.TempFormat, InvC)}],"); else - heatIdx.Append($"[{recDate},null]"); - - if (i < len) - heatIdx.Append(","); + heatIdx.Append($"[{recDate},null],"); } if (cumulus.GraphOptions.AppTempVisible) { // hi app temp if (DayFile[i].HighAppTemp > -999) - maxApp.Append($"[{recDate},{DayFile[i].HighAppTemp.ToString(cumulus.TempFormat, InvC)}]"); + maxApp.Append($"[{recDate},{DayFile[i].HighAppTemp.ToString(cumulus.TempFormat, InvC)}],"); else - maxApp.Append($"[{recDate},null]"); + maxApp.Append($"[{recDate},null],"); // lo app temp if (DayFile[i].LowAppTemp < 999) - minApp.Append($"[{recDate},{DayFile[i].LowAppTemp.ToString(cumulus.TempFormat, InvC)}]"); + minApp.Append($"[{recDate},{DayFile[i].LowAppTemp.ToString(cumulus.TempFormat, InvC)}],"); else - minApp.Append($"[{recDate},null]"); - - if (i < len) - { - maxApp.Append(","); - minApp.Append(","); - } + minApp.Append($"[{recDate},null],"); } // lo wind chill if (cumulus.GraphOptions.WCVisible) { if (DayFile[i].LowWindChill < 999) - windChill.Append($"[{recDate},{DayFile[i].LowWindChill.ToString(cumulus.TempFormat, InvC)}]"); + windChill.Append($"[{recDate},{DayFile[i].LowWindChill.ToString(cumulus.TempFormat, InvC)}],"); else - windChill.Append($"[{recDate},null]"); - - if (i < len) - windChill.Append(","); + windChill.Append($"[{recDate},null],"); } if (cumulus.GraphOptions.DPVisible) { // hi dewpt if (DayFile[i].HighDewPoint > -999) - maxDew.Append($"[{recDate},{DayFile[i].HighDewPoint.ToString(cumulus.TempFormat, InvC)}]"); + maxDew.Append($"[{recDate},{DayFile[i].HighDewPoint.ToString(cumulus.TempFormat, InvC)}],"); else - maxDew.Append($"[{recDate},null]"); + maxDew.Append($"[{recDate},null],"); // lo dewpt if (DayFile[i].LowDewPoint < 999) - minDew.Append($"[{recDate},{DayFile[i].LowDewPoint.ToString(cumulus.TempFormat, InvC)}]"); + minDew.Append($"[{recDate},{DayFile[i].LowDewPoint.ToString(cumulus.TempFormat, InvC)}],"); else - minDew.Append($"[{recDate},null]"); - - if (i < len) - { - maxDew.Append(","); - minDew.Append(","); - } + minDew.Append($"[{recDate},null],"); } if (cumulus.GraphOptions.FeelsLikeVisible) { // hi feels like if (DayFile[i].HighFeelsLike > -999) - maxFeels.Append($"[{recDate},{DayFile[i].HighFeelsLike.ToString(cumulus.TempFormat, InvC)}]"); + maxFeels.Append($"[{recDate},{DayFile[i].HighFeelsLike.ToString(cumulus.TempFormat, InvC)}],"); else - maxFeels.Append($"[{recDate},null]"); + maxFeels.Append($"[{recDate},null],"); // lo feels like if (DayFile[i].LowFeelsLike < 999) - minFeels.Append($"[{recDate},{DayFile[i].LowFeelsLike.ToString(cumulus.TempFormat, InvC)}]"); + minFeels.Append($"[{recDate},{DayFile[i].LowFeelsLike.ToString(cumulus.TempFormat, InvC)}],"); else - minFeels.Append($"[{recDate},null]"); - - if (i < len) - { - maxFeels.Append(","); - minFeels.Append(","); - } + minFeels.Append($"[{recDate},null],"); } if (cumulus.GraphOptions.HumidexVisible) { // hi humidex if (DayFile[i].HighHumidex > -999) - humidex.Append($"[{recDate},{DayFile[i].HighHumidex.ToString(cumulus.TempFormat, InvC)}]"); + humidex.Append($"[{recDate},{DayFile[i].HighHumidex.ToString(cumulus.TempFormat, InvC)}],"); else - humidex.Append($"[{recDate},null]"); - - if (i < len) - humidex.Append(","); + humidex.Append($"[{recDate},null],"); } } } + + // remove trailing commas + minTemp.Length--; + maxTemp.Length--; + avgTemp.Length--; + + if (cumulus.GraphOptions.DailyMinTempVisible) sb.Append("\"minTemp\":" + minTemp.ToString() + "],"); if (cumulus.GraphOptions.DailyMaxTempVisible) @@ -11141,26 +11124,41 @@ public string GetAllDailyTempGraphData() if (cumulus.GraphOptions.DailyAvgTempVisible) sb.Append("\"avgTemp\":" + avgTemp.ToString() + "],"); if (cumulus.GraphOptions.HIVisible) + { + heatIdx.Length--; sb.Append("\"heatIndex\":" + heatIdx.ToString() + "],"); + } if (cumulus.GraphOptions.AppTempVisible) { + maxApp.Length--; + minApp.Length--; sb.Append("\"maxApp\":" + maxApp.ToString() + "],"); sb.Append("\"minApp\":" + minApp.ToString() + "],"); } if (cumulus.GraphOptions.WCVisible) + { + windChill.Length--; sb.Append("\"windChill\":" + windChill.ToString() + "],"); + } if (cumulus.GraphOptions.DPVisible) { + maxDew.Length--; + minDew.Length--; sb.Append("\"maxDew\":" + maxDew.ToString() + "],"); sb.Append("\"minDew\":" + minDew.ToString() + "],"); } if (cumulus.GraphOptions.FeelsLikeVisible) { + maxFeels.Length--; + minFeels.Length--; sb.Append("\"maxFeels\":" + maxFeels.ToString() + "],"); sb.Append("\"minFeels\":" + minFeels.ToString() + "],"); } if (cumulus.GraphOptions.HumidexVisible) + { + humidex.Length--; sb.Append("\"humidex\":" + humidex.ToString() + "],"); + } sb.Length--; sb.Append("}"); @@ -11195,20 +11193,18 @@ public string GetAllDailyWindGraphData() var recDate = DateTimeToUnix(DayFile[i].Date) * 1000; // hi gust - maxGust.Append($"[{recDate},{DayFile[i].HighGust.ToString(cumulus.WindFormat, InvC)}]"); + maxGust.Append($"[{recDate},{DayFile[i].HighGust.ToString(cumulus.WindFormat, InvC)}],"); // hi wind run - windRun.Append($"[{recDate},{DayFile[i].WindRun.ToString(cumulus.WindRunFormat, InvC)}]"); + windRun.Append($"[{recDate},{DayFile[i].WindRun.ToString(cumulus.WindRunFormat, InvC)}],"); // hi wind - maxWind.Append($"[{recDate},{DayFile[i].HighAvgWind.ToString(cumulus.WindAvgFormat, InvC)}]"); - - if (i < len) - { - maxGust.Append(","); - windRun.Append(","); - maxWind.Append(","); - } + maxWind.Append($"[{recDate},{DayFile[i].HighAvgWind.ToString(cumulus.WindAvgFormat, InvC)}],"); } } + + maxGust.Length--; + windRun.Length--; + maxWind.Length--; + sb.Append("\"maxGust\":" + maxGust.ToString() + "],"); sb.Append("\"windRun\":" + windRun.ToString() + "],"); sb.Append("\"maxWind\":" + maxWind.ToString() + "]"); @@ -11244,17 +11240,15 @@ public string GetAllDailyRainGraphData() long recDate = DateTimeToUnix(DayFile[i].Date) * 1000; // hi rain rate - maxRRate.Append($"[{recDate},{DayFile[i].HighRainRate.ToString(cumulus.RainFormat, InvC)}]"); + maxRRate.Append($"[{recDate},{DayFile[i].HighRainRate.ToString(cumulus.RainFormat, InvC)}],"); // total rain - rain.Append($"[{recDate},{DayFile[i].TotalRain.ToString(cumulus.RainFormat, InvC)}]"); - - if (i < len) - { - maxRRate.Append(","); - rain.Append(","); - } + rain.Append($"[{recDate},{DayFile[i].TotalRain.ToString(cumulus.RainFormat, InvC)}],"); } } + + maxRRate.Length--; + rain.Length--; + sb.Append("\"maxRainRate\":" + maxRRate.ToString() + "],"); sb.Append("\"rain\":" + rain.ToString() + "]"); sb.Append("}"); @@ -11290,17 +11284,15 @@ public string GetAllDailyPressGraphData() long recDate = DateTimeToUnix(DayFile[i].Date) * 1000; // lo baro - minBaro.Append($"[{recDate},{DayFile[i].LowPress.ToString(cumulus.PressFormat, InvC)}]"); + minBaro.Append($"[{recDate},{DayFile[i].LowPress.ToString(cumulus.PressFormat, InvC)}],"); // hi baro - maxBaro.Append($"[{recDate},{DayFile[i].HighPress.ToString(cumulus.PressFormat, InvC)}]"); - - if (i < len) - { - maxBaro.Append(","); - minBaro.Append(","); - } + maxBaro.Append($"[{recDate},{DayFile[i].HighPress.ToString(cumulus.PressFormat, InvC)}],"); } } + + // Remove trailing commas + minBaro.Length--; + maxBaro.Length--; sb.Append("\"minBaro\":" + minBaro.ToString() + "],"); sb.Append("\"maxBaro\":" + maxBaro.ToString() + "]"); sb.Append("}"); @@ -11308,65 +11300,42 @@ public string GetAllDailyPressGraphData() return sb.ToString(); } - //public string GetAllDailyWindDirGraphData() - //{ - // int linenum = 0; - // int valInt; - - // /* returns: - // * { - // * highgust:[[date1,val1],[date2,val2]...], - // * mintemp:[[date1,val1],[date2,val2]...], - // * etc - // * } - // */ - - // StringBuilder sb = new StringBuilder("{"); - // StringBuilder windDir = new StringBuilder("["); - - // var watch = Stopwatch.StartNew(); - - // // Read the dayfile and extract the records from there - // if (File.Exists(cumulus.DayFile)) - // { - // try - // { - // var dayfile = File.ReadAllLines(cumulus.DayFile); - - // foreach (var line in dayfile) - // { - // linenum++; - // List st = new List(Regex.Split(line, CultureInfo.CurrentCulture.TextInfo.ListSeparator)); - - // if (st.Count <= 0) continue; - - // // dominant wind direction - // if (st.Count > 39) - // { - // long recDate = DateTimeToUnix(ddmmyyStrToDate(st[0])) * 1000; - - // if (int.TryParse(st[39], out valInt)) - // windDir.Append($"[{recDate},{valInt}]"); - // else - // windDir.Append($"[{recDate},null]"); - // if (linenum < dayfile.Length) - // windDir.Append(","); - // } - // } - // } - // catch (Exception e) - // { - // cumulus.LogMessage("GetAllDailyWindDirGraphData: Error on line " + linenum + " of " + cumulus.DayFile + ": " + e.Message); - // } - // } - // sb.Append("\"windDir\":" + windDir.ToString() + "]"); - // sb.Append("}"); - - // watch.Stop(); - // cumulus.LogDebugMessage($"GetAllDailyWindDirGraphData: Dayfile parse = {watch.ElapsedMilliseconds} ms"); - - // return sb.ToString(); - //} + public string GetAllDailyWindDirGraphData() + { + + /* returns: + * { + * highgust:[[date1,val1],[date2,val2]...], + * mintemp:[[date1,val1],[date2,val2]...], + * etc + * } + */ + + StringBuilder sb = new StringBuilder("{"); + StringBuilder windDir = new StringBuilder("["); + + + // Read the dayfile and extract the records from there + if (DayFile.Count() > 0) + { + var len = DayFile.Count() - 1; + + for (var i = 0; i < DayFile.Count(); i++) + { + long recDate = DateTimeToUnix(DayFile[i].Date) * 1000; + + windDir.Append($"[{recDate},{DayFile[i].DominantWindBearing.ToString()}],"); + + } + } + + // Remove trailing commas + windDir.Length--; + sb.Append("\"windDir\":" + windDir.ToString() + "]"); + sb.Append("}"); + + return sb.ToString(); + } public string GetAllDailyHumGraphData() { @@ -11393,17 +11362,15 @@ public string GetAllDailyHumGraphData() long recDate = DateTimeToUnix(DayFile[i].Date) * 1000; // lo humidity - minHum.Append($"[{recDate},{DayFile[i].LowHumidity}]"); + minHum.Append($"[{recDate},{DayFile[i].LowHumidity}],"); // hi humidity - maxHum.Append($"[{recDate},{DayFile[i].HighHumidity}]"); - - if (i < len) - { - minHum.Append(","); - maxHum.Append(","); - } + maxHum.Append($"[{recDate},{DayFile[i].HighHumidity}],"); } } + // Remove trailing commas + minHum.Length--; + maxHum.Length--; + sb.Append("\"minHum\":" + minHum.ToString() + "],"); sb.Append("\"maxHum\":" + maxHum.ToString() + "]"); sb.Append("}"); @@ -11440,36 +11407,35 @@ public string GetAllDailySolarGraphData() if (cumulus.GraphOptions.SunshineVisible) { // sunshine hours - sunHours.Append($"[{recDate},{DayFile[i].SunShineHours.ToString(InvC)}]"); - if (i < len) - sunHours.Append(","); + sunHours.Append($"[{recDate},{DayFile[i].SunShineHours.ToString(InvC)}],"); } if (cumulus.GraphOptions.SolarVisible) { // hi solar rad - solarRad.Append($"[{recDate},{DayFile[i].HighSolar}]"); - if (i < len) - solarRad.Append(","); + solarRad.Append($"[{recDate},{DayFile[i].HighSolar}],"); } if (cumulus.GraphOptions.UVVisible) { // hi UV-I - uvi.Append($"[{recDate},{DayFile[i].HighUv.ToString(cumulus.UVFormat, InvC)}]"); - if (i < len) - uvi.Append(","); + uvi.Append($"[{recDate},{DayFile[i].HighUv.ToString(cumulus.UVFormat, InvC)}],"); } } } + if (cumulus.GraphOptions.SunshineVisible) + { + sunHours.Length--; sb.Append("\"sunHours\":" + sunHours.ToString() + "]"); + } if (cumulus.GraphOptions.SolarVisible) { if (cumulus.GraphOptions.SunshineVisible) sb.Append(","); + solarRad.Length--; sb.Append("\"solarRad\":" + solarRad.ToString() + "]"); } @@ -11478,6 +11444,7 @@ public string GetAllDailySolarGraphData() if (cumulus.GraphOptions.SunshineVisible || cumulus.GraphOptions.SolarVisible) sb.Append(","); + uvi.Length--; sb.Append("\"uvi\":" + uvi.ToString() + "]"); } sb.Append("}"); From d43e0ed1c48a034735a62eea93c58dfac1d48637 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Mon, 20 Jun 2022 11:14:31 +0100 Subject: [PATCH 08/21] Fix: Ecowitt Extra Sensors setup error 500 --- CumulusMX/Api.cs | 6 +++--- CumulusMX/ExtraSensorSettings.cs | 10 +++++----- CumulusMX/StationSettings.cs | 2 +- Updates.txt | 7 +++++++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CumulusMX/Api.cs b/CumulusMX/Api.cs index 6e23eca6..671a9fce 100644 --- a/CumulusMX/Api.cs +++ b/CumulusMX/Api.cs @@ -481,9 +481,9 @@ public async Task GetDailyGraphData(string req) case "pressdata.json": await writer.WriteAsync(Station.GetAllDailyPressGraphData()); break; - //case "wdirdata.json": - //await writer.WriteAsync(Station.GetAllDailyWindDirGraphData()); - //break; + case "wdirdata.json": + await writer.WriteAsync(Station.GetAllDailyWindDirGraphData()); + break; case "humdata.json": await writer.WriteAsync(Station.GetAllDailyHumGraphData()); break; diff --git a/CumulusMX/ExtraSensorSettings.cs b/CumulusMX/ExtraSensorSettings.cs index f659d169..58911686 100644 --- a/CumulusMX/ExtraSensorSettings.cs +++ b/CumulusMX/ExtraSensorSettings.cs @@ -519,11 +519,11 @@ public class JsonExtraSensorAmbient public class JsonExtraSensorEcowitt : JsonExtraSensorAmbient { - internal bool setcustom { get; set; } - internal string gwaddr { get; set; } - internal string localaddr { get; set; } - internal int interval { get; set; } - internal JsonStationSettingsEcowittMappings mappings { get; set; } + public bool setcustom { get; set; } + public string gwaddr { get; set; } + public string localaddr { get; set; } + public int interval { get; set; } + public JsonStationSettingsEcowittMappings mappings { get; set; } } diff --git a/CumulusMX/StationSettings.cs b/CumulusMX/StationSettings.cs index 25c23d60..32f43324 100644 --- a/CumulusMX/StationSettings.cs +++ b/CumulusMX/StationSettings.cs @@ -1675,7 +1675,7 @@ internal class JsonStationSettingsEcowittApi public string mac { get; set; } } - internal class JsonStationSettingsEcowittMappings + public class JsonStationSettingsEcowittMappings { public int primaryTHsensor { get; set; } public int primaryRainSensor { get; set; } diff --git a/Updates.txt b/Updates.txt index d53a8024..54266966 100644 --- a/Updates.txt +++ b/Updates.txt @@ -1,3 +1,10 @@ +3.18.1 - b3191 +—————————————— +- Fix: Ecowitt Extra Sensors setup error 500 + +- Change: Migrate the log file viewers to the new date picker + + 3.18.0 - b3190 —————————————— - Fix: Adds Ecowitt Wh40 battery state decode From 416c43e00f3f45e68e54f73a081c16f843fb3a15 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Mon, 20 Jun 2022 13:21:27 +0100 Subject: [PATCH 09/21] StringBuilder optimisations --- CumulusMX/WeatherStation.cs | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index a8a369f8..652b7dbc 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -10708,7 +10708,7 @@ public string GetUnits() public string GetGraphConfig() { var json = new StringBuilder(200); - json.Append("{"); + json.Append('{'); json.Append($"\"temp\":{{\"units\":\"{cumulus.Units.TempText[1]}\",\"decimals\":{cumulus.TempDPlaces}}},"); json.Append($"\"wind\":{{\"units\":\"{cumulus.Units.WindText}\",\"decimals\":{cumulus.WindAvgDPlaces},\"rununits\":\"{cumulus.Units.WindRunText}\"}},"); json.Append($"\"rain\":{{\"units\":\"{cumulus.Units.RainText}\",\"decimals\":{cumulus.RainDPlaces}}},"); @@ -10793,7 +10793,7 @@ public string GetAvailGraphData() if (json[json.Length - 1] == ',') json.Length--; - json.Append("]"); + json.Append(']'); } @@ -10811,7 +10811,7 @@ public string GetAvailGraphData() if (json[json.Length - 1] == ',') json.Length--; - json.Append("]"); + json.Append(']'); } // Sunshine @@ -10835,7 +10835,7 @@ public string GetAvailGraphData() { json.Append(",\"PM 10\""); } - json.Append("]"); + json.Append(']'); } // Degree Days @@ -10851,7 +10851,7 @@ public string GetAvailGraphData() if (json[json.Length - 1] == ',') json.Length--; - json.Append("]"); + json.Append(']'); } // Temp Sum @@ -10868,10 +10868,10 @@ public string GetAvailGraphData() if (json[json.Length - 1] == ',') json.Length--; - json.Append("]"); + json.Append(']'); } - json.Append("}"); + json.Append('}'); return json.ToString(); } @@ -10918,14 +10918,14 @@ public string GetSunHoursGraphData() var sunhrs = data[i].SunShineHours >= 0 ? data[i].SunShineHours : 0; sb.Append($"[{DateTimeToUnix(data[i].Date) * 1000},{sunhrs.ToString(cumulus.SunFormat, InvC)}],"); } - sb.Append("]"); + sb.Append(']'); } // remove trailing comma if (sb[sb.Length - 1] == ',') sb.Length--; - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -10950,14 +10950,14 @@ public string GetDailyTempGraphData() if (sb[sb.Length - 1] == ',') sb.Length--; - sb.Append("]"); + sb.Append(']'); append = true; } if (cumulus.GraphOptions.DailyMaxTempVisible) { if (append) - sb.Append(","); + sb.Append(','); sb.Append("\"maxtemp\":["); @@ -10970,14 +10970,14 @@ public string GetDailyTempGraphData() if (sb[sb.Length - 1] == ',') sb.Length--; - sb.Append("]"); + sb.Append(']'); append = true; } if (cumulus.GraphOptions.DailyAvgTempVisible) { if (append) - sb.Append(","); + sb.Append(','); sb.Append("\"avgtemp\":["); for (var i = 0; i < data.Count; i++) @@ -10989,10 +10989,10 @@ public string GetDailyTempGraphData() if (sb[sb.Length - 1] == ',') sb.Length--; - sb.Append("]"); + sb.Append(']'); } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11161,7 +11161,7 @@ public string GetAllDailyTempGraphData() } sb.Length--; - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11208,7 +11208,7 @@ public string GetAllDailyWindGraphData() sb.Append("\"maxGust\":" + maxGust.ToString() + "],"); sb.Append("\"windRun\":" + windRun.ToString() + "],"); sb.Append("\"maxWind\":" + maxWind.ToString() + "]"); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11251,7 +11251,7 @@ public string GetAllDailyRainGraphData() sb.Append("\"maxRainRate\":" + maxRRate.ToString() + "],"); sb.Append("\"rain\":" + rain.ToString() + "]"); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11295,7 +11295,7 @@ public string GetAllDailyPressGraphData() maxBaro.Length--; sb.Append("\"minBaro\":" + minBaro.ToString() + "],"); sb.Append("\"maxBaro\":" + maxBaro.ToString() + "]"); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11332,7 +11332,7 @@ public string GetAllDailyWindDirGraphData() // Remove trailing commas windDir.Length--; sb.Append("\"windDir\":" + windDir.ToString() + "]"); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11373,7 +11373,7 @@ public string GetAllDailyHumGraphData() sb.Append("\"minHum\":" + minHum.ToString() + "],"); sb.Append("\"maxHum\":" + maxHum.ToString() + "]"); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11433,7 +11433,7 @@ public string GetAllDailySolarGraphData() if (cumulus.GraphOptions.SolarVisible) { if (cumulus.GraphOptions.SunshineVisible) - sb.Append(","); + sb.Append(','); solarRad.Length--; sb.Append("\"solarRad\":" + solarRad.ToString() + "]"); @@ -11442,12 +11442,12 @@ public string GetAllDailySolarGraphData() if (cumulus.GraphOptions.UVVisible) { if (cumulus.GraphOptions.SunshineVisible || cumulus.GraphOptions.SolarVisible) - sb.Append(","); + sb.Append(','); uvi.Length--; sb.Append("\"uvi\":" + uvi.ToString() + "]"); } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11621,7 +11621,7 @@ public string GetAllDegreeDaysGraphData() sb.Append(options); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11789,7 +11789,7 @@ public string GetAllTempSumGraphData() sb.Append("\"Sum0\":" + tempSumYears0 + "}"); if (cumulus.GraphOptions.TempSumVisible1 || cumulus.GraphOptions.TempSumVisible2) - sb.Append(","); + sb.Append(','); } if (cumulus.GraphOptions.TempSumVisible1) { @@ -11830,7 +11830,7 @@ public string GetAllTempSumGraphData() sb.Append(options); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -11844,7 +11844,7 @@ internal string GetCurrentData() { for (var i = 1; i < cumulus.NumWindRosePoints; i++) { - windRoseData.Append(","); + windRoseData.Append(','); windRoseData.Append((windcounts[i] * cumulus.Calib.WindGust.Mult).ToString(cumulus.WindFormat, CultureInfo.InvariantCulture)); } } From a724dd970a1df41675090527633b55187015e892 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Mon, 20 Jun 2022 13:28:07 +0100 Subject: [PATCH 10/21] StringBuilder optimisations --- CumulusMX/ApiTagProcessor.cs | 2 +- CumulusMX/Cumulus.cs | 6 +- CumulusMX/DataEditor.cs | 6 +- CumulusMX/DavisAirLink.cs | 16 +-- CumulusMX/DavisWllStation.cs | 16 +-- CumulusMX/IniFile.cs | 2 +- CumulusMX/InternetSettings.cs | 6 +- CumulusMX/SQLite.cs | 6 +- CumulusMX/WMR200Station.cs | 2 +- CumulusMX/WS2300Station.cs | 2 +- CumulusMX/WeatherStation.cs | 258 +++++++++++++++++----------------- 11 files changed, 161 insertions(+), 161 deletions(-) diff --git a/CumulusMX/ApiTagProcessor.cs b/CumulusMX/ApiTagProcessor.cs index 35003543..c4ef777f 100644 --- a/CumulusMX/ApiTagProcessor.cs +++ b/CumulusMX/ApiTagProcessor.cs @@ -67,7 +67,7 @@ public string ProcessJson(IHttpRequest request) // remove trailing "," output.Remove(output.Length - 1, 1); } - output.Append("}"); + output.Append('}'); cumulus.LogDataMessage("API tag: Output string = " + output); } diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index 399aa071..fcabdf86 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -7061,7 +7061,7 @@ public async void DoLogFile(DateTime timestamp, bool live) values.Append(station.CompassPoint(station.Bearing) + "',"); values.Append(station.FeelsLike.ToString(TempFormat, InvC) + ","); values.Append(station.Humidex.ToString(TempFormat, InvC)); - values.Append(")"); + values.Append(')'); string queryString = values.ToString(); @@ -7371,7 +7371,7 @@ public async void DoAirLinkLogFile(DateTime timestamp) { sb.Append("0" + ListSeparator); } - sb.Append("0"); + sb.Append('0'); } var success = false; @@ -9156,7 +9156,7 @@ public void MySqlRealtimeFile(int cycle, bool live, DateTime? logdate = null) values.Append(((int)Math.Round(station.CurrentSolarMax)).ToString() + ",'"); values.Append((station.IsSunny ? "1" : "0") + "',"); values.Append(station.FeelsLike.ToString(TempFormat, InvC)); - values.Append(")"); + values.Append(')'); string valuesString = values.ToString(); List cmds = new List() { valuesString }; diff --git a/CumulusMX/DataEditor.cs b/CumulusMX/DataEditor.cs index 8b23f741..569e970a 100644 --- a/CumulusMX/DataEditor.cs +++ b/CumulusMX/DataEditor.cs @@ -233,7 +233,7 @@ internal string GetAllTimeRecData() json.Append($"\"highMonthlyRainTime\":\"{station.AllTime.MonthlyRain.GetTsString("MM/yyyy")}\","); json.Append($"\"longestDryPeriodTime\":\"{station.AllTime.LongestDryPeriod.GetTsString(dateStampFormat)}\","); json.Append($"\"longestWetPeriodTime\":\"{station.AllTime.LongestWetPeriod.GetTsString(dateStampFormat)}\""); - json.Append("}"); + json.Append('}'); return json.ToString(); } @@ -1651,7 +1651,7 @@ internal string GetMonthlyRecData() json.Append($"\"{m}-longestWetPeriodTime\":\"{station.MonthlyRecs[m].LongestWetPeriod.GetTsString(dateStampFormat)}\","); } json.Length--; - json.Append("}"); + json.Append('}'); return json.ToString(); } @@ -2582,7 +2582,7 @@ internal string GetMonthlyRecLogFile() } json.Length--; - json.Append("}"); + json.Append('}'); watch.Stop(); var elapsed = watch.ElapsedMilliseconds; diff --git a/CumulusMX/DavisAirLink.cs b/CumulusMX/DavisAirLink.cs index 5a664ac3..bb5f3451 100644 --- a/CumulusMX/DavisAirLink.cs +++ b/CumulusMX/DavisAirLink.cs @@ -672,9 +672,9 @@ private void GetWlHistoricData() foreach (KeyValuePair entry in parameters) { historicUrl.Append(entry.Key); - historicUrl.Append("="); + historicUrl.Append('='); historicUrl.Append(entry.Value); - historicUrl.Append("&"); + historicUrl.Append('&'); } // remove the trailing "&" historicUrl.Remove(historicUrl.Length - 1, 1); @@ -1114,9 +1114,9 @@ private void GetWlHistoricHealth() foreach (KeyValuePair entry in parameters) { historicUrl.Append(entry.Key); - historicUrl.Append("="); + historicUrl.Append('='); historicUrl.Append(entry.Value); - historicUrl.Append("&"); + historicUrl.Append('&'); } // remove the trailing "&" historicUrl.Remove(historicUrl.Length - 1, 1); @@ -1379,9 +1379,9 @@ private bool GetAvailableStationIds() foreach (KeyValuePair entry in parameters) { stationsUrl.Append(entry.Key); - stationsUrl.Append("="); + stationsUrl.Append('='); stationsUrl.Append(entry.Value); - stationsUrl.Append("&"); + stationsUrl.Append('&'); } // remove the trailing "&" stationsUrl.Remove(stationsUrl.Length - 1, 1); @@ -1498,9 +1498,9 @@ private void GetAvailableSensors() foreach (KeyValuePair entry in parameters) { sensorsUrl.Append(entry.Key); - sensorsUrl.Append("="); + sensorsUrl.Append('='); sensorsUrl.Append(entry.Value); - sensorsUrl.Append("&"); + sensorsUrl.Append('&'); } // remove the trailing "&" sensorsUrl.Remove(sensorsUrl.Length - 1, 1); diff --git a/CumulusMX/DavisWllStation.cs b/CumulusMX/DavisWllStation.cs index 64bcfd69..a5249630 100644 --- a/CumulusMX/DavisWllStation.cs +++ b/CumulusMX/DavisWllStation.cs @@ -1568,9 +1568,9 @@ private void GetWlHistoricData(BackgroundWorker worker) foreach (KeyValuePair entry in parameters) { historicUrl.Append(entry.Key); - historicUrl.Append("="); + historicUrl.Append('='); historicUrl.Append(entry.Value); - historicUrl.Append("&"); + historicUrl.Append('&'); } // remove the trailing "&" historicUrl.Remove(historicUrl.Length - 1, 1); @@ -2915,9 +2915,9 @@ private void GetWlHistoricHealth() foreach (KeyValuePair entry in parameters) { historicUrl.Append(entry.Key); - historicUrl.Append("="); + historicUrl.Append('='); historicUrl.Append(entry.Value); - historicUrl.Append("&"); + historicUrl.Append('&'); } // remove the trailing "&" historicUrl.Remove(historicUrl.Length - 1, 1); @@ -3094,9 +3094,9 @@ private void GetAvailableStationIds(bool logToConsole = false) foreach (KeyValuePair entry in parameters) { stationsUrl.Append(entry.Key); - stationsUrl.Append("="); + stationsUrl.Append('='); stationsUrl.Append(entry.Value); - stationsUrl.Append("&"); + stationsUrl.Append('&'); } // remove the trailing "&" stationsUrl.Remove(stationsUrl.Length - 1, 1); @@ -3207,9 +3207,9 @@ private void GetAvailableSensors() foreach (KeyValuePair entry in parameters) { stationsUrl.Append(entry.Key); - stationsUrl.Append("="); + stationsUrl.Append('='); stationsUrl.Append(entry.Value); - stationsUrl.Append("&"); + stationsUrl.Append('&'); } // remove the trailing "&" stationsUrl.Remove(stationsUrl.Length - 1, 1); diff --git a/CumulusMX/IniFile.cs b/CumulusMX/IniFile.cs index 2877ade6..b04048c7 100644 --- a/CumulusMX/IniFile.cs +++ b/CumulusMX/IniFile.cs @@ -321,7 +321,7 @@ private string EncodeByteArray(byte[] Value) } else { - if (l < 2) sb.Append("0"); + if (l < 2) sb.Append('0'); sb.Append(hex); } } diff --git a/CumulusMX/InternetSettings.cs b/CumulusMX/InternetSettings.cs index 05359e00..ea4293f6 100644 --- a/CumulusMX/InternetSettings.cs +++ b/CumulusMX/InternetSettings.cs @@ -559,13 +559,13 @@ public string GetExtraWebFilesData() string utf8 = cumulus.ExtraFiles[i].UTF8 ? "true" : "false"; string binary = cumulus.ExtraFiles[i].binary ? "true" : "false"; string endofday = cumulus.ExtraFiles[i].endofday ? "true" : "false"; - json.Append("{"); + json.Append('{'); json.Append($"\"id\":{(i + 1)},\"values\":[\"{local}\",\"{remote}\",\"{process}\",\"{realtime}\",\"{ftp}\",\"{utf8}\",\"{binary}\",\"{endofday}\"]"); - json.Append("}"); + json.Append('}'); if (i < Cumulus.numextrafiles - 1) { - json.Append(","); + json.Append(','); } } diff --git a/CumulusMX/SQLite.cs b/CumulusMX/SQLite.cs index 502d069c..76e460a5 100644 --- a/CumulusMX/SQLite.cs +++ b/CumulusMX/SQLite.cs @@ -2803,15 +2803,15 @@ private CompileResult CompileExpr (Expression expr, List queryArgs) // if (val != null && val is System.Collections.IEnumerable && !(val is string) && !(val is System.Collections.Generic.IEnumerable)) { var sb = new System.Text.StringBuilder(); - sb.Append("("); + sb.Append('('); var head = ""; foreach (var a in (System.Collections.IEnumerable)val) { queryArgs.Add(a); sb.Append(head); - sb.Append("?"); + sb.Append('?'); head = ","; } - sb.Append(")"); + sb.Append(')'); return new CompileResult { CommandText = sb.ToString(), Value = val diff --git a/CumulusMX/WMR200Station.cs b/CumulusMX/WMR200Station.cs index 64754aae..95c3321d 100644 --- a/CumulusMX/WMR200Station.cs +++ b/CumulusMX/WMR200Station.cs @@ -1625,7 +1625,7 @@ private void ProcessWMR200Packet() for (int i = 0; i < packetBuffer[1]; i++) { str.Append(packetBuffer[i].ToString("X2")); - str.Append(" "); + str.Append(' '); } cumulus.LogDataMessage($"Packet:{str}"); diff --git a/CumulusMX/WS2300Station.cs b/CumulusMX/WS2300Station.cs index 905f31d1..f783a790 100644 --- a/CumulusMX/WS2300Station.cs +++ b/CumulusMX/WS2300Station.cs @@ -547,7 +547,7 @@ private int Ws2300ReadHistoryRecord(int record, out int address, out double temp for (int n = 0; n < bytes; n++) { msg.Append(data[n].ToString("X2")); - msg.Append(" "); + msg.Append(' '); } cumulus.LogMessage(msg.ToString()); diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 652b7dbc..d410d00e 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -1492,7 +1492,7 @@ private async Task sendWebSocketData() for (var i = 1; i < cumulus.NumWindRosePoints; i++) { - windRoseData.Append(","); + windRoseData.Append(','); windRoseData.Append((windcounts[i] * cumulus.Calib.WindGust.Mult).ToString(cumulus.WindFormat, CultureInfo.InvariantCulture)); } } @@ -1864,7 +1864,7 @@ private void MinuteChanged(DateTime now) xapReport.Append($"DewF={ConvertUserTempToF(OutdoorDewpoint):F1}\n"); xapReport.Append($"AirPressure={ConvertUserPressToMB(Pressure):F1}\n"); xapReport.Append($"Rain={ConvertUserRainToMM(RainToday):F1}\n"); - xapReport.Append("}"); + xapReport.Append('}'); data = Encoding.ASCII.GetBytes(xapReport.ToString()); @@ -2276,7 +2276,7 @@ public string GetSolarGraphData() if (sbUv[sbUv.Length - 1] == ',') sbUv.Length--; - sbUv.Append("]"); + sbUv.Append(']'); sb.Append(sbUv); } if (cumulus.GraphOptions.SolarVisible) @@ -2287,18 +2287,18 @@ public string GetSolarGraphData() sbMax.Length--; } - sbSol.Append("]"); - sbMax.Append("]"); + sbSol.Append(']'); + sbMax.Append(']'); if (cumulus.GraphOptions.UVVisible) { - sb.Append(","); + sb.Append(','); } sb.Append(sbSol); - sb.Append(","); + sb.Append(','); sb.Append(sbMax); } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2327,10 +2327,10 @@ public string GetRainGraphData() sbRate.Length--; } sbRain.Append("],"); - sbRate.Append("]"); + sbRate.Append(']'); sb.Append(sbRain); sb.Append(sbRate); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2361,7 +2361,7 @@ public string GetHumGraphData() if (sbOut[sbOut.Length - 1] == ',') sbOut.Length--; - sbOut.Append("]"); + sbOut.Append(']'); sb.Append(sbOut); } @@ -2371,15 +2371,15 @@ public string GetHumGraphData() if (sbIn[sbIn.Length - 1] == ',') sbIn.Length--; - sbIn.Append("]"); + sbIn.Append(']'); if (cumulus.GraphOptions.OutHumVisible) - sb.Append(","); + sb.Append(','); sb.Append(sbIn); } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2402,12 +2402,12 @@ public string GetWindDirGraphData() { sb.Length--; sbAvg.Length--; - sbAvg.Append("]"); + sbAvg.Append(']'); } sb.Append("],"); sb.Append(sbAvg); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2431,12 +2431,12 @@ public string GetWindGraphData() { sb.Length--; sbSpd.Length--; - sbSpd.Append("]"); + sbSpd.Append(']'); } sb.Append("],"); sb.Append(sbSpd); - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2509,7 +2509,7 @@ public string GetTempGraphData() if (sbIn[sbIn.Length - 1] == ',') sbIn.Length--; - sbIn.Append("]"); + sbIn.Append(']'); sb.Append(sbIn); append = true; } @@ -2519,7 +2519,7 @@ public string GetTempGraphData() if (sbDew[sbDew.Length - 1] == ',') sbDew.Length--; - sbDew.Append("]"); + sbDew.Append(']'); sb.Append((append ? "," : "") + sbDew); append = true; } @@ -2529,7 +2529,7 @@ public string GetTempGraphData() if (sbApp[sbApp.Length - 1] == ',') sbApp.Length--; - sbApp.Append("]"); + sbApp.Append(']'); sb.Append((append ? "," : "") + sbApp); append = true; } @@ -2539,7 +2539,7 @@ public string GetTempGraphData() if (sbFeel[sbFeel.Length - 1] == ',') sbFeel.Length--; - sbFeel.Append("]"); + sbFeel.Append(']'); sb.Append((append ? "," : "") + sbFeel); append = true; } @@ -2549,7 +2549,7 @@ public string GetTempGraphData() if (sbChill[sbChill.Length - 1] == ',') sbChill.Length--; - sbChill.Append("]"); + sbChill.Append(']'); sb.Append((append ? "," : "") + sbChill); append = true; } @@ -2559,7 +2559,7 @@ public string GetTempGraphData() if (sbHeat[sbHeat.Length - 1] == ',') sbHeat.Length--; - sbHeat.Append("]"); + sbHeat.Append(']'); sb.Append((append ? "," : "") + sbHeat); append = true; } @@ -2569,7 +2569,7 @@ public string GetTempGraphData() if (sbTemp[sbTemp.Length - 1] == ',') sbTemp.Length--; - sbTemp.Append("]"); + sbTemp.Append(']'); sb.Append((append ? "," : "") + sbTemp); append = true; } @@ -2579,11 +2579,11 @@ public string GetTempGraphData() if (sbHumidex[sbHumidex.Length - 1] == ',') sbHumidex.Length--; - sbHumidex.Append("]"); + sbHumidex.Append(']'); sb.Append((append ? "," : "") + sbHumidex); } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -2622,7 +2622,7 @@ public string GetAqGraphData() if (sb2p5[sb2p5.Length - 1] == ',') sb2p5.Length--; - sb2p5.Append("]"); + sb2p5.Append(']'); sb.Append(sb2p5); if (append) @@ -2630,13 +2630,13 @@ public string GetAqGraphData() if (sb10[sb10.Length - 1] == ',') sb10.Length--; - sb10.Append("]"); + sb10.Append(']'); sb.Append(sb10); } } - sb.Append("}"); + sb.Append('}'); return sb.ToString(); } @@ -5730,7 +5730,7 @@ private async void DoDayfile(DateTime timestamp) queryString.Append(HiLoToday.HighHumidex.ToString(cumulus.TempFormat, InvC) + ","); queryString.Append(HiLoToday.HighHumidexTime.ToString("\\'HH:mm\\'")); - queryString.Append(")"); + queryString.Append(')'); // run the query async so we do not block the main EOD processing _ = cumulus.MySqlCommandAsync(queryString.ToString(), "MySQL Dayfile"); @@ -8763,7 +8763,7 @@ public string GetAwekasURLv4(out string pwstring, DateTime timestamp) if (cumulus.AWEKAS.SendSoilTemp) { - if (started) sb.Append("&"); else started = true; + if (started) sb.Append('&'); else started = true; for (var i = 1; i <= 4; i++) { sb.Append($"soiltemp{i}=" + ConvertUserTempToC(SoilTemp[i]).ToString("F1", InvC)); @@ -8772,7 +8772,7 @@ public string GetAwekasURLv4(out string pwstring, DateTime timestamp) if (cumulus.AWEKAS.SendSoilMoisture) { - if (started) sb.Append("&"); else started = true; + if (started) sb.Append('&'); else started = true; sb.Append("soilmoisture1=" + SoilMoisture1); sb.Append("&soilmoisture2=" + SoilMoisture2); sb.Append("&soilmoisture3=" + SoilMoisture3); @@ -8781,7 +8781,7 @@ public string GetAwekasURLv4(out string pwstring, DateTime timestamp) if (cumulus.AWEKAS.SendLeafWetness) { - if (started) sb.Append("&"); else started = true; + if (started) sb.Append('&'); else started = true; sb.Append("leafwetness1=" + LeafWetness1.ToString(cumulus.LeafWetFormat)); sb.Append("&leafwetness2=" + LeafWetness2.ToString(cumulus.LeafWetFormat)); sb.Append("&leafwetness3=" + LeafWetness3.ToString(cumulus.LeafWetFormat)); @@ -8790,7 +8790,7 @@ public string GetAwekasURLv4(out string pwstring, DateTime timestamp) if (cumulus.AWEKAS.SendAirQuality) { - if (started) sb.Append("&"); else started = true; + if (started) sb.Append('&'); else started = true; switch (cumulus.StationOptions.PrimaryAqSensor) { @@ -8829,7 +8829,7 @@ public string GetAwekasURLv4(out string pwstring, DateTime timestamp) } } - if (started) sb.Append("&"); + if (started) sb.Append('&'); sb.Append("output=json&val="); // @@ -9410,7 +9410,7 @@ public string GetHumRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(alltimejsonformat(AllTime.HighHumidity, "%", cumulus.HumFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.LowHumidity, "%", cumulus.HumFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9421,7 +9421,7 @@ public string GetPressRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(alltimejsonformat(AllTime.HighPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.LowPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9432,9 +9432,9 @@ public string GetWindRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(alltimejsonformat(AllTime.HighGust, cumulus.Units.WindText, cumulus.WindFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.HighWind, cumulus.Units.WindText, cumulus.WindAvgFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.HighWindRun, cumulus.Units.WindRunText, cumulus.WindRunFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9445,17 +9445,17 @@ public string GetRainRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(alltimejsonformat(AllTime.HighRainRate, cumulus.Units.RainText + "/hr", cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.HourlyRain, cumulus.Units.RainText, cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.DailyRain, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.Rain24Hours, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.MonthlyRain, cumulus.Units.RainText, cumulus.RainFormat, "Y")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.LongestDryPeriod, "days", "f0", "D")); - json.Append(","); + json.Append(','); json.Append(alltimejsonformat(AllTime.LongestWetPeriod, "days", "f0", "D")); json.Append("]}"); return json.ToString(); @@ -9471,33 +9471,33 @@ public string GetMonthlyTempRecords(int month) var json = new StringBuilder("{\"data\":[", 1024); json.Append(monthlyjsonformat(MonthlyRecs[month].HighTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighHumidex, " ", cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowChill, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighHeatIndex, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighMinTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowMaxTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9508,7 +9508,7 @@ public string GetMonthlyHumRecords(int month) var json = new StringBuilder("{\"data\":[", 256); json.Append(monthlyjsonformat(MonthlyRecs[month].HighHumidity, "%", cumulus.HumFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowHumidity, "%", cumulus.HumFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9519,7 +9519,7 @@ public string GetMonthlyPressRecords(int month) var json = new StringBuilder("{\"data\":[", 256); json.Append(monthlyjsonformat(MonthlyRecs[month].HighPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LowPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9530,9 +9530,9 @@ public string GetMonthlyWindRecords(int month) var json = new StringBuilder("{\"data\":[", 256); json.Append(monthlyjsonformat(MonthlyRecs[month].HighGust, cumulus.Units.WindText, cumulus.WindFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighWind, cumulus.Units.WindText, cumulus.WindAvgFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HighWindRun, cumulus.Units.WindRunText, cumulus.WindRunFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9543,17 +9543,17 @@ public string GetMonthlyRainRecords(int month) var json = new StringBuilder("{\"data\":[", 512); json.Append(monthlyjsonformat(MonthlyRecs[month].HighRainRate, cumulus.Units.RainText + "/hr", cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].HourlyRain, cumulus.Units.RainText, cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].DailyRain, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].Rain24Hours, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].MonthlyRain, cumulus.Units.RainText, cumulus.RainFormat, "Y")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LongestDryPeriod, "days", "f0", "D")); - json.Append(","); + json.Append(','); json.Append(monthlyjsonformat(MonthlyRecs[month].LongestWetPeriod, "days", "f0", "D")); json.Append("]}"); return json.ToString(); @@ -9569,33 +9569,33 @@ public string GetThisMonthTempRecords() var json = new StringBuilder("{\"data\":[", 1024); json.Append(monthyearjsonformat(ThisMonth.HighTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighHumidex, " ", cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowChill, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighHeatIndex, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighMinTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowMaxTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9606,7 +9606,7 @@ public string GetThisMonthHumRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisMonth.HighHumidity, "%", cumulus.HumFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowHumidity, "%", cumulus.HumFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9617,7 +9617,7 @@ public string GetThisMonthPressRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisMonth.HighPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LowPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9628,9 +9628,9 @@ public string GetThisMonthWindRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisMonth.HighGust, cumulus.Units.WindText, cumulus.WindFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighWind, cumulus.Units.WindText, cumulus.WindAvgFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HighWindRun, cumulus.Units.WindRunText, cumulus.WindRunFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9641,17 +9641,17 @@ public string GetThisMonthRainRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(monthyearjsonformat(ThisMonth.HighRainRate, cumulus.Units.RainText + "/hr", cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.HourlyRain, cumulus.Units.RainText, cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.DailyRain, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.Rain24Hours, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); //json.Append(monthyearjsonformat(ThisMonth.WetMonth.Desc, month, cumulus.Units.RainText, cumulus.RainFormat, "Y")); - //json.Append(","); + //json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LongestDryPeriod, "days", "f0", "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisMonth.LongestWetPeriod, "days", "f0", "D")); json.Append("]}"); return json.ToString(); @@ -9662,33 +9662,33 @@ public string GetThisYearTempRecords() var json = new StringBuilder("{\"data\":[", 1024); json.Append(monthyearjsonformat(ThisYear.HighTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowDewPoint, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowAppTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowFeelsLike, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighHumidex, " ", cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowChill, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighHeatIndex, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighMinTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowMaxTemp, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowDailyTempRange, "°" + cumulus.Units.TempText[1].ToString(), cumulus.TempFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9699,7 +9699,7 @@ public string GetThisYearHumRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisYear.HighHumidity, "%", cumulus.HumFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowHumidity, "%", cumulus.HumFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9710,7 +9710,7 @@ public string GetThisYearPressRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisYear.HighPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LowPress, cumulus.Units.PressText, cumulus.PressFormat, "f")); json.Append("]}"); return json.ToString(); @@ -9721,9 +9721,9 @@ public string GetThisYearWindRecords() var json = new StringBuilder("{\"data\":[", 256); json.Append(monthyearjsonformat(ThisYear.HighGust, cumulus.Units.WindText, cumulus.WindFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighWind, cumulus.Units.WindText, cumulus.WindAvgFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HighWindRun, cumulus.Units.WindRunText, cumulus.WindRunFormat, "D")); json.Append("]}"); return json.ToString(); @@ -9734,17 +9734,17 @@ public string GetThisYearRainRecords() var json = new StringBuilder("{\"data\":[", 512); json.Append(monthyearjsonformat(ThisYear.HighRainRate, cumulus.Units.RainText + "/hr", cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.HourlyRain, cumulus.Units.RainText, cumulus.RainFormat, "f")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.DailyRain, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.Rain24Hours, cumulus.Units.RainText, cumulus.RainFormat, "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.MonthlyRain, cumulus.Units.RainText, cumulus.RainFormat, "Y")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LongestDryPeriod, "days", "f0", "D")); - json.Append(","); + json.Append(','); json.Append(monthyearjsonformat(ThisYear.LongestWetPeriod, "days", "f0", "D")); json.Append("]}"); return json.ToString(); @@ -9766,7 +9766,7 @@ public string GetExtraTemp() if (sensor < 10) { - json.Append(","); + json.Append(','); } } @@ -9790,7 +9790,7 @@ public string GetUserTemp() if (sensor < 8) { - json.Append(","); + json.Append(','); } } @@ -9812,7 +9812,7 @@ public string GetExtraHum() if (sensor < 10) { - json.Append(","); + json.Append(','); } } @@ -9836,7 +9836,7 @@ public string GetExtraDew() if (sensor < 10) { - json.Append(","); + json.Append(','); } } @@ -10445,7 +10445,7 @@ public string GetDayfile(string draw, int start, int length) json.Append($"\"{fields[i]}\""); if (i < fields.Length - 1) { - json.Append(","); + json.Append(','); } } @@ -11593,7 +11593,7 @@ public string GetAllDegreeDaysGraphData() // have previous years been appended? if (growdegdaysYears1[growdegdaysYears1.Length - 1] == ']') { - growdegdaysYears1.Append(","); + growdegdaysYears1.Append(','); } growdegdaysYears1.Append(growYear1 + "]"); @@ -11611,7 +11611,7 @@ public string GetAllDegreeDaysGraphData() // have previous years been appended? if (growdegdaysYears2[growdegdaysYears2.Length - 1] == ']') { - growdegdaysYears2.Append(","); + growdegdaysYears2.Append(','); } growdegdaysYears2.Append(growYear2 + "]"); @@ -11780,7 +11780,7 @@ public string GetAllTempSumGraphData() // have previous years been appended? if (tempSumYears0[tempSumYears0.Length - 1] == ']') { - tempSumYears0.Append(","); + tempSumYears0.Append(','); } tempSumYears0.Append(tempSum0 + "]"); @@ -11801,7 +11801,7 @@ public string GetAllTempSumGraphData() // have previous years been appended? if (tempSumYears1[tempSumYears1.Length - 1] == ']') { - tempSumYears1.Append(","); + tempSumYears1.Append(','); } tempSumYears1.Append(tempSum1 + "]"); @@ -11819,7 +11819,7 @@ public string GetAllTempSumGraphData() // have previous years been appended? if (tempSumYears2[tempSumYears2.Length - 1] == ']') { - tempSumYears2.Append(","); + tempSumYears2.Append(','); } tempSumYears2.Append(tempSum2 + "]"); @@ -12038,7 +12038,7 @@ public void UpdateAPRS() message.Append($"r{APRSrain(RainLastHour)}"); // rain last 24 hours 0.01 inches pnnn message.Append($"p{APRSrain(RainLast24Hour)}"); - message.Append("P"); + message.Append('P'); if (cumulus.RolloverHour == 0) { // use today"s rain for safety From b03a1f5f6e6fb5ea99fb50e5ad8ab8753efbf543 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Wed, 22 Jun 2022 18:08:12 +0100 Subject: [PATCH 11/21] Update MQTTnet package --- CumulusMX/CumulusMX.csproj | 4 ++-- CumulusMX/packages.config | 2 +- Updates.txt | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CumulusMX/CumulusMX.csproj b/CumulusMX/CumulusMX.csproj index 2490252d..2ed75f43 100644 --- a/CumulusMX/CumulusMX.csproj +++ b/CumulusMX/CumulusMX.csproj @@ -116,8 +116,8 @@ ..\packages\MimeKit.3.3.0\lib\net48\MimeKit.dll - - ..\packages\MQTTnet.4.0.0.167\lib\net461\MQTTnet.dll + + ..\packages\MQTTnet.4.0.1.184\lib\net461\MQTTnet.dll ..\packages\MySqlConnector.2.1.10\lib\net471\MySqlConnector.dll diff --git a/CumulusMX/packages.config b/CumulusMX/packages.config index b5898cc3..0ca04739 100644 --- a/CumulusMX/packages.config +++ b/CumulusMX/packages.config @@ -10,7 +10,7 @@ - + diff --git a/Updates.txt b/Updates.txt index 54266966..ba0426f5 100644 --- a/Updates.txt +++ b/Updates.txt @@ -3,6 +3,7 @@ - Fix: Ecowitt Extra Sensors setup error 500 - Change: Migrate the log file viewers to the new date picker +- Change: Default web site menu system - add accessible sub-menus (setpagedata.js) 3.18.0 - b3190 From 0949ca6944de1b71f893d54cc00d4b5fe81099e2 Mon Sep 17 00:00:00 2001 From: Mark Crossley <1196094+mcrossley@users.noreply.github.com> Date: Fri, 24 Jun 2022 21:14:38 +0100 Subject: [PATCH 12/21] NOAA reports fixes General API fixes WebSocket fixes Remove Twitter --- CumulusMX/Api.cs | 135 ++++++++++++++++--------------- CumulusMX/Cumulus.cs | 137 +------------------------------- CumulusMX/CumulusMX.csproj | 24 +----- CumulusMX/MXWebSocket.cs | 18 ++++- CumulusMX/NOAAReports.cs | 4 +- CumulusMX/ThirdPartySettings.cs | 40 ---------- CumulusMX/WeatherStation.cs | 19 ++--- CumulusMX/packages.config | 5 -- Updates.txt | 18 ++++- 9 files changed, 113 insertions(+), 287 deletions(-) diff --git a/CumulusMX/Api.cs b/CumulusMX/Api.cs index 671a9fce..b4eb936b 100644 --- a/CumulusMX/Api.cs +++ b/CumulusMX/Api.cs @@ -115,14 +115,14 @@ public async Task GetEditData(string req) await writer.WriteAsync(dataEditor.GetRecordsLogFile("thisyear")); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/edit: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -178,14 +178,14 @@ public async Task PostEditData(string req) await writer.WriteAsync(dataEditor.EditDatalog(HttpContext)); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/edit: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -247,13 +247,13 @@ public async Task GetData(string req) await writer.WriteAsync(Station.GetDiarySummary()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/data: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -286,15 +286,15 @@ public async Task PostTags(string req) await writer.WriteAsync(tagProcessor.ProcessText(HttpContext.Request)); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/tags: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -322,14 +322,14 @@ public async Task GetTags(string req) await writer.WriteAsync(tagProcessor.ProcessJson(Request)); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/tags: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -403,13 +403,13 @@ public async Task GetGraphData(string req) await writer.WriteAsync(Station.GetSelectaChartOptions()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/graphdata: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -437,15 +437,15 @@ public async Task SetGraphData(string req) await writer.WriteAsync(stationSettings.SetSelectaChartOptions(HttpContext)); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/graphdata: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -503,14 +503,14 @@ public async Task GetDailyGraphData(string req) await writer.WriteAsync(Station.GetGraphConfig()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/dailygraphdata: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -553,14 +553,14 @@ public async Task GetAlltimeData(string req) await writer.WriteAsync(EscapeUnicode(Station.GetRainRecords())); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/records/alltime: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -608,14 +608,14 @@ public async Task GetMonthlyRecordData(string mon, string req) await writer.WriteAsync(EscapeUnicode(Station.GetMonthlyRainRecords(month))); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/records/month: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -655,14 +655,14 @@ public async Task GetThisMonthRecordData(string req) await writer.WriteAsync(EscapeUnicode(Station.GetThisMonthRainRecords())); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/records/thismonth: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -701,14 +701,14 @@ public async Task GetThisYearRecordData(string req) await writer.WriteAsync(EscapeUnicode(Station.GetThisYearRainRecords())); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/records/thisyear: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -755,14 +755,14 @@ public async Task GetYesterdayData(string req) await writer.WriteAsync(Station.GetTodayYestSolar()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/todayyest: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -847,14 +847,14 @@ public async Task GetExtraData(string req) await writer.WriteAsync(Station.GetCO2sensor()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/extra: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -940,14 +940,14 @@ public async Task SettingsGet(string req) await writer.WriteAsync(wizard.GetAlpacaFormData()); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/settings: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -1012,14 +1012,14 @@ public async Task SettingsSet(string req) await writer.WriteAsync(wizard.UpdateConfig(HttpContext)); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/setsettings: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -1040,7 +1040,7 @@ public async Task GetData(string req) var query = HttpUtility.ParseQueryString(Request.Url.Query); int month, year; - Response.ContentType = "application/json"; + Response.ContentType = "text/plain"; using (var writer = HttpContext.OpenResponseText()) { @@ -1055,7 +1055,7 @@ public async Task GetData(string req) switch (req) { case "noaayear": - await writer.WriteAsync(Json.Serialize(noaarpts.GetNoaaYearReport(year))); + await writer.WriteAsync(String.Join("\n", noaarpts.GetNoaaYearReport(year).ToArray())); break; case "noaamonth": if (!Int32.TryParse(query["month"], out month) || month < 1 || month > 12) @@ -1064,17 +1064,17 @@ public async Task GetData(string req) Response.StatusCode = 406; return; } - await writer.WriteAsync(Json.Serialize(noaarpts.GetNoaaMonthReport(year, month))); + await writer.WriteAsync(String.Join("\n", noaarpts.GetNoaaMonthReport(year, month).ToArray())); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/reports: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -1087,7 +1087,7 @@ public async Task GenReports(string req) { var query = HttpUtility.ParseQueryString(Request.Url.Query); int month, year; - Response.ContentType = "application/json"; + Response.ContentType = "text/plain"; using (var writer = HttpContext.OpenResponseText()) { @@ -1101,7 +1101,7 @@ public async Task GenReports(string req) switch (req) { case "noaayear": - await writer.WriteAsync(Json.Serialize(noaarpts.GenerateNoaaYearReport(year))); + await writer.WriteAsync(String.Join("\n", noaarpts.GenerateNoaaYearReport(year).ToArray())); break; case "noaamonth": if (!Int32.TryParse(query["month"], out month) || month < 1 || month > 12) @@ -1110,18 +1110,21 @@ public async Task GenReports(string req) Response.StatusCode = 406; return; } - await writer.WriteAsync(Json.Serialize(noaarpts.GenerateNoaaMonthReport(year, month))); + await writer.WriteAsync(String.Join("\n", noaarpts.GenerateNoaaMonthReport(year, month).ToArray())); break; default: - throw new KeyNotFoundException("Key Not Found: " + req); + Response.StatusCode = 404; + throw new Exception(); + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + //using (var writer = HttpContext.OpenResponseText()) + // await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); Response.StatusCode = 500; + Program.cumulus.LogMessage($"api/genreports: Unexpected Error, ErrorCode: {ex.GetType().Name}, Description: \"{ex.Message}\""); } } } @@ -1162,13 +1165,15 @@ public async Task PostTags(string req) await writer.WriteAsync("{\"Error\":\"HTTP Station (Ecowitt) is not running}\""); } break; + default: + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/httpstation: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } @@ -1220,13 +1225,15 @@ public async Task GetStation(string req) await writer.WriteAsync("HTTP Station (Ambient) is not running"); } break; + default: + Response.StatusCode = 404; + break; } } } catch (Exception ex) { - using (var writer = HttpContext.OpenResponseText()) - await writer.WriteAsync($"{{\"Title\":\"Unexpected Error\",\"ErrorCode\":\"{ex.GetType().Name}\",\"Description\":\"{ex.Message}\"}}"); + Program.cumulus.LogMessage($"api/httpstation: Unexpected Error, Description: \"{ex.Message}\""); Response.StatusCode = 500; } } diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index fcabdf86..1f81953a 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -18,7 +18,6 @@ using MySqlConnector; using FluentFTP; using FluentFTP.Helpers; -using LinqToTwitter; using ServiceStack.Text; using EmbedIO; using EmbedIO.WebApi; @@ -466,9 +465,6 @@ public struct TExtraFiles //private const int VP2USBCONNECTION = 1; //private const int VP2TCPIPCONNECTION = 2; - private readonly string twitterKey = "lQiGNdtlYUJ4wS3d7souPw"; - private readonly string twitterSecret = "AoB7OqimfoaSfGQAd47Hgatqdv3YeTTiqpinkje6Xg"; - public string AlltimeIniFile; public string Alltimelogfile; public string MonthlyAlltimeIniFile; @@ -545,9 +541,6 @@ public struct TExtraFiles public bool RealtimeIntervalEnabled; // The timer is to be started private int realtimeFTPRetries; // Count of failed realtime FTP attempts - // Twitter settings - public WebUploadTwitter Twitter = new WebUploadTwitter(); - // Wunderground settings public WebUploadWund Wund = new WebUploadWund(); @@ -770,7 +763,6 @@ public Cumulus(int HTTPport, bool DebugEnabled, string startParms) DirectorySeparator = Path.DirectorySeparatorChar; AppDir = Directory.GetCurrentDirectory() + DirectorySeparator; - TwitterTxtFile = AppDir + "twitter.txt"; WebTagFile = AppDir + "WebTags.txt"; //b3045>, use same port for WS... WS port = HTTPS port @@ -1709,6 +1701,9 @@ public Cumulus(int HTTPport, bool DebugEnabled, string startParms) station.StartLoop(); } + // let the web socket know about the station + WebSock.SetStation = station; + // If enabled generate the daily graph data files, and upload at first opportunity LogDebugMessage("Generating the daily graph data files"); station.CreateEodGraphDataFiles(); @@ -2160,103 +2155,6 @@ private void WebTimerTick(object sender, ElapsedEventArgs e) } } - internal async void UpdateTwitter() - { - if (station.DataStopped) - { - // No data coming in, do nothing - return; - } - - LogDebugMessage("Starting Twitter update"); - var auth = new XAuthAuthorizer - { - CredentialStore = new XAuthCredentials { ConsumerKey = twitterKey, ConsumerSecret = twitterSecret, UserName = Twitter.ID, Password = Twitter.PW } - }; - - if (Twitter.OauthToken == "unknown") - { - // need to get tokens using xauth - LogDebugMessage("Obtaining Twitter tokens"); - await auth.AuthorizeAsync(); - - Twitter.OauthToken = auth.CredentialStore.OAuthToken; - Twitter.OauthTokenSecret = auth.CredentialStore.OAuthTokenSecret; - //LogDebugMessage("Token=" + TwitterOauthToken); - //LogDebugMessage("TokenSecret=" + TwitterOauthTokenSecret); - LogDebugMessage("Tokens obtained"); - } - else - { - auth.CredentialStore.OAuthToken = Twitter.OauthToken; - auth.CredentialStore.OAuthTokenSecret = Twitter.OauthTokenSecret; - } - - using (var twitterCtx = new TwitterContext(auth)) - { - StringBuilder status = new StringBuilder(1024); - - if (File.Exists(TwitterTxtFile)) - { - // use twitter.txt file - LogDebugMessage("Using twitter.txt file"); - var twitterTokenParser = new TokenParser(); - var utf8WithoutBom = new UTF8Encoding(false); - var encoding = utf8WithoutBom; - twitterTokenParser.Encoding = encoding; - twitterTokenParser.SourceFile = TwitterTxtFile; - twitterTokenParser.OnToken += TokenParserOnToken; - status.Append(twitterTokenParser); - } - else - { - // default message - status.Append($"Wind {station.WindAverage.ToString(WindAvgFormat)} {Units.WindText} {station.AvgBearingText}."); - status.Append($" Barometer {station.Pressure.ToString(PressFormat)} {Units.PressText}, {station.Presstrendstr}."); - status.Append($" Temperature {station.OutdoorTemperature.ToString(TempFormat)} {Units.TempText}."); - status.Append($" Rain today {station.RainToday.ToString(RainFormat)}{Units.RainText}."); - status.Append($" Humidity {station.OutdoorHumidity}%"); - } - - LogDebugMessage($"Updating Twitter: {status}"); - - var statusStr = status.ToString(); - - try - { - Status tweet; - - if (Twitter.SendLocation) - { - tweet = await twitterCtx.TweetAsync(statusStr, (decimal)Latitude, (decimal)Longitude); - } - else - { - tweet = await twitterCtx.TweetAsync(statusStr); - } - - if (tweet == null) - { - LogDebugMessage("Null Twitter response"); - } - else - { - LogDebugMessage($"Status returned: ({tweet.StatusID}) {tweet.User.Name}, {tweet.Text}, {tweet.CreatedAt}"); - } - - HttpUploadAlarm.Triggered = false; - } - catch (Exception ex) - { - LogMessage($"UpdateTwitter: {ex.Message}"); - HttpUploadAlarm.LastError = "Twitter: " + ex.Message; - HttpUploadAlarm.Triggered = true; - } - //if (tweet != null) - // Console.WriteLine("Status returned: " + "(" + tweet.StatusID + ")" + tweet.User.Name + ", " + tweet.Text + "\n"); - } - } - private void WundTimerTick(object sender, ElapsedEventArgs e) { if (!string.IsNullOrWhiteSpace(Wund.ID)) @@ -4655,19 +4553,6 @@ private void ReadIniFile() WCloud.SendLeafWetness = ini.GetValue("WeatherCloud", "SendLeafWetness", false); WCloud.LeafWetnessSensor = ini.GetValue("WeatherCloud", "LeafWetnessSensor", 1); - Twitter.ID = ini.GetValue("Twitter", "User", ""); - Twitter.PW = ini.GetValue("Twitter", "Password", ""); - Twitter.Enabled = ini.GetValue("Twitter", "Enabled", false); - Twitter.Interval = ini.GetValue("Twitter", "Interval", 60); - if (Twitter.Interval < 1) - { - Twitter.Interval = 1; - rewriteRequired = true; - } - Twitter.OauthToken = ini.GetValue("Twitter", "OauthToken", "unknown"); - Twitter.OauthTokenSecret = ini.GetValue("Twitter", "OauthTokenSecret", "unknown"); - Twitter.SendLocation = ini.GetValue("Twitter", "SendLocation", true); - //if HTTPLogging then // MainForm.WUHTTP.IcsLogger = MainForm.HTTPlogger; @@ -5672,14 +5557,6 @@ internal void WriteIniFile() ini.SetValue("WeatherCloud", "SendLeafWetness", WCloud.SendLeafWetness); ini.SetValue("WeatherCloud", "LeafWetnessSensor", WCloud.LeafWetnessSensor); - ini.SetValue("Twitter", "User", Twitter.ID); - ini.SetValue("Twitter", "Password", Twitter.PW); - ini.SetValue("Twitter", "Enabled", Twitter.Enabled); - ini.SetValue("Twitter", "Interval", Twitter.Interval); - ini.SetValue("Twitter", "OauthToken", Twitter.OauthToken); - ini.SetValue("Twitter", "OauthTokenSecret", Twitter.OauthTokenSecret); - ini.SetValue("Twitter", "TwitterSendLocation", Twitter.SendLocation); - ini.SetValue("PWSweather", "ID", PWS.ID); ini.SetValue("PWSweather", "Password", PWS.PW); ini.SetValue("PWSweather", "Enabled", PWS.Enabled); @@ -6700,7 +6577,6 @@ private void ReadStringsFile() public DateTime defaultRecordTS = DateTime.MinValue; public string WxnowFile = "wxnow.txt"; private readonly string RealtimeFile = "realtime.txt"; - private readonly string TwitterTxtFile; private readonly FtpClient RealtimeFTP = new FtpClient(); private SftpClient RealtimeSSH; private volatile bool RealtimeFtpInProgress; @@ -11040,13 +10916,6 @@ public class WebUploadService public bool Updating; } - public class WebUploadTwitter : WebUploadService - { - public string OauthToken; - public string OauthTokenSecret; - public bool SendLocation; - } - public class WebUploadWund : WebUploadService { public bool RapidFireEnabled; diff --git a/CumulusMX/CumulusMX.csproj b/CumulusMX/CumulusMX.csproj index 2ed75f43..666dd0a7 100644 --- a/CumulusMX/CumulusMX.csproj +++ b/CumulusMX/CumulusMX.csproj @@ -11,7 +11,8 @@ CumulusMX v4.8 512 - 8de6c3ed + + false C:\Users\mcrossley\Code\CumulusMX-Dist\ @@ -102,14 +103,6 @@ ..\packages\HidSharp.2.1.0\lib\net35\HidSharp.dll - - False - ..\packages\linqtotwitter.3.1.1\lib\net45\LinqToTwitter.AspNet.dll - - - False - ..\packages\linqtotwitter.3.1.1\lib\net45\LinqToTwitterPcl.dll - ..\packages\MailKit.3.3.0\lib\net48\MailKit.dll @@ -147,12 +140,6 @@ ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll - - - ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll - False @@ -296,13 +283,6 @@ - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - -