Skip to content

Commit

Permalink
Merge pull request #173 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.25.0 support
  • Loading branch information
mcrossley authored Apr 24, 2023
2 parents 2524ccd + 6554486 commit 86f3e7f
Show file tree
Hide file tree
Showing 36 changed files with 3,185 additions and 946 deletions.
9 changes: 6 additions & 3 deletions CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void doTriggered(bool value)
{
msg += "\r\nLast error: " + LastError;
}
Task.Run(async () =>
_ = Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
Expand All @@ -119,6 +119,7 @@ private void doTriggered(bool value)
{
// Prepare the process to run
var parser = new TokenParser();
parser.OnToken += cumulus.TokenParserOnToken;
parser.InputText = ActionParams;
var args = parser.ToStringFromString();
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {args}");
Expand Down Expand Up @@ -252,7 +253,7 @@ private void doUpTriggered(bool value)
{
// Construct the message - preamble, plus values
var msg = cumulus.Trans.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsgUp, Value, Units);
Task.Run(async () =>
_ = Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
Expand All @@ -276,6 +277,7 @@ private void doUpTriggered(bool value)
{
// Prepare the process to run
var parser = new TokenParser();
parser.OnToken += cumulus.TokenParserOnToken;
parser.InputText = ActionParams;
var args = parser.ToStringFromString();
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {args}");
Expand Down Expand Up @@ -326,7 +328,7 @@ private void doDownTriggered(bool value)
{
// Construct the message - preamble, plus values
var msg = cumulus.Trans.AlarmEmailPreamble + "\n" + string.Format(EmailMsgDn, Value, Units);
Task.Run(async () =>
_ = Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
Expand All @@ -350,6 +352,7 @@ private void doDownTriggered(bool value)
{
// Prepare the process to run
var parser = new TokenParser();
parser.OnToken += cumulus.TokenParserOnToken;
parser.InputText = ActionParams;
var args = parser.ToStringFromString();
cumulus.LogMessage($"Alarm ({Name}): Starting external program: '{Action}', with parameters: {args}");
Expand Down
58 changes: 39 additions & 19 deletions CumulusMX/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EmbedIO;
using EmbedIO.Routing;
using EmbedIO.WebApi;
using SQLite;
using Swan.Formatters;

namespace CumulusMX
Expand All @@ -24,6 +25,7 @@ public static class Api
public static NOAASettings noaaSettings;
public static MysqlSettings mySqlSettings;
public static CustomLogs customLogs;
internal static HttpFiles httpFiles;
public static Wizard wizard;
internal static LangSettings langSettings;
internal static DisplaySettings displaySettings;
Expand Down Expand Up @@ -378,32 +380,41 @@ public async Task GetGraphData(string req)
return;
}

var incremental = false;
DateTime? start = null;

if (this.Request.QueryString.AllKeys.Contains("start") && long.TryParse(this.Request.QueryString.Get("start"), out long ts))
{
start = Utils.FromUnixTime(ts);
incremental = true;
}

try
{
using (var writer = HttpContext.OpenResponseText(new UTF8Encoding(false)))
{
switch (req)
{
case "tempdata.json":
await writer.WriteAsync(Station.GetTempGraphData(false, true));
await writer.WriteAsync(Station.GetTempGraphData(incremental, true, start));
break;
case "winddata.json":
await writer.WriteAsync(Station.GetWindGraphData(false));
await writer.WriteAsync(Station.GetWindGraphData(incremental, start));
break;
case "raindata.json":
await writer.WriteAsync(Station.GetRainGraphData(false));
await writer.WriteAsync(Station.GetRainGraphData(incremental, start));
break;
case "pressdata.json":
await writer.WriteAsync(Station.GetPressGraphData(false));
await writer.WriteAsync(Station.GetPressGraphData(incremental, start));
break;
case "wdirdata.json":
await writer.WriteAsync(Station.GetWindDirGraphData(false));
await writer.WriteAsync(Station.GetWindDirGraphData(incremental, start));
break;
case "humdata.json":
await writer.WriteAsync(Station.GetHumGraphData(false, true));
await writer.WriteAsync(Station.GetHumGraphData(incremental, true, start));
break;
case "solardata.json":
await writer.WriteAsync(Station.GetSolarGraphData(false, true));
await writer.WriteAsync(Station.GetSolarGraphData(incremental, true, start));
break;
case "dailyrain.json":
await writer.WriteAsync(Station.GetDailyRainGraphData());
Expand All @@ -421,28 +432,31 @@ public async Task GetGraphData(string req)
await writer.WriteAsync(Station.GetGraphConfig(true));
break;
case "airqualitydata.json":
await writer.WriteAsync(Station.GetAqGraphData(false));
await writer.WriteAsync(Station.GetAqGraphData(incremental, start));
break;
case "extratemp.json":
await writer.WriteAsync(Station.GetExtraTempGraphData(false, true));
await writer.WriteAsync(Station.GetExtraTempGraphData(incremental, true, start));
break;
case "extrahum.json":
await writer.WriteAsync(Station.GetExtraHumGraphData(false, true));
await writer.WriteAsync(Station.GetExtraHumGraphData(incremental, true, start));
break;
case "extradew.json":
await writer.WriteAsync(Station.GetExtraDewPointGraphData(false, true));
await writer.WriteAsync(Station.GetExtraDewPointGraphData(incremental, true, start));
break;
case "soiltemp.json":
await writer.WriteAsync(Station.GetSoilTempGraphData(false, true));
await writer.WriteAsync(Station.GetSoilTempGraphData(incremental, true, start));
break;
case "soilmoist.json":
await writer.WriteAsync(Station.GetSoilMoistGraphData(false, true));
await writer.WriteAsync(Station.GetSoilMoistGraphData(incremental, true, start));
break;
case "leafwetness.json":
await writer.WriteAsync(Station.GetLeafWetnessGraphData(incremental, true, start));
break;
case "usertemp.json":
await writer.WriteAsync(Station.GetUserTempGraphData(false, true));
await writer.WriteAsync(Station.GetUserTempGraphData(incremental, true, start));
break;
case "co2sensor.json":
await writer.WriteAsync(Station.GetCo2SensorGraphData(false, true));
await writer.WriteAsync(Station.GetCo2SensorGraphData(incremental, true, start));
break;
case "availabledata.json":
await writer.WriteAsync(Station.GetAvailGraphData(true));
Expand Down Expand Up @@ -1102,6 +1116,9 @@ public async Task SettingsGet(string req)
case "displayoptions.json":
await writer.WriteAsync(displaySettings.GetAlpacaFormData());
break;
case "httpfiles.json":
await writer.WriteAsync(httpFiles.GetAlpacaFormData());
break;
default:
Response.StatusCode = 404;
break;
Expand Down Expand Up @@ -1192,6 +1209,9 @@ public async Task SettingsSet(string req)
case "updatelanguage.json":
await writer.WriteAsync(langSettings.UpdateConfig(HttpContext));
break;
case "updatehttpfiles.json":
await writer.WriteAsync(httpFiles.UpdateConfig(HttpContext));
break;
default:
Response.StatusCode = 404;
break;
Expand Down Expand Up @@ -1233,7 +1253,7 @@ public async Task GetData(string req)
switch (req)
{
case "noaayear":
await writer.WriteAsync(String.Join("\n", noaarpts.GetNoaaYearReport(year).ToArray()));
await writer.WriteAsync(noaarpts.GetNoaaYearReport(year));
break;
case "noaamonth":
if (!Int32.TryParse(query["month"], out month) || month < 1 || month > 12)
Expand All @@ -1242,7 +1262,7 @@ public async Task GetData(string req)
Response.StatusCode = 406;
return;
}
await writer.WriteAsync(String.Join("\n", noaarpts.GetNoaaMonthReport(year, month).ToArray()));
await writer.WriteAsync(noaarpts.GetNoaaMonthReport(year, month));
break;
default:
Response.StatusCode = 404;
Expand Down Expand Up @@ -1279,7 +1299,7 @@ public async Task GenReports(string req)
switch (req)
{
case "noaayear":
await writer.WriteAsync(String.Join("\n", noaarpts.GenerateNoaaYearReport(year).ToArray()));
await writer.WriteAsync(noaarpts.GenerateNoaaYearReport(year));
break;
case "noaamonth":
if (!Int32.TryParse(query["month"], out month) || month < 1 || month > 12)
Expand All @@ -1288,7 +1308,7 @@ public async Task GenReports(string req)
Response.StatusCode = 406;
return;
}
await writer.WriteAsync(String.Join("\n", noaarpts.GenerateNoaaMonthReport(year, month).ToArray()));
await writer.WriteAsync(noaarpts.GenerateNoaaMonthReport(year, month));
break;
default:
Response.StatusCode = 404;
Expand Down
59 changes: 37 additions & 22 deletions CumulusMX/App.config
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="CumulusMX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<GCConserveMemory enabled="6" />
<GCConserveMemory enabled="6" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.1" newVersion="7.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.2" newVersion="7.0.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
Expand All @@ -48,4 +53,14 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<applicationSettings>
<CumulusMX.Properties.Settings>
<setting name="MinThreadPoolSize" serializeAs="String">
<value>10</value>
</setting>
<setting name="MaxThreadPoolSize" serializeAs="String">
<value>30</value>
</setting>
</CumulusMX.Properties.Settings>
</applicationSettings>
</configuration>
28 changes: 23 additions & 5 deletions CumulusMX/CalibrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,26 @@ public string UpdateConfig(IHttpContext context)
cumulus.Calib.WindSpeed.Mult = Convert.ToDouble(settings.windspd.multiplier, invC);
cumulus.Calib.WindGust.Mult = Convert.ToDouble(settings.gust.multiplier, invC);
cumulus.Calib.Temp.Mult = Convert.ToDouble(settings.temp.multiplier, invC);
cumulus.Calib.Temp.Mult2 = Convert.ToDouble(settings.temp.multiplier2, invC);
cumulus.Calib.InTemp.Mult = Convert.ToDouble(settings.tempin.multiplier, invC);
cumulus.Calib.Hum.Mult = Convert.ToDouble(settings.hum.multiplier, invC);
cumulus.Calib.Hum.Mult2 = Convert.ToDouble(settings.hum.multiplier2, invC);
cumulus.Calib.InHum.Mult = Convert.ToDouble(settings.humin.multiplier, invC);
cumulus.Calib.Rain.Mult = Convert.ToDouble(settings.rain.multiplier, invC);
cumulus.Calib.Solar.Mult = Convert.ToDouble(settings.solar.multiplier, invC);
cumulus.Calib.UV.Mult = Convert.ToDouble(settings.uv.multiplier, invC);
cumulus.Calib.WetBulb.Mult = Convert.ToDouble(settings.wetbulb.multiplier, invC);

//multipliers2
cumulus.Calib.Press.Mult2 = Convert.ToDouble(settings.pressure.multiplier2, invC);
cumulus.Calib.WindSpeed.Mult2 = Convert.ToDouble(settings.windspd.multiplier2, invC);
cumulus.Calib.WindGust.Mult2 = Convert.ToDouble(settings.gust.multiplier2, invC);
cumulus.Calib.Temp.Mult2 = Convert.ToDouble(settings.temp.multiplier2, invC);
cumulus.Calib.InTemp.Mult2 = Convert.ToDouble(settings.tempin.multiplier2, invC);
cumulus.Calib.Hum.Mult2 = Convert.ToDouble(settings.hum.multiplier2, invC);
cumulus.Calib.InHum.Mult2 = Convert.ToDouble(settings.humin.multiplier2, invC);
cumulus.Calib.Solar.Mult2 = Convert.ToDouble(settings.solar.multiplier2, invC);
cumulus.Calib.UV.Mult2 = Convert.ToDouble(settings.uv.multiplier2, invC);
cumulus.Calib.WetBulb.Mult2 = Convert.ToDouble(settings.wetbulb.multiplier2, invC);

// spike removal
cumulus.Spike.TempDiff = Convert.ToDouble(settings.temp.spike, invC);
cumulus.Spike.HumidityDiff = Convert.ToDouble(settings.hum.spike, invC);
Expand Down Expand Up @@ -119,6 +129,7 @@ public string GetAlpacaFormData()
{
offset = cumulus.Calib.Press.Offset,
multiplier = cumulus.Calib.Press.Mult,
multiplier2 = cumulus.Calib.Press.Mult2,
spike = cumulus.Spike.PressDiff,
limitmax = cumulus.Limit.PressHigh,
limitmin = cumulus.Limit.PressLow
Expand All @@ -138,6 +149,7 @@ public string GetAlpacaFormData()
{
offset = cumulus.Calib.InTemp.Offset,
multiplier = cumulus.Calib.InTemp.Mult,
multiplier2 = cumulus.Calib.InTemp.Mult2,
spike = cumulus.Spike.InTempDiff
};

Expand All @@ -153,18 +165,21 @@ public string GetAlpacaFormData()
{
offset = (int) cumulus.Calib.InHum.Offset,
multiplier = cumulus.Calib.InHum.Mult,
multiplier2 = cumulus.Calib.InHum.Mult2,
spike = cumulus.Spike.InHumDiff
};

var windspd = new JsonCalibrationSettings()
{
multiplier = cumulus.Calib.WindSpeed.Mult,
multiplier2 = cumulus.Calib.WindSpeed.Mult2,
spike = cumulus.Spike.WindDiff
};

var gust = new JsonCalibrationSettings()
{
multiplier = cumulus.Calib.WindGust.Mult,
multiplier2 = cumulus.Calib.WindGust.Mult2,
spike = cumulus.Spike.GustDiff,
limitmax = cumulus.Limit.WindHigh
};
Expand All @@ -184,19 +199,22 @@ public string GetAlpacaFormData()
var solar = new JsonCalibrationSettings()
{
offset = cumulus.Calib.Solar.Offset,
multiplier = cumulus.Calib.Solar.Mult
multiplier = cumulus.Calib.Solar.Mult,
multiplier2 = cumulus.Calib.Solar.Mult2
};

var uv = new JsonCalibrationSettings()
{
offset = cumulus.Calib.UV.Offset,
multiplier = cumulus.Calib.UV.Mult
multiplier = cumulus.Calib.UV.Mult,
multiplier2 = cumulus.Calib.UV.Mult2
};

var wetbulb = new JsonCalibrationSettings()
{
offset = cumulus.Calib.WetBulb.Offset,
multiplier = cumulus.Calib.WetBulb.Mult
multiplier = cumulus.Calib.WetBulb.Mult,
multiplier2 = cumulus.Calib.WetBulb.Mult2
};

var dewpt = new JsonCalibrationSettings()
Expand Down
9 changes: 8 additions & 1 deletion CumulusMX/CalibrationsLimits.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace CumulusMX
using System;

namespace CumulusMX
{
public class Calibrations
{
Expand Down Expand Up @@ -35,6 +37,11 @@ public class Settings
public double Offset = 0;
public double Mult = 1;
public double Mult2 = 0;

public double Calibrate(double value)
{
return value * value * Mult2 + value * Mult + Offset;
}
}

public class Limits
Expand Down
Loading

0 comments on commit 86f3e7f

Please sign in to comment.