Skip to content

Commit

Permalink
Merge pull request #167 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.23.1 updates
  • Loading branch information
mcrossley authored Jan 10, 2023
2 parents a5c33ca + 61a689c commit 2b6955d
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ FakesAssemblies/
ToDo.txt
/CumulusMX/DataEditor-byDay.cs
/CumulusMX/WeatherStation-byDay.cs
/Updates.md
3 changes: 3 additions & 0 deletions CumulusMX/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ public async Task GetGraphData(string req)
case "extrahum.json":
await writer.WriteAsync(Station.GetExtraHumGraphData(DateTime.Now));
break;
case "extradew.json":
await writer.WriteAsync(Station.GetExtraDewpointGraphData(DateTime.Now));
break;
case "soiltemp.json":
await writer.WriteAsync(Station.GetSoilTempGraphData(DateTime.Now));
break;
Expand Down
10 changes: 8 additions & 2 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,7 @@ internal async void UpdateAwekas(DateTime timestamp)
LogMessage($"AWEKAS: ERROR - Response code = {response.StatusCode}, body = {responseBodyAsText}");
HttpUploadAlarm.LastError = $"AWEKAS: HTTP Response code = {response.StatusCode}, body = {responseBodyAsText}";
HttpUploadAlarm.Triggered = true;
return;
}
else
{
Expand Down Expand Up @@ -4346,6 +4347,7 @@ private void ReadIniFile()
WllApiSecret = ini.GetValue("WLL", "WLv2ApiSecret", "");
WllStationId = ini.GetValue("WLL", "WLStationId", -1);
//if (WllStationId == "-1") WllStationId = "";
WllTriggerDataStoppedOnBroadcast = ini.GetValue("WLL", "DataStoppedOnBroadcast", true);
WLLAutoUpdateIpAddress = ini.GetValue("WLL", "AutoUpdateIpAddress", true);
WllBroadcastDuration = ini.GetValue("WLL", "BroadcastDuration", WllBroadcastDuration);
WllBroadcastPort = ini.GetValue("WLL", "BroadcastPort", WllBroadcastPort);
Expand Down Expand Up @@ -4660,6 +4662,7 @@ private void ReadIniFile()
GraphOptions.TempSumVisible2 = ini.GetValue("Graphs", "TempSumVisible2", true);
GraphOptions.ExtraTempVisible = ini.GetValue("Graphs", "ExtraTempVisible", new bool[10]);
GraphOptions.ExtraHumVisible = ini.GetValue("Graphs", "ExtraHumVisible", new bool[10]);
GraphOptions.ExtraDewPointVisible = ini.GetValue("Graphs", "ExtraDewPointVisible", new bool[10]);
GraphOptions.SoilTempVisible = ini.GetValue("Graphs", "SoilTempVisible", new bool[16]);
GraphOptions.SoilMoistVisible = ini.GetValue("Graphs", "SoilMoistVisible", new bool[16]);
GraphOptions.UserTempVisible = ini.GetValue("Graphs", "UserTempVisible", new bool[8]);
Expand Down Expand Up @@ -5664,6 +5667,7 @@ internal void WriteIniFile()
ini.SetValue("WLL", "WLv2ApiKey", WllApiKey);
ini.SetValue("WLL", "WLv2ApiSecret", WllApiSecret);
ini.SetValue("WLL", "WLStationId", WllStationId);
ini.SetValue("WLL", "DataStoppedOnBroadcast", WllTriggerDataStoppedOnBroadcast);
ini.SetValue("WLL", "PrimaryRainTxId", WllPrimaryRain);
ini.SetValue("WLL", "PrimaryTempHumTxId", WllPrimaryTempHum);
ini.SetValue("WLL", "PrimaryWindTxId", WllPrimaryWind);
Expand Down Expand Up @@ -6320,6 +6324,7 @@ internal void WriteIniFile()
ini.SetValue("Graphs", "TempSumVisible2", GraphOptions.TempSumVisible2);
ini.SetValue("Graphs", "ExtraTempVisible", GraphOptions.ExtraTempVisible);
ini.SetValue("Graphs", "ExtraHumVisible", GraphOptions.ExtraHumVisible);
ini.SetValue("Graphs", "ExtraDewPointVisible", GraphOptions.ExtraDewPointVisible);
ini.SetValue("Graphs", "SoilTempVisible", GraphOptions.SoilTempVisible);
ini.SetValue("Graphs", "SoilMoistVisible", GraphOptions.SoilMoistVisible);
ini.SetValue("Graphs", "UserTempVisible", GraphOptions.UserTempVisible);
Expand Down Expand Up @@ -6886,7 +6891,7 @@ private void ReadStringsFile()
public string WllApiSecret;
public int WllStationId;
public int WllParentId;

public bool WllTriggerDataStoppedOnBroadcast; // trigger a data stopped state if broadcasts stop being received but current data is OK
/// <value>Read-only setting, default 20 minutes (1200 sec)</value>
public int WllBroadcastDuration = 1200;
/// <value>Read-only setting, default 22222</value>
Expand Down Expand Up @@ -7847,7 +7852,7 @@ public void BackupData(bool daily, DateTime timestamp)
if (CustomIntvlLogSettings[i].Enabled)
{
var filename = GetCustomIntvlLogFileName(i, timestamp.AddDays(-1));
CopyBackupFile(filename, filename.Replace(logFilePath, ""), true);
CopyBackupFile(filename, foldername + filename.Replace(logFilePath, ""), true);
}
}
}
Expand Down Expand Up @@ -11432,6 +11437,7 @@ public class GraphOptions
public bool TempSumVisible2 { get; set; }
public bool[] ExtraTempVisible = new bool[10];
public bool[] ExtraHumVisible = new bool[10];
public bool[] ExtraDewPointVisible = new bool[10];
public bool[] SoilTempVisible = new bool[16];
public bool[] SoilMoistVisible = new bool[16];
public bool[] UserTempVisible = new bool[8];
Expand Down
13 changes: 12 additions & 1 deletion CumulusMX/DataEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3568,7 +3568,7 @@ internal string EditDatalog(IHttpContext context)
var InvC = new CultureInfo("");
var lastMonth = -1;
var lines = new List<string>();
var logfile = "";
var logfile = string.Empty;

using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
{
Expand All @@ -3579,6 +3579,17 @@ internal string EditDatalog(IHttpContext context)

if (newData.action == "Edit")
{
// Get the log file date
var ts = Utils.ddmmyyStrToDate(newData.data[0][0]);
var fileDate = new DateTime(ts.Year, ts.Month, 15);

logfile = (newData.extra ? cumulus.GetExtraLogFileName(ts) : cumulus.GetLogFileName(ts));

// read the log file into a List
lines.Clear();
lines = File.ReadAllLines(logfile).ToList();


var lineNum = newData.lines[0] - 1; // our List is zero relative

// replace the edited line
Expand Down
8 changes: 6 additions & 2 deletions CumulusMX/DataStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public string HighFeelsLikeTodayRounded
[DataMember(Name = "TempTrend")]
public string TempTrendRounded
{
get => TempTrend.ToString(cumulus.TempFormat);
get => TempTrend.ToString("+0.0;-0.0;0.0");
set { }
}

Expand All @@ -727,7 +727,11 @@ public string TempTrendRounded
[DataMember(Name = "PressTrend")]
public string PressTrendRounded
{
get => PressTrend.ToString(cumulus.PressFormat);
get {
var dps = new string('0', cumulus.PressDPlaces);
var format = $"+0.{dps};-0.{dps};0.{dps}";
return PressTrend.ToString(format);
}
set { }
}

Expand Down
117 changes: 86 additions & 31 deletions CumulusMX/DavisWllStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal class DavisWllStation : WeatherStation
private readonly HttpClient dogsBodyClient = new HttpClient();
private readonly bool checkWllGustValues;
private bool broadcastReceived;
private bool broadcastStopped;
private int weatherLinkArchiveInterval = 16 * 60; // Used to get historic Health, 16 minutes in seconds only for initial fetch after load
private bool wllVoltageLow;
private readonly CancellationTokenSource tokenSource = new CancellationTokenSource();
Expand All @@ -46,6 +47,7 @@ internal class DavisWllStation : WeatherStation
private readonly AutoResetEvent bwDoneEvent = new AutoResetEvent(false);
private readonly List<WlSensor> sensorList = new List<WlSensor>();
private readonly bool useWeatherLinkDotCom = true;
private double currentAvgWindSpd = 0;

public DavisWllStation(Cumulus cumulus) : base(cumulus)
{
Expand Down Expand Up @@ -122,9 +124,9 @@ public DavisWllStation(Cumulus cumulus) : base(cumulus)
}
else
{
// User period is less than 10 minutes, so we cannot use the station 10 min gust values
// User period is less than 10 minutes
CalcRecentMaxGust = true;
checkWllGustValues = false;
checkWllGustValues = true;
}


Expand Down Expand Up @@ -537,6 +539,16 @@ private async void GetWllCurrent(object source, ElapsedEventArgs e)
cumulus.LogMessage($"GetWllCurrent: Error: {ex.Message}");
else
cumulus.LogMessage($"GetWllCurrent: Error: {ex.InnerException.Message}");

if (!DataStopped)
{
cumulus.LogMessage($"ERROR: No current data received from the WLL, DataStopped triggered");

DataStopped = true;
DataStoppedTime = DateTime.Now;
cumulus.DataStoppedAlarm.LastError = "No current data is being received from the WLL";
cumulus.DataStoppedAlarm.Triggered = true;
}
}
retry++;

Expand All @@ -545,7 +557,7 @@ private async void GetWllCurrent(object source, ElapsedEventArgs e)
Thread.Sleep(1000);
tmrCurrent.Start();
}
} while (retry < 3);
} while (retry <= 3);

//cumulus.LogDebugMessage("GetWllCurrent: Releasing lock");
WebReq.Release();
Expand Down Expand Up @@ -585,8 +597,8 @@ private void DecodeBroadcast(string broadcastJson, IPEndPoint from)
// WLL BUG/FEATURE: The WLL sends a null wind direction for calm when the avg speed falls to zero, we use zero
int windDir = rec.wind_dir_last ?? 0;

// No average in the broadcast data, so use last value from current - allow for calibration
DoWind(ConvertWindMPHToUser(rec.wind_speed_last), windDir, WindAverage / cumulus.Calib.WindSpeed.Mult, dateTime);
// No average in the broadcast data, so use last value from current
DoWind(ConvertWindMPHToUser(rec.wind_speed_last), windDir, currentAvgWindSpd, dateTime);

var gust = ConvertWindMPHToUser(rec.wind_speed_hi_last_10_min);
var gustCal = gust * cumulus.Calib.WindGust.Mult;
Expand Down Expand Up @@ -670,6 +682,7 @@ private void DecodeBroadcast(string broadcastJson, IPEndPoint from)
UpdateMQTT();

broadcastReceived = true;
broadcastStopped = false;
DataStopped = false;
cumulus.DataStoppedAlarm.Triggered = false;
multicastsGood++;
Expand Down Expand Up @@ -841,22 +854,46 @@ private void DecodeCurrent(string currentJson)
*/
try
{
cumulus.LogDebugMessage($"WLL current: using wind data from TxId {data1.txid}");
cumulus.LogDebugMessage($"WLL current: using average wind speed data from TxId {data1.txid}");

// pesky null values from WLL when it is calm
int wdir = data1.wind_dir_last.HasValue ? data1.wind_dir_last.Value : 0;
double wind = ConvertWindMPHToUser(data1.wind_speed_last ?? 0);
double wspdAvg10min = ConvertWindMPHToUser(data1.wind_speed_avg_last_10_min ?? 0);
if (cumulus.StationOptions.AvgSpeedMinutes == 1)
currentAvgWindSpd = ConvertWindMPHToUser(data1.wind_speed_avg_last_1_min ?? 0);
else if (cumulus.StationOptions.AvgSpeedMinutes < 10)
currentAvgWindSpd = ConvertWindMPHToUser(data1.wind_speed_avg_last_2_min ?? 0);
else
currentAvgWindSpd = ConvertWindMPHToUser(data1.wind_speed_avg_last_10_min ?? 0);

// Only use wind data from current if we are not receiving broadcasts
if (broadcastStopped)
{
cumulus.LogDebugMessage($"WLL current: no broadcast data so using full wind data from TxId {data1.txid}");

DoWind(wind, wdir, wspdAvg10min, dateTime);
// pesky null values from WLL when it is calm
int wdir = data1.wind_dir_last ?? 0;
double wind = ConvertWindMPHToUser(data1.wind_speed_last ?? 0);

//WindAverage = wspdAvg10min * cumulus.Calib.WindSpeed.Mult;
DoWind(wind, wdir, currentAvgWindSpd, dateTime);
}

double gust;
int gustDir;
if (cumulus.StationOptions.PeakGustMinutes < 10)
{
gust = ConvertWindMPHToUser(data1.wind_speed_hi_last_2_min ?? 0);
gustDir = data1.wind_dir_at_hi_speed_last_2_min ?? 0;
}
else
{
gust = ConvertWindMPHToUser(data1.wind_speed_hi_last_10_min ?? 0);
gustDir = data1.wind_dir_at_hi_speed_last_10_min ?? 0;

}

// Wind data can be a bit out of date compared to the broadcasts (1 minute update), so only use gust broadcast data
/*
var gust = ConvertWindMPHToUser(data1.wind_speed_hi_last_10_min);
ConvertWindMPHToUser(gust);
var gustCal = gust * cumulus.Calib.WindGust.Mult;


if (checkWllGustValues)
{
// See if the current speed is higher than the current 10-min max
Expand All @@ -865,15 +902,15 @@ private void DecodeCurrent(string currentJson)
if (gustCal > RecentMaxGust)
{
// Check for spikes, and set highs
if (CheckHighGust(gustCal, data1.wind_dir_at_hi_speed_last_10_min, dateTime))
if (CheckHighGust(gustCal, gustDir, dateTime))
{
cumulus.LogDebugMessage("Setting max gust from current 10 min value: " + gustCal.ToString(cumulus.WindFormat) + " was: " + RecentMaxGust.ToString(cumulus.WindFormat));
cumulus.LogDebugMessage("Setting max gust from current value: " + gustCal.ToString(cumulus.WindFormat) + " was: " + RecentMaxGust.ToString(cumulus.WindFormat));

// add to recent values so normal calculation includes this value
WindRecent[nextwind].Gust = gust; // use uncalibrated value
WindRecent[nextwind].Speed = WindAverage / cumulus.Calib.WindSpeed.Mult;
WindRecent[nextwind].Speed = currentAvgWindSpd;
WindRecent[nextwind].Timestamp = dateTime;
nextwind = (nextwind + 1) % cumulus.MaxWindRecent;
nextwind = (nextwind + 1) % MaxWindRecent;

RecentMaxGust = gustCal;
}
Expand All @@ -882,12 +919,11 @@ private void DecodeCurrent(string currentJson)
else if (!CalcRecentMaxGust)
{
// Check for spikes, and set highs
if (CheckHighGust(gustCal, data1.wind_dir_at_hi_speed_last_10_min, dateTime))
if (CheckHighGust(gustCal, gustDir, dateTime))
{
RecentMaxGust = gustCal;
}
}
*/
}
catch (Exception ex)
{
Expand Down Expand Up @@ -915,7 +951,7 @@ private void DecodeCurrent(string currentJson)
*/


cumulus.LogDebugMessage($"WLL current: using rain data from TxId {data1.txid}");
cumulus.LogDebugMessage($"WLL current: using storm rain data from TxId {data1.txid}");

if (data1.rain_size.HasValue)
{
Expand Down Expand Up @@ -956,18 +992,37 @@ private void DecodeCurrent(string currentJson)
}
}

// Rain data can be a bit out of date compared to the broadcasts (1 minute update), so only use storm data
// Rain data can be a bit out of date compared to the broadcasts (1 minute update), so only use storm data unless we are not receiving broadcasts

// All rainfall values supplied as *tip counts*
//double rain = ConvertRainINToUser((double)rec["rainfall_year"]);
//double rainrate = ConvertRainINToUser((double)rec["rain_rate_last"]);
if (!broadcastStopped)
{
cumulus.LogDebugMessage($"WLL current: Skipping rain data from TxId {data1.txid} as broadcasts are being received ok");
}
else
{
cumulus.LogDebugMessage($"WLL current: No broadcast data so using rain data from TxId {data1.txid}");

//if (rainrate < 0)
//{
// rainrate = 0;
//}
if (!data1.rainfall_year.HasValue || !data1.rain_rate_last.HasValue || !data1.rain_size.HasValue)
{
cumulus.LogDebugMessage("WLL current: No rain values present!");
}
else
{
// double check that the rainfall isn't out of date so we double count when it catches up
var rain = ConvertRainClicksToUser(data1.rainfall_year.Value, data1.rain_size.Value);
var rainrate = ConvertRainClicksToUser(data1.rain_rate_last.Value, data1.rain_size.Value);

//DoRain(rain, rainrate, dateTime);
if (rain > 0 && rain < Raincounter)
{
cumulus.LogDebugMessage("WLL current: The current yearly rainfall value is less than the value we had previously, ignoring it to avoid double counting");
}
else
{
DoRain(rain, rainrate, dateTime);
}
}
}

if (!data1.rain_storm.HasValue || !data1.rain_storm_start_at.HasValue || !data1.rain_size.HasValue)
{
Expand Down Expand Up @@ -3324,13 +3379,13 @@ private void BroadcastTimeout(object source, ElapsedEventArgs e)
else
{
cumulus.LogMessage($"ERROR: No broadcast data received from the WLL for {tmrBroadcastWatchdog.Interval / 1000} seconds");
if (!DataStopped)
if (cumulus.WllTriggerDataStoppedOnBroadcast && !DataStopped)
{
DataStoppedTime = DateTime.Now;
}
DataStopped = true;
cumulus.DataStoppedAlarm.LastError = $"No broadcast data received from the WLL for {tmrBroadcastWatchdog.Interval / 1000} seconds";
cumulus.DataStoppedAlarm.Triggered = true;
broadcastStopped = true;
// Try and give the broadcasts a kick in case the last command did not get through
GetWllRealtime(null, null);
}
Expand Down
8 changes: 4 additions & 4 deletions CumulusMX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cumulus MX")]
[assembly: AssemblyDescription("Version 3.23.0 - Build 3220")]
[assembly: AssemblyDescription("Version 3.23.1 - Build 3221")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cumulus MX")]
[assembly: AssemblyCopyright("Copyright © 2015-2022 Cumulus MX")]
[assembly: AssemblyCopyright("Copyright © 2015-2023 Cumulus MX")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -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.23.0.3220")]
[assembly: AssemblyFileVersion("3.23.0.3220")]
[assembly: AssemblyVersion("3.23.1.3221")]
[assembly: AssemblyFileVersion("3.23.1.3221")]
Loading

0 comments on commit 2b6955d

Please sign in to comment.