Skip to content

Commit

Permalink
Merge pull request #181 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.27.0 merge
  • Loading branch information
mcrossley authored Oct 28, 2023
2 parents 71d9750 + 8d46e09 commit 5816539
Show file tree
Hide file tree
Showing 73 changed files with 11,115 additions and 3,966 deletions.
46 changes: 23 additions & 23 deletions CumulusMX/AirQualityIndices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static int US_EPApm2p5(double pmVal)
retVal = Interpolate(0, 12, pmVal) * 50;
}
//return (Ihigh - Ilow) / (Chigh - Clow) * (pmVal - Clow) + Ilow;
return (int)Math.Round(retVal);
return (int) Math.Round(retVal);
}

/*
Expand Down Expand Up @@ -145,7 +145,7 @@ public static int US_EPApm10(double pmVal)
retVal = Interpolate(0, 54, pmVal) * 50;
}
//return (Ihigh - Ilow) / (Chigh - Clow) * (pmVal - Clow) + Ilow;
return (int)Math.Round(retVal);
return (int) Math.Round(retVal);
}


Expand Down Expand Up @@ -215,15 +215,15 @@ public static double UK_COMEAPpm10(double pmVal)
*/
public static double EU_AQIpm2p5h1(double pmVal)
{
if (pmVal > 110) // Very High
if (pmVal > 110) // Very High
return 5;
else if (pmVal >= 55) // High
else if (pmVal >= 55) // High
return 4 + Interpolate(55, 110, pmVal);
else if (pmVal >= 30) // Medium
else if (pmVal >= 30) // Medium
return 3 + Interpolate(30, 55, pmVal);
else if (pmVal >= 15) // Low
else if (pmVal >= 15) // Low
return 2 + Interpolate(15, 30, pmVal);
else // Very Low
else // Very Low
return 1 + Interpolate(0, 15, pmVal);
}

Expand All @@ -233,15 +233,15 @@ public static double EU_AQIpm2p5h1(double pmVal)
*/
public static double EU_AQI2p5h24(double pmVal)
{
if (pmVal > 60) // Very High
if (pmVal > 60) // Very High
return 5;
else if (pmVal >= 30) // High
else if (pmVal >= 30) // High
return 4 + Interpolate(30, 60, pmVal);
else if (pmVal >= 20) // Medium
else if (pmVal >= 20) // Medium
return 3 + Interpolate(20, 30, pmVal);
else if (pmVal >= 10) // Low
else if (pmVal >= 10) // Low
return 2 + Interpolate(10, 20, pmVal);
else // Very Low
else // Very Low
return 1 + Interpolate(0, 10, pmVal);
}

Expand All @@ -251,15 +251,15 @@ public static double EU_AQI2p5h24(double pmVal)
*/
public static double EU_AQI10h1(double pmVal)
{
if (pmVal > 180) // Very High
if (pmVal > 180) // Very High
return 5;
else if (pmVal >= 90) // High
else if (pmVal >= 90) // High
return 4 + Interpolate(90, 180, pmVal);
else if (pmVal >= 50) // Medium
else if (pmVal >= 50) // Medium
return 3 + Interpolate(50, 90, pmVal);
else if (pmVal >= 25) // Low
else if (pmVal >= 25) // Low
return 2 + Interpolate(25, 50, pmVal);
else // Very Low
else // Very Low
return 1 + Interpolate(0, 25, pmVal);
}

Expand All @@ -269,15 +269,15 @@ public static double EU_AQI10h1(double pmVal)
*/
public static double EU_AQI10h24(double pmVal)
{
if (pmVal > 100) // Very High
if (pmVal > 100) // Very High
return 5;
else if (pmVal >= 50) // High
else if (pmVal >= 50) // High
return 4 + Interpolate(50, 100, pmVal);
else if (pmVal >= 30) // Medium
else if (pmVal >= 30) // Medium
return 3 + Interpolate(30, 50, pmVal);
else if (pmVal >= 15) // Low
else if (pmVal >= 15) // Low
return 2 + Interpolate(15, 30, pmVal);
else // Very Low
else // Very Low
return 1 + Interpolate(0, 15, pmVal);
}

Expand All @@ -288,7 +288,7 @@ public static double EU_AQI10h24(double pmVal)
*/
public static int CA_AQHI(double pmVal)
{
var aqi = (int)(1000 / 10.4 * (Math.Exp(0.000487 * pmVal) - 1));
var aqi = (int) (1000 / 10.4 * (Math.Exp(0.000487 * pmVal) - 1));
return aqi < 1 ? 1 : aqi;
}

Expand Down
1 change: 0 additions & 1 deletion CumulusMX/Alarm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace CumulusMX
Expand Down
201 changes: 194 additions & 7 deletions CumulusMX/AlarmSettings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.IO;
using System.Net;
using ServiceStack;

using EmbedIO;

using ServiceStack;

namespace CumulusMX
{
public class AlarmSettings
Expand Down Expand Up @@ -308,6 +310,158 @@ public string GetAlarmSettings()
return retObject.ToJson();
}

public string GetAlarmInfo()
{
//var InvC = new CultureInfo("");

var data = new JsonAlarmInfoData()
{
tempBelow = new JsonAlarmInfo()
{
Enabled = cumulus.LowTempAlarm.Enabled,
SoundEnabled = cumulus.LowTempAlarm.Sound,
Sound = cumulus.LowTempAlarm.SoundFile,
Notify = cumulus.LowTempAlarm.Notify
},
tempAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighTempAlarm.Enabled,
SoundEnabled = cumulus.HighTempAlarm.Sound,
Sound = cumulus.HighTempAlarm.SoundFile,
Notify = cumulus.HighTempAlarm.Notify
},
tempChange = new JsonAlarmInfo()
{
Enabled = cumulus.TempChangeAlarm.Enabled,
SoundEnabled = cumulus.TempChangeAlarm.Sound,
Sound = cumulus.TempChangeAlarm.SoundFile,
Notify = cumulus.TempChangeAlarm.Notify
},
pressBelow = new JsonAlarmInfo()
{
Enabled = cumulus.LowPressAlarm.Enabled,
SoundEnabled = cumulus.LowPressAlarm.Sound,
Sound = cumulus.LowPressAlarm.SoundFile,
Notify = cumulus.LowPressAlarm.Notify
},
pressAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighPressAlarm.Enabled,
SoundEnabled = cumulus.HighPressAlarm.Sound,
Sound = cumulus.HighPressAlarm.SoundFile,
Notify = cumulus.HighPressAlarm.Notify
},
pressChange = new JsonAlarmInfo()
{
Enabled = cumulus.PressChangeAlarm.Enabled,
SoundEnabled = cumulus.PressChangeAlarm.Sound,
Sound = cumulus.PressChangeAlarm.SoundFile,
Notify = cumulus.PressChangeAlarm.Notify
},
rainAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighRainTodayAlarm.Enabled,
SoundEnabled = cumulus.HighRainTodayAlarm.Sound,
Sound = cumulus.HighRainTodayAlarm.SoundFile,
Notify = cumulus.HighRainTodayAlarm.Notify
},
rainRateAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighRainRateAlarm.Enabled,
SoundEnabled = cumulus.HighRainRateAlarm.Sound,
Sound = cumulus.HighRainRateAlarm.SoundFile,
Notify = cumulus.HighRainRateAlarm.Notify
},
isRaining = new JsonAlarmInfo()
{
Enabled = cumulus.IsRainingAlarm.Enabled,
SoundEnabled = cumulus.IsRainingAlarm.Sound,
Sound = cumulus.IsRainingAlarm.SoundFile,
Notify = cumulus.IsRainingAlarm.Notify
},
gustAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighGustAlarm.Enabled,
SoundEnabled = cumulus.HighGustAlarm.Sound,
Sound = cumulus.HighGustAlarm.SoundFile,
Notify = cumulus.HighGustAlarm.Notify
},
windAbove = new JsonAlarmInfo()
{
Enabled = cumulus.HighWindAlarm.Enabled,
SoundEnabled = cumulus.HighWindAlarm.Sound,
Sound = cumulus.HighWindAlarm.SoundFile,
Notify = cumulus.HighWindAlarm.Notify
},
contactLost = new JsonAlarmInfo()
{
Enabled = cumulus.SensorAlarm.Enabled,
SoundEnabled = cumulus.SensorAlarm.Sound,
Sound = cumulus.SensorAlarm.SoundFile,
Notify = cumulus.SensorAlarm.Notify
},
newRecord = new JsonAlarmInfo()
{
Enabled = cumulus.NewRecordAlarm.Enabled,
SoundEnabled = cumulus.NewRecordAlarm.Sound,
Sound = cumulus.NewRecordAlarm.SoundFile,
Notify = cumulus.NewRecordAlarm.Notify
},
dataStopped = new JsonAlarmInfo()
{
Enabled = cumulus.DataStoppedAlarm.Enabled,
SoundEnabled = cumulus.DataStoppedAlarm.Sound,
Sound = cumulus.DataStoppedAlarm.SoundFile,
Notify = cumulus.DataStoppedAlarm.Notify
},
batteryLow = new JsonAlarmInfo()
{
Enabled = cumulus.BatteryLowAlarm.Enabled,
SoundEnabled = cumulus.BatteryLowAlarm.Sound,
Sound = cumulus.BatteryLowAlarm.SoundFile,
Notify = cumulus.BatteryLowAlarm.Notify
},
spike = new JsonAlarmInfo()
{
Enabled = cumulus.SpikeAlarm.Enabled,
SoundEnabled = cumulus.SpikeAlarm.Sound,
Sound = cumulus.SpikeAlarm.SoundFile,
Notify = cumulus.SpikeAlarm.Notify
},
upgrade = new JsonAlarmInfo()
{
Enabled = cumulus.UpgradeAlarm.Enabled,
SoundEnabled = cumulus.UpgradeAlarm.Sound,
Sound = cumulus.UpgradeAlarm.SoundFile,
Notify = cumulus.UpgradeAlarm.Notify
},
httpUpload = new JsonAlarmInfo()
{
Enabled = cumulus.ThirdPartyAlarm.Enabled,
SoundEnabled = cumulus.ThirdPartyAlarm.Sound,
Sound = cumulus.ThirdPartyAlarm.SoundFile,
Notify = cumulus.ThirdPartyAlarm.Notify
},
mySqlUpload = new JsonAlarmInfo()
{
Enabled = cumulus.MySqlUploadAlarm.Enabled,
SoundEnabled = cumulus.MySqlUploadAlarm.Sound,
Sound = cumulus.MySqlUploadAlarm.SoundFile,
Notify = cumulus.MySqlUploadAlarm.Notify
},
ftpUpload = new JsonAlarmInfo()
{
Enabled = cumulus.FtpAlarm.Enabled,
SoundEnabled = cumulus.FtpAlarm.Sound,
Sound = cumulus.FtpAlarm.SoundFile,
Notify = cumulus.FtpAlarm.Notify
}
};

return data.ToJson();
}


public string UpdateAlarmSettings(IHttpContext context)
{
var json = "";
Expand All @@ -331,7 +485,7 @@ public string UpdateAlarmSettings(IHttpContext context)
catch (Exception ex)
{
var msg = "Error de-serializing Alarm Settings JSON: " + ex.Message;
cumulus.LogMessage(msg);
cumulus.LogErrorMessage(msg);
cumulus.LogDebugMessage("Alarm Data: " + json);
context.Response.StatusCode = 500;
return msg;
Expand Down Expand Up @@ -586,7 +740,7 @@ public string UpdateAlarmSettings(IHttpContext context)
if (emailRequired && !EmailSender.CheckEmailAddress(result.email.fromEmail.Trim()))
{
var msg = "ERROR: Alarm email option enabled and an invalid Alarm from email address entered";
cumulus.LogMessage(msg);
cumulus.LogWarningMessage(msg);
context.Response.StatusCode = 500;
return msg;
}
Expand All @@ -603,7 +757,7 @@ public string UpdateAlarmSettings(IHttpContext context)
if (!EmailSender.CheckEmailAddress(emails[i]))
{
var msg = "ERROR: Invalid Alarm destination email address entered";
cumulus.LogMessage(msg);
cumulus.LogWarningMessage(msg);
context.Response.StatusCode = 500;
return msg;
}
Expand All @@ -619,7 +773,7 @@ public string UpdateAlarmSettings(IHttpContext context)
}
catch (Exception ex)
{
cumulus.LogMessage("Error processing Alarm settings: " + ex.Message);
cumulus.LogErrorMessage("Error processing Alarm settings: " + ex.Message);
cumulus.LogDebugMessage("Alarm Data: " + json);
context.Response.StatusCode = 500;
return ex.Message;
Expand All @@ -645,7 +799,7 @@ public string TestEmail(IHttpContext context)
if (!EmailSender.CheckEmailAddress(result.fromEmail.Trim()))
{
var msg = "ERROR: Invalid Alarm from email address entered";
cumulus.LogMessage(msg);
cumulus.LogWarningMessage(msg);
context.Response.StatusCode = 500;
return msg;
}
Expand All @@ -659,7 +813,7 @@ public string TestEmail(IHttpContext context)
if (!EmailSender.CheckEmailAddress(dest[i]))
{
var msg = "ERROR: Invalid Alarm destination email address entered";
cumulus.LogMessage(msg);
cumulus.LogWarningMessage(msg);
context.Response.StatusCode = 500;
return msg;
}
Expand Down Expand Up @@ -727,6 +881,39 @@ public class JsonAlarmValues
public string ActionParams { get; set; }
}

public class JsonAlarmInfoData
{
public JsonAlarmInfo tempBelow { get; set; }
public JsonAlarmInfo tempAbove { get; set; }
public JsonAlarmInfo tempChange { get; set; }
public JsonAlarmInfo pressBelow { get; set; }
public JsonAlarmInfo pressAbove { get; set; }
public JsonAlarmInfo pressChange { get; set; }
public JsonAlarmInfo rainAbove { get; set; }
public JsonAlarmInfo rainRateAbove { get; set; }
public JsonAlarmInfo gustAbove { get; set; }
public JsonAlarmInfo windAbove { get; set; }
public JsonAlarmInfo newRecord { get; set; }
public JsonAlarmInfo contactLost { get; set; }
public JsonAlarmInfo dataStopped { get; set; }
public JsonAlarmInfo batteryLow { get; set; }
public JsonAlarmInfo spike { get; set; }
public JsonAlarmInfo upgrade { get; set; }
public JsonAlarmInfo httpUpload { get; set; }
public JsonAlarmInfo mySqlUpload { get; set; }
public JsonAlarmInfo isRaining { get; set; }
public JsonAlarmInfo ftpUpload { get; set; }
}


public class JsonAlarmInfo
{
public bool Enabled { get; set; }
public bool SoundEnabled { get; set; }
public string Sound { get; set; }
public bool Notify { get; set; }
}

public class JsonAlarmEmail
{
public string fromEmail { get; set; }
Expand Down
Loading

0 comments on commit 5816539

Please sign in to comment.