Skip to content

Commit

Permalink
Merge pull request #169 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.24.0
  • Loading branch information
mcrossley authored Mar 8, 2023
2 parents 2b6955d + 8e36d5f commit 71d18cd
Show file tree
Hide file tree
Showing 42 changed files with 11,738 additions and 6,275 deletions.
63 changes: 52 additions & 11 deletions CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace CumulusMX
{
Expand Down Expand Up @@ -88,15 +89,28 @@ private void doTriggered(bool value)

if (Email && cumulus.SmtpOptions.Enabled && cumulus.emailer != null)
{
cumulus.LogMessage($"Alarm ({Name}): Sending email");

// Construct the message - preamble, plus values
var msg = cumulus.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsg, Value, Units);
var msg = cumulus.Trans.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsg, Value, Units);
if (!string.IsNullOrEmpty(LastError))
{
msg += "\r\nLast error: " + LastError;
}
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
{
// delay for 0, 60, 120 seconds
System.Threading.Thread.Sleep(i * 60000);

cumulus.LogMessage($"Alarm ({Name}): Sending email - attempt {i + 1}");

if (await cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.Trans.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml))
{
break;
}
}
});
}

if (!string.IsNullOrEmpty(Action))
Expand Down Expand Up @@ -236,11 +250,24 @@ private void doUpTriggered(bool value)

if (Email && cumulus.SmtpOptions.Enabled && cumulus.emailer != null)
{
cumulus.LogMessage($"Alarm ({Name}): Sending email");

// Construct the message - preamble, plus values
var msg = cumulus.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsgUp, Value, Units);
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
var msg = cumulus.Trans.AlarmEmailPreamble + "\r\n" + string.Format(EmailMsgUp, Value, Units);
Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
{
// delay for 0, 60, 120 seconds
System.Threading.Thread.Sleep(i * 60000);

cumulus.LogMessage($"Alarm ({Name}): Sending email - attempt {i + 1}");

if (await cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.Trans.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml))
{
break;
}
}
});
}

if (!string.IsNullOrEmpty(Action))
Expand Down Expand Up @@ -297,10 +324,24 @@ private void doDownTriggered(bool value)

if (Email && cumulus.SmtpOptions.Enabled && cumulus.emailer != null)
{
cumulus.LogMessage($"Alarm ({Name}): Sending email");
// Construct the message - preamble, plus values
var msg = cumulus.AlarmEmailPreamble + "\n" + string.Format(EmailMsgDn, Value, Units);
cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml);
var msg = cumulus.Trans.AlarmEmailPreamble + "\n" + string.Format(EmailMsgDn, Value, Units);
Task.Run(async () =>
{
// try to send the email 3 times
for (int i = 0; i < 3; i++)
{
// delay for 0, 60, 120 seconds
System.Threading.Thread.Sleep(i * 60000);

cumulus.LogMessage($"Alarm ({Name}): Sending email - attempt {i + 1}");

if (await cumulus.emailer.SendEmail(cumulus.AlarmDestEmail, cumulus.AlarmFromEmail, cumulus.Trans.AlarmEmailSubject, msg, cumulus.AlarmEmailHtml))
{
break;
}
}
});
}

if (!string.IsNullOrEmpty(Action))
Expand Down
84 changes: 48 additions & 36 deletions CumulusMX/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static class Api
public static MysqlSettings mySqlSettings;
public static CustomLogs customLogs;
public static Wizard wizard;
internal static LangSettings langSettings;
internal static DisplaySettings displaySettings;
internal static AlarmSettings alarmSettings;
internal static DataEditor dataEditor;
internal static ApiTagProcessor tagProcessor;
Expand Down Expand Up @@ -383,67 +385,67 @@ public async Task GetGraphData(string req)
switch (req)
{
case "tempdata.json":
await writer.WriteAsync(Station.GetTempGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetTempGraphData(false, true));
break;
case "winddata.json":
await writer.WriteAsync(Station.GetWindGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetWindGraphData(false));
break;
case "raindata.json":
await writer.WriteAsync(Station.GetRainGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetRainGraphData(false));
break;
case "pressdata.json":
await writer.WriteAsync(Station.GetPressGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetPressGraphData(false));
break;
case "wdirdata.json":
await writer.WriteAsync(Station.GetWindDirGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetWindDirGraphData(false));
break;
case "humdata.json":
await writer.WriteAsync(Station.GetHumGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetHumGraphData(false, true));
break;
case "solardata.json":
await writer.WriteAsync(Station.GetSolarGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetSolarGraphData(false, true));
break;
case "dailyrain.json":
await writer.WriteAsync(Station.GetDailyRainGraphData());
break;
case "sunhours.json":
await writer.WriteAsync(Station.GetSunHoursGraphData());
await writer.WriteAsync(Station.GetSunHoursGraphData(true));
break;
case "dailytemp.json":
await writer.WriteAsync(Station.GetDailyTempGraphData());
await writer.WriteAsync(Station.GetDailyTempGraphData(true));
break;
case "units.json":
await writer.WriteAsync(Station.GetUnits());
break;
case "graphconfig.json":
await writer.WriteAsync(Station.GetGraphConfig());
await writer.WriteAsync(Station.GetGraphConfig(true));
break;
case "airqualitydata.json":
await writer.WriteAsync(Station.GetAqGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetAqGraphData(false));
break;
case "extratemp.json":
await writer.WriteAsync(Station.GetExtraTempGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetExtraTempGraphData(false, true));
break;
case "extrahum.json":
await writer.WriteAsync(Station.GetExtraHumGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetExtraHumGraphData(false, true));
break;
case "extradew.json":
await writer.WriteAsync(Station.GetExtraDewpointGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetExtraDewPointGraphData(false, true));
break;
case "soiltemp.json":
await writer.WriteAsync(Station.GetSoilTempGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetSoilTempGraphData(false, true));
break;
case "soilmoist.json":
await writer.WriteAsync(Station.GetSoilMoistGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetSoilMoistGraphData(false, true));
break;
case "usertemp.json":
await writer.WriteAsync(Station.GetUserTempGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetUserTempGraphData(false, true));
break;
case "co2sensor.json":
await writer.WriteAsync(Station.GetCo2SensorGraphData(DateTime.Now));
await writer.WriteAsync(Station.GetCo2SensorGraphData(false, true));
break;
case "availabledata.json":
await writer.WriteAsync(Station.GetAvailGraphData());
await writer.WriteAsync(Station.GetAvailGraphData(true));
break;
case "selectachart.json":
await writer.WriteAsync(Station.GetSelectaChartOptions());
Expand Down Expand Up @@ -516,7 +518,7 @@ public async Task GetDailyGraphData(string req)
switch (req)
{
case "tempdata.json":
await writer.WriteAsync(Station.GetAllDailyTempGraphData());
await writer.WriteAsync(Station.GetAllDailyTempGraphData(true));
break;
case "winddata.json":
await writer.WriteAsync(Station.GetAllDailyWindGraphData());
Expand All @@ -534,19 +536,19 @@ public async Task GetDailyGraphData(string req)
await writer.WriteAsync(Station.GetAllDailyHumGraphData());
break;
case "solardata.json":
await writer.WriteAsync(Station.GetAllDailySolarGraphData());
await writer.WriteAsync(Station.GetAllDailySolarGraphData(true));
break;
case "degdaydata.json":
await writer.WriteAsync(Station.GetAllDegreeDaysGraphData());
await writer.WriteAsync(Station.GetAllDegreeDaysGraphData(true));
break;
case "tempsumdata.json":
await writer.WriteAsync(Station.GetAllTempSumGraphData());
await writer.WriteAsync(Station.GetAllTempSumGraphData(true));
break;
case "units.json":
await writer.WriteAsync(Station.GetUnits());
break;
case "graphconfig.json":
await writer.WriteAsync(Station.GetGraphConfig());
await writer.WriteAsync(Station.GetGraphConfig(true));
break;
default:
Response.StatusCode = 404;
Expand Down Expand Up @@ -952,17 +954,11 @@ public async Task GetExtraData(string req)
case "soilmoisture.json":
await writer.WriteAsync(Station.GetSoilMoisture());
break;
case "leaf.json":
await writer.WriteAsync(Station.GetLeaf());
break;
case "leaf4.json":
await writer.WriteAsync(Station.GetLeaf4());
break;
case "leaf8.json":
await writer.WriteAsync(Station.GetLeaf8());
await writer.WriteAsync(Station.GetLeaf8(true));
break;
case "airqual.json":
await writer.WriteAsync(Station.GetAirQuality());
await writer.WriteAsync(Station.GetAirQuality(true));
break;
case "lightning.json":
await writer.WriteAsync(Station.GetLightning());
Expand Down Expand Up @@ -991,7 +987,7 @@ public async Task GetExtraData(string req)
break;

case "co2sensor.json":
await writer.WriteAsync(Station.GetCO2sensor());
await writer.WriteAsync(Station.GetCO2sensor(true));
break;
default:
Response.StatusCode = 404;
Expand Down Expand Up @@ -1068,6 +1064,9 @@ public async Task SettingsGet(string req)
case "calibrationdata.json":
await writer.WriteAsync(calibrationSettings.GetAlpacaFormData());
break;
case "langdata.json":
await writer.WriteAsync(langSettings.GetAlpacaFormData());
break;
case "noaadata.json":
await writer.WriteAsync(noaaSettings.GetAlpacaFormData());
break;
Expand All @@ -1090,12 +1089,19 @@ public async Task SettingsGet(string req)
Response.ContentType = "text/plain";
await writer.WriteAsync(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
break;
case "csvseparator.txt":
Response.ContentType = "text/plain";
await writer.WriteAsync(CultureInfo.CurrentCulture.TextInfo.ListSeparator);
break;
case "customlogsintvl.json":
await writer.WriteAsync(customLogs.GetAlpacaFormDataIntvl());
break;
case "customlogsdaily.json":
await writer.WriteAsync(customLogs.GetAlpacaFormDataDaily());
break;
case "displayoptions.json":
await writer.WriteAsync(displaySettings.GetAlpacaFormData());
break;
default:
Response.StatusCode = 404;
break;
Expand Down Expand Up @@ -1180,6 +1186,12 @@ public async Task SettingsSet(string req)
case "updatecustomlogsdaily.json":
await writer.WriteAsync(customLogs.UpdateConfigDaily(HttpContext));
break;
case "updatedisplay.json":
await writer.WriteAsync(displaySettings.UpdateConfig(HttpContext));
break;
case "updatelanguage.json":
await writer.WriteAsync(langSettings.UpdateConfig(HttpContext));
break;
default:
Response.StatusCode = 404;
break;
Expand All @@ -1200,7 +1212,7 @@ public class ReportsController : WebApiController
[Route(HttpVerbs.Get, "/reports/{req}")]
public async Task GetData(string req)
{
NOAAReports noaarpts = new NOAAReports(Program.cumulus);
NOAAReports noaarpts = new NOAAReports(Program.cumulus, Station);
try
{
var query = HttpUtility.ParseQueryString(Request.Url.Query);
Expand Down Expand Up @@ -1248,7 +1260,7 @@ public async Task GetData(string req)
[Route(HttpVerbs.Get, "/genreports/{req}")]
public async Task GenReports(string req)
{
NOAAReports noaarpts = new NOAAReports(Program.cumulus);
NOAAReports noaarpts = new NOAAReports(Program.cumulus, Station);
try
{
var query = HttpUtility.ParseQueryString(Request.Url.Query);
Expand Down Expand Up @@ -1478,7 +1490,7 @@ public async Task PostUtilsData(string req)
switch (req)
{
case "ftpnow.json":
await writer.WriteAsync(stationSettings.FtpNow(HttpContext));
await writer.WriteAsync(stationSettings.UploadNow(HttpContext));
break;
default:
Response.StatusCode = 404;
Expand Down
14 changes: 13 additions & 1 deletion CumulusMX/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<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.0" newVersion="7.0.0.0" />
<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" />
Expand All @@ -34,6 +34,18 @@
<assemblyIdentity name="MimeKit" publicKeyToken="bede1c8a46c66814" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SQLitePCLRaw.core" publicKeyToken="1488e028ca7ab535" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.4.1835" newVersion="2.1.4.1835" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SQLitePCLRaw.batteries_v2" publicKeyToken="8226ea5df37bcae9" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.4.1835" newVersion="2.1.4.1835" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit 71d18cd

Please sign in to comment.