diff --git a/CumulusMX/EcowittApi.cs b/CumulusMX/EcowittApi.cs index 5bd0801b..54934ed8 100644 --- a/CumulusMX/EcowittApi.cs +++ b/CumulusMX/EcowittApi.cs @@ -7,6 +7,7 @@ using System.Reactive; using System.Runtime.Serialization; using System.Text; +using System.Threading; using System.Threading.Tasks; using ServiceStack; using ServiceStack.Text; @@ -65,7 +66,7 @@ public EcowittApi(Cumulus cuml, WeatherStation stn) } - internal bool GetHistoricData(DateTime startTime, DateTime endTime) + internal bool GetHistoricData(DateTime startTime, DateTime endTime, CancellationToken token) { var data = new EcowittHistoricData(); @@ -267,7 +268,7 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime) } cumulus.LogMessage("API.GetHistoricData: System Busy or Rate Limited, waiting 5 secs before retry..."); - System.Threading.Thread.Sleep(5000); + Task.Delay(5000, token).Wait(); } else { @@ -292,7 +293,10 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime) // } while (!success); - ProcessHistoryData(data); + if (!token.IsCancellationRequested) + { + ProcessHistoryData(data, token); + } return true; } @@ -305,7 +309,7 @@ internal bool GetHistoricData(DateTime startTime, DateTime endTime) } - private void ProcessHistoryData(EcowittHistoricData data) + private void ProcessHistoryData(EcowittHistoricData data, CancellationToken token) { // allocate a dictionary of data objects, keyed on the timestamp var buffer = new SortedDictionary(); @@ -1163,6 +1167,11 @@ private void ProcessHistoryData(EcowittHistoricData data) foreach (var rec in buffer) { + if (token.IsCancellationRequested) + { + return; + } + cumulus.LogMessage("Processing data for " + rec.Key); var h = rec.Key.Hour; diff --git a/CumulusMX/GW1000Station.cs b/CumulusMX/GW1000Station.cs index 0b03b4d2..7b60d329 100644 --- a/CumulusMX/GW1000Station.cs +++ b/CumulusMX/GW1000Station.cs @@ -292,7 +292,7 @@ private void GetHistoricData() maxArchiveRuns++; } - EcowittApi.GetHistoricData(startTime, endTime); + EcowittApi.GetHistoricData(startTime, endTime, cancellationToken); } private Discovery DiscoverGW1000() diff --git a/CumulusMX/HttpStationEcowitt.cs b/CumulusMX/HttpStationEcowitt.cs index 675b8a7d..473bfe37 100644 --- a/CumulusMX/HttpStationEcowitt.cs +++ b/CumulusMX/HttpStationEcowitt.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace CumulusMX @@ -20,6 +21,8 @@ class HttpStationEcowitt : WeatherStation private readonly WeatherStation station; private bool starting = true; private bool stopping = false; + private readonly CancellationTokenSource tokenSource = new CancellationTokenSource(); + private CancellationToken cancellationToken; private readonly NumberFormatInfo invNum = CultureInfo.InvariantCulture.NumberFormat; private bool reportStationType = true; private int lastMinute = -1; @@ -117,7 +120,7 @@ public HttpStationEcowitt(Cumulus cumulus, WeatherStation station = null) : base cumulus.Units.LeafWetnessUnitText = "%"; } - + cancellationToken = tokenSource.Token; // Only perform the Start-up if we are a proper station, not a Extra Sensor if (mainStation) @@ -150,6 +153,10 @@ public override void Stop() stopping = true; Api.stationEcowitt = null; Api.stationEcowittExtra = null; + if (tokenSource != null) + { + tokenSource.Cancel(); + } if (station == null) { StopMinuteTimer(); @@ -211,7 +218,7 @@ private void GetHistoricData() maxArchiveRuns++; } - ecowittApi.GetHistoricData(startTime, endTime); + ecowittApi.GetHistoricData(startTime, endTime, cancellationToken); } diff --git a/Updates.txt b/Updates.txt index e3748405..d44b202b 100644 --- a/Updates.txt +++ b/Updates.txt @@ -9,7 +9,7 @@ New <#MySqlRealtimeTime> = time of last real-time table insert <#MySqlIntervalTime> = time of last interval data table insert - Most weather value web tags now perform unit conversion. Specify the web tag parameter: unit=[xx] - Where [xx] is one of the following (case sensitive): + Where [xx] is one of the following (case insensitive): Temperature: C | F Pressure : hPa | mb | kPa | inHg Wind : mph | kph | ms | kt @@ -34,9 +34,13 @@ Fixed - Davis VP2 logger downloading entire contents if CMX was restarted before the next console log interval - Stop second instance on Linux, this now uses a lock file to prevent a second instance from running - Fix Custom HTTP intervals from trying to process null entries -- Fix for Davis WLL missed broadcast package counter not being incremented -- Fix for Davis WLL processing broadcast messages twice or more on systems with both IPv4 and IPv6 enabled -- Fix for missing average temperature calculation during Ecowitt catch-up +- Davis WLL + - Missed broadcast package counter not being incremented + - No longer processes broadcast messages twice or more on systems with multiple network interfaces + - Improved collision avoidance between broadcasts and API requests +- Ecowitt + - Fix for missing average temperature calculation during Ecowitt historic catch-up + - Historic catch-up is now cancellable with Ctrl-C 3.22.4 - b3215